-
Notifications
You must be signed in to change notification settings - Fork 0
/
isPalindrome.js
86 lines (70 loc) · 2.39 KB
/
isPalindrome.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* eslint-disable */
const {isPalindrome} = require("../functions/isPalindrome");
const fs = require("fs");
function generateImageBadgeURL(label, value, passed) {
return `https://img.shields.io/badge/${encodeURIComponent(label)}-${value}-${passed === 0 ? '13b285' : 'ff69b4'}`;}
function generateTestBadge(functionName, numberOfPassed, numberOfFailed) {
const url = generateImageBadgeURL(functionName + '()', encodeURIComponent(numberOfPassed + ' passed, ' + numberOfFailed + ' failed.'), numberOfFailed);
return '\n\n### Tests for ' + functionName + '\n\n' + '![' + functionName + '](' + url + ')';}
function addToReadme(str) {fs.appendFile('./README.md', str, function (err) {if (err) throw err;console.log('String added to the file');});}/**
* Test for isPalindrome function
*/
function testIsPalindrome() {
let number_of_tests_passed = 0;
let number_of_tests_failed = 0;
const name_of_function = "isPalindrome";
try {
const result = isPalindrome("A man a plan a canal Panama");
if (result === true) {
number_of_tests_passed++;
} else {
number_of_tests_failed++;
}
} catch (err) {
number_of_tests_failed++;
}
try {
const result = isPalindrome("race car");
if (result === true) {
number_of_tests_passed++;
} else {
number_of_tests_failed++;
}
} catch (err) {
number_of_tests_failed++;
}
try {
const result = isPalindrome("hello");
if (result === false) {
number_of_tests_passed++;
} else {
number_of_tests_failed++;
}
} catch (err) {
number_of_tests_failed++;
}
try {
const result = isPalindrome("Madam In Eden, I'm Adam");
if (result === true) {
number_of_tests_passed++;
} else {
number_of_tests_failed++;
}
} catch (err) {
number_of_tests_failed++;
}
try {
const result = isPalindrome("long_palindrome_word_with_spaces");
if (result === false) {
number_of_tests_passed++;
} else {
number_of_tests_failed++;
}
} catch (err) {
number_of_tests_failed++;
}
addToReadme(generateTestBadge(name_of_function, number_of_tests_passed, number_of_tests_failed));
}
module.exports = {
testIsPalindrome
};