Skip to content

Commit f6f394c

Browse files
committed
Updated after feedback
1 parent 3d438c6 commit f6f394c

File tree

5 files changed

+72
-15
lines changed

5 files changed

+72
-15
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ function getAngleType(angle) {
3737
else if (angle > 180 && angle < 360) {
3838
return "Reflex angle";
3939
}
40-
// everything greater than 360 return invalid angle
40+
41+
// if it is 360 then it is a full rotation
42+
else if (angle === 360) {
43+
return "Full rotation";
44+
}
45+
// everything greater than 360 rand less than 0 return invalid angle
4146
else {
4247
return "Invalid angle";
4348
}
@@ -61,3 +66,18 @@ function assertEquals(actualOutput, targetOutput) {
6166
// Example: Identify Right Angles
6267
const right = getAngleType(90);
6368
assertEquals(right, "Right angle");
69+
70+
const acute = getAngleType(45);
71+
assertEquals(acute, "Acute angle");
72+
73+
const obtuse = getAngleType(120);
74+
assertEquals(obtuse, "Obtuse angle");
75+
76+
const straight = getAngleType(180);
77+
assertEquals(straight, "Straight angle");
78+
79+
const reflex = getAngleType(270);
80+
assertEquals(reflex, "Reflex angle");
81+
82+
const invalid = getAngleType(200);
83+
assertEquals(invalid, "Invalid angle");

Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,23 @@
2222
// execute the code to ensure all tests pass.
2323

2424
function getCardValue(card) {
25+
const suits = ["♠", "♥", "♦", "♣"]; // valid card suits
26+
27+
const suit = card.slice(-1); // gives me the last character
28+
const rank = card.slice(0, -1); // gets beginning character up to (not including) the last character
29+
30+
if (!suits.includes(suit)) {
31+
throw new Error("Error invalid card");
32+
}
2533
// TODO: Implement this function
2634

2735
// if card is an ace return 11
28-
if (card === "A") {
36+
if (card === "A") {
2937
return 11;
3038
}
3139

3240
// if card is face "J", "Q", "K"
33-
else if (card === "J" || card === "Q" || card === "K") {
41+
else if (card === "J" || card === "Q" || card === "K") {
3442
return 10;
3543
}
3644

@@ -56,7 +64,7 @@ function assertEquals(actualOutput, targetOutput) {
5664

5765
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
5866
// Examples:
59-
assertEquals(getCardValue("9"), 9);
67+
assertEquals(getCardValue("9"), 9);
6068

6169
// Handling invalid cards
6270
try {

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,16 @@ test(`should return "Reflex angles" when (angle > 180 && < 360)`, () => {
3737
expect(getAngleType(245)).toEqual("Reflex angle");
3838
expect(getAngleType(306)).toEqual("Reflex angle");
3939
});
40-
// Case 6: Invalid angles
41-
test(`should return "Invalid angles" when (angle > 180 && < 360)`, () => {
40+
// Case 6: Full rotation
41+
test("returns full rotation for 360 degrees (angle === 360))", () => {
42+
expect(getAngleType(360)).toBe("Full rotation");
43+
});
44+
// Case 7: Invalid angles
45+
test(`should return "Invalid angles" when (angle >360)`, () => {
4246
// Test various invalid angles, including boundary cases
43-
expect(getAngleType(360)).toEqual("Invalid angle");
47+
expect(getAngleType(400)).toEqual("Invalid angle");
48+
});
49+
// Case 8: Invalid angles
50+
test(`should return "Invalid angles" when (angle <0)`, () => {
51+
expect(getAngleType(-7)).toBe("Invalid angle");
4452
});

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,43 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
44

55
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
66

7-
// Special case: numerator is zero
7+
// Special case: denominator is zero
88
test(`should return false when denominator is zero`, () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
1010
});
1111

12-
test(`for positive`, () => {
12+
// Case 2: Proper fractions
13+
// the numerator is smaller than the denominator, so the fraction is a proper fraction
14+
test(`should return true when |numerator| < |denominator|`, () => {
1315
expect(isProperFraction(6, 7)).toEqual(true);
1416
expect(isProperFraction(2, 4)).toEqual(true);
1517
});
1618

17-
test(`should return false for improper fractions`, () => {
19+
// Case 3: Improper fractions
20+
// numerator is bigger than denominator, so the fraction is not proper
21+
test("should return false when numerator is bigger than denominator", () => {
1822
expect(isProperFraction(8, 6)).toEqual(false);
1923
expect(isProperFraction(4, 2)).toEqual(false);
2024
});
2125

22-
test(`negative combinations`, () => {
26+
// Case 4: Negative numbers
27+
// numerator or denominator is negative, but function compares absolute values
28+
test("should return correct result when numerator or denominator is negative", () => {
2329
expect(isProperFraction(-5, 9)).toEqual(true);
2430
expect(isProperFraction(-2, 0)).toEqual(false);
2531
});
32+
33+
// Case 5: Numerator equals denominator fraction equals 1, so it is not proper
34+
test("should return false when numerator is equal to denominator", () => {
35+
expect(isProperFraction(6, 6)).toEqual(false);
36+
});
37+
38+
// Case 6: Numerator just less than denominator fraction is slightly below 1, so it is proper
39+
test("should return true when numerator is just less than denominator", () => {
40+
expect(isProperFraction(2, 3)).toEqual(true);
41+
});
42+
43+
// Case 7: Numerator greater than denominator fraction is slightly above 1, so it is not proper
44+
test("should return false when numerator is greater than denominator", () => {
45+
expect(isProperFraction(6, 5)).toEqual(false);
46+
});

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const getCardValue = require("../implement/3-get-card-value");
66

77
// Case 1: Ace (A)
88
test(`Should return 11 when given an ace card`, () => {
9-
expect(getCardValue("A")).toEqual(11);
9+
expect(getCardValue("A")).toEqual(11);
1010
});
1111

1212
// Suggestion: Group the remaining test data into these categories:
@@ -16,15 +16,15 @@ test(`Should return 11 when given an ace card`, () => {
1616

1717
// Case 2: Face (J, Q, K)
1818
test(`Should return 10 when given an face card`, () => {
19-
expect(getCardValue("J")).toEqual(10);
19+
expect(getCardValue("J")).toEqual(10);
2020
});
2121

2222
test(`Should return 10 when given an face card`, () => {
23-
expect(getCardValue("Q")).toEqual(10);
23+
expect(getCardValue("Q")).toEqual(10);
2424
});
2525

2626
test(`Should return 10 when given an face card`, () => {
27-
expect(getCardValue("K")).toEqual(10);
27+
expect(getCardValue("K")).toEqual(10);
2828
});
2929
// Case 3: Number Cards (2-10)
3030
test(`Should return numerical value when given an number card`, () => {

0 commit comments

Comments
 (0)