Skip to content

Commit 7a7dbb9

Browse files
committed
testing functions
1 parent 0717b53 commit 7a7dbb9

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

dist/functionality.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

project/js/functionality/reverseNum.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
* @returns {number}
66
*/
77
function reverseNum(number) {
8+
if (number == 0 || number == -0) {
9+
return 0;
10+
}
11+
if (!number) {
12+
return "";
13+
}
814
// this code is changed from the original one because it didn't work properly when the number is decimal
915
if (number < 10 && number > -10) {
1016
return number;

tests/reverseNum.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const reverseNum = require("../project/js/functionality/reverseNum.js");
2+
3+
it("always returns a number", function () {
4+
expect(typeof reverseNum(123)).toBe("number");
5+
});
6+
7+
it("returns the number reversed", function () {
8+
expect(reverseNum(123)).toBe(321);
9+
});
10+
11+
it("returns empty string if there is no parameter", function () {
12+
expect(reverseNum()).toBe("");
13+
});
14+
15+
it("returns the number if it its length equal to 1", function () {
16+
expect(reverseNum(0)).toBe(0);
17+
});
18+
19+
it("does not reverse the negative sign when reversing number", function () {
20+
expect(reverseNum(-123)).toBe(-321);
21+
});

tests/reverseString.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
const reversestring = require("../project/js/functionality/reverseString.js");
1+
const reverseString = require("../project/js/functionality/reverseString.js");
22

33
it("always return a string", function () {
4-
expect(typeof reversestring("hello")).toBe("string");
4+
expect(typeof reverseString("hello")).toBe("string");
55
});
66

77
it("always reverse the parameter", function () {
8-
expect(reversestring("hello")).toBe("olleh");
8+
expect(reverseString("hello")).toBe("olleh");
99
});
1010

1111
it("returns empty string if no parameter", function () {
12-
expect(reversestring()).toBe("");
12+
expect(reverseString()).toBe("");
1313
});
1414

1515
it("returns empty string if the parameter is not a string", function () {
16-
expect(reversestring(5)).toBe("");
16+
expect(reverseString(5)).toBe("");
1717
});
1818

1919
it("does not matter about multiple parameters", function () {
20-
expect(reversestring("hello", "world")).toBe("olleh");
20+
expect(reverseString("hello", "world")).toBe("olleh");
2121
});

0 commit comments

Comments
 (0)