Skip to content

Commit 3c8fe4f

Browse files
committed
adding more tests for different types of input
1 parent 6c04424 commit 3c8fe4f

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88
// Then, write the next test! :) Go through this process until all the cases are implemented
99

1010
function getAngleType(angle) {
11+
if (
12+
angle === null ||
13+
(typeof angle !== "number" && typeof angle !== "string")
14+
) {
15+
return "Input should be a number or a number in string";
16+
}
17+
angle = Number(angle);
18+
if (isNaN(angle)) {
19+
return "Input should be a number or a number in string";
20+
}
21+
if (angle < 0 || angle > 360) {
22+
return "Angle should be between 0 and 360";
23+
}
24+
if (angle === 0) {
25+
return "Zero angle";
26+
}
1127
if (angle === 90) {
1228
return "Right angle";
1329
}
@@ -25,6 +41,9 @@ function getAngleType(angle) {
2541
if (angle > 180 && angle < 360) {
2642
return "Reflex angle";
2743
}
44+
if (angle === 360) {
45+
return "Full rotation";
46+
}
2847
}
2948

3049
// The line below allows us to load the getAngleType function into tests in other files.

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,79 @@ test("should identify straight angle (180°)", () => {
3636
test("should identify reflex angle (>180° and <360°)", () => {
3737
expect(getAngleType(250)).toEqual("Reflex angle");
3838
});
39+
40+
// Case 6: Identify Full Rotation:
41+
// When the angle is exactly 360 degrees,
42+
// Then the function should return "Full rotation"
43+
test("should identify full rotation (360°)", () => {
44+
expect(getAngleType(360)).toEqual("Full rotation");
45+
});
46+
47+
// Case 7: input is a number in string
48+
test("should return as usual when input is a number in string", () => {
49+
expect(getAngleType("90")).toEqual("Right angle");
50+
});
51+
52+
// Case 8: input is not a number
53+
test("should return 'Input should be a number or a number in string' when input is not a number", () => {
54+
expect(getAngleType("hello")).toEqual(
55+
"Input should be a number or a number in string"
56+
);
57+
});
58+
59+
// Case 9: input is less than 0
60+
test("should return 'Angle should be between 0 and 360' when input is less than 0", () => {
61+
expect(getAngleType(-10)).toEqual("Angle should be between 0 and 360");
62+
});
63+
64+
// Case 10: input is greater than 360
65+
test("should return 'Angle should be between 0 and 360' when input is greater than 360", () => {
66+
expect(getAngleType(400)).toEqual("Angle should be between 0 and 360");
67+
});
68+
69+
// Case 11: input is exactly 0
70+
test("should identify zero angle (0°)", () => {
71+
expect(getAngleType(0)).toEqual("Zero angle");
72+
});
73+
74+
// Case 12: input is empty
75+
test("should return 'Input should be a number or a number in string' when input is empty", () => {
76+
expect(getAngleType()).toEqual(
77+
"Input should be a number or a number in string"
78+
);
79+
});
80+
81+
// Case 13: input is null
82+
test("should return 'Input should be a number or a number in string' when input is null", () => {
83+
expect(getAngleType(null)).toEqual(
84+
"Input should be a number or a number in string"
85+
);
86+
});
87+
88+
// Case 14: input is NaN
89+
test("should return 'Input should be a number or a number in string' when input is NaN", () => {
90+
expect(getAngleType(NaN)).toEqual(
91+
"Input should be a number or a number in string"
92+
);
93+
});
94+
95+
// Case 15: input is undefined
96+
test("should return 'Input should be a number or a number in string' when input is undefined", () => {
97+
expect(getAngleType(undefined)).toEqual(
98+
"Input should be a number or a number in string"
99+
);
100+
});
101+
102+
// Case 16: input is an object
103+
test("should return 'Input should be a number or a number in string' when input is an object", () => {
104+
expect(getAngleType({})).toEqual(
105+
"Input should be a number or a number in string"
106+
);
107+
});
108+
109+
// Case 17: input is an array
110+
test("should return 'Input should be a number or a number in string' when input is an array", () => {
111+
expect(getAngleType([])).toEqual(
112+
"Input should be a number or a number in string"
113+
);
114+
});

0 commit comments

Comments
 (0)