Skip to content

Commit caa7f2a

Browse files
committed
adding back tests
1 parent 1bd578a commit caa7f2a

File tree

7 files changed

+156
-0
lines changed

7 files changed

+156
-0
lines changed

tests/capitalize.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const capitalize = require("../project/js/functionality/capitalize.js");
2+
3+
it("always make the first letter capital", function () {
4+
expect(capitalize("hello")).toBe("Hello");
5+
});
6+
7+
it("returns any value type", function () {
8+
expect(capitalize("hello")).toEqual(expect.anything());
9+
});
10+
11+
it("returns empty if no parameter", function () {
12+
expect(capitalize()).toBe("");
13+
});

tests/getMid.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const getMid = require("../project/js/functionality/getMid");
2+
3+
it("always returns a number", function () {
4+
expect(typeof getMid(1, 2)).toBe("number");
5+
});
6+
7+
it("always returns a number also if the parameters are string", function () {
8+
expect(typeof getMid("ali", "ahmed")).toBe("number");
9+
});
10+
11+
it("always returns a zero if the first parameter is not a number", function () {
12+
expect(getMid("ali", 5)).toBe(0);
13+
});
14+
15+
it("always returns a zero if the second parameter is not a number", function () {
16+
expect(getMid(5, "ali")).toBe(0);
17+
});
18+
19+
it("returns the two parameters value if they are the same also if they are a string type", function () {
20+
expect(getMid("5", "5")).toBe(5);
21+
});
22+
23+
it("returns the middle of two parameters", function () {
24+
expect(getMid(10, 20)).toBe(15);
25+
});
26+
27+
it("returns the two parameters value if they are the same", function () {
28+
expect(getMid(5, 5)).toBe(5);
29+
});
30+
31+
it("returns the first number if not Entering The Second Number", function () {
32+
expect(getMid(5)).toBe(5);
33+
});
34+
35+
it("returns zero if the first parameter is not a number and the second parameter is not passing", function () {
36+
expect(getMid([1, 2, 3, 4])).toBe(0);
37+
});
38+
39+
it("returns zero if there is no parameters", function () {
40+
expect(getMid()).toBe(0);
41+
});

tests/isPalindrome.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const isPalindrome = require("../project/js/functionality/isPalindrome.js");
2+
3+
it("always returns a boolean value", function () {
4+
expect(typeof isPalindrome("123")).toBe("boolean");
5+
});
6+
7+
it("returns true if word is palindrome", function () {
8+
expect(isPalindrome("mum")).toBe(true);
9+
});
10+
11+
it("returns false if word is not palindrome", function () {
12+
expect(isPalindrome("muom")).toBe(false);
13+
});
14+
15+
it("returns true if word is palindrome also if the parameter is number", function () {
16+
expect(isPalindrome(121)).toBe(true);
17+
});
18+
19+
it("returns false if word is not palindrome also if the parameter is number", function () {
20+
expect(isPalindrome(123)).toBe(false);
21+
});
22+
23+
it("returns empty string if there is no parameter", function () {
24+
expect(isPalindrome()).toBe("");
25+
});

tests/randomBoolean.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const randomBoolean = require("../project/js/functionality/randomBoolean.js");
2+
3+
it("always return a boolean value", function () {
4+
expect(typeof randomBoolean()).toBe("boolean");
5+
});
6+
7+
it("always return true or false only", function () {
8+
expect(randomBoolean()).toEqual(expect.any(Boolean));
9+
});
10+
11+
it("does not matter about parameters", function () {
12+
expect(randomBoolean(5, 7)).toEqual(expect.any(Boolean));
13+
});

tests/randomHex.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const randomHex = require("../project/js/functionality/randomHex");
2+
3+
it("always returns a string", () => {
4+
expect(typeof randomHex()).toBe("string");
5+
});
6+
7+
it("always returns a colour", () => {
8+
const colours = Array(100)
9+
.fill(null)
10+
.map(() => randomHex());
11+
12+
colours.every((colour) => expect(colour).toMatch(/^#[\da-f]{6}$/));
13+
});
14+
15+
it("doesn't always return the same colour", () => {
16+
const colours = Array(100)
17+
.fill(null)
18+
.map(() => randomHex());
19+
20+
expect(new Set(colours).size).toBeGreaterThan(1);
21+
// or a higher number, but e.g. `.toEqual(colours.length)` can fail due to collisions
22+
});

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const reverseString = require("../project/js/functionality/reverseString.js");
2+
3+
it("always return a string", function () {
4+
expect(typeof reverseString("hello")).toBe("string");
5+
});
6+
7+
it("always reverse the parameter", function () {
8+
expect(reverseString("hello")).toBe("olleh");
9+
});
10+
11+
it("returns empty string if no parameter", function () {
12+
expect(reverseString()).toBe("");
13+
});
14+
15+
it("returns empty string if the parameter is not a string", function () {
16+
expect(reverseString(5)).toBe("");
17+
});
18+
19+
it("does not matter about multiple parameters", function () {
20+
expect(reverseString("hello", "world")).toBe("olleh");
21+
});

0 commit comments

Comments
 (0)