Skip to content

Commit 01cf925

Browse files
committed
Completion of 1-implement-and-rewrite-tests
1 parent 522d1bd commit 01cf925

File tree

6 files changed

+120
-4
lines changed

6 files changed

+120
-4
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616

1717
function getAngleType(angle) {
1818
// TODO: Implement this function
19+
if (angle >= 0 && angle < 90) {
20+
return "Acute angle";
21+
} else if (angle === 90) {
22+
return "Right angle";
23+
} else if (angle > 90 && angle < 180) {
24+
return "Obtuse angle";
25+
} else if (angle === 180) {
26+
return "Straight angle";
27+
} else if (angle > 180 && angle <= 360) {
28+
return "Reflex angle";
29+
} else {
30+
return "Invalid angle";
31+
}
1932
}
2033

2134
// The line below allows us to load the getAngleType function into tests in other files.
@@ -35,3 +48,19 @@ function assertEquals(actualOutput, targetOutput) {
3548
// Example: Identify Right Angles
3649
const right = getAngleType(90);
3750
assertEquals(right, "Right angle");
51+
52+
const acute = getAngleType(70);
53+
assertEquals(acute, "Acute angle");
54+
55+
const obtuse = getAngleType(140);
56+
assertEquals(obtuse, "Obtuse angle");
57+
58+
const straight = getAngleType(180);
59+
assertEquals(straight, "Straight angle");
60+
61+
const reflex = getAngleType(190);
62+
assertEquals(reflex, "Reflex angle");
63+
64+
const invalid = getAngleType(370);
65+
assertEquals(invalid, "Invalid angle");
66+

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15+
if (numerator < denominator) {
16+
return "true";
17+
} else {
18+
return "false";
19+
}
1520
}
1621

1722
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -30,4 +35,6 @@ function assertEquals(actualOutput, targetOutput) {
3035
// What combinations of numerators and denominators should you test?
3136

3237
// Example: 1/2 is a proper fraction
33-
assertEquals(isProperFraction(1, 2), true);
38+
assertEquals(isProperFraction(1, 2), "true");
39+
assertEquals(isProperFraction(2, 2), "false");
40+
assertEquals(isProperFraction(7, 4), "false");

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323

2424
function getCardValue(card) {
2525
// TODO: Implement this function
26+
rankCard = card.slice(0, 1);
27+
if (rankCard === "A") {
28+
return 11;
29+
} else if (rankCard === "J" || rankCard === "Q" || rankCard === "K") {
30+
return 10;
31+
} else if (+rankCard >= 2 && +rankCard <= 10) {
32+
return +rankCard;
33+
} else {
34+
return rankCard.toThrow();
35+
}
2636
}
2737

2838
// The line below allows us to load the getCardValue function into tests in other files.
@@ -47,6 +57,8 @@ try {
4757

4858
// This line will not be reached if an error is thrown as expected
4959
console.error("Error was not thrown for invalid card");
50-
} catch (e) {}
60+
} catch (e) { }
5161

5262
// What other invalid card cases can you think of?
63+
64+
getCardValue("13♠");

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,31 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
1414
});
1515

1616
// Case 2: Right angle
17+
test(`should return "Right angle" when (angle === 90)`, () => {
18+
expect(getAngleType(90)).toEqual("Right angle");
19+
});
20+
1721
// Case 3: Obtuse angles
22+
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
23+
expect(getAngleType(91)).toEqual("Obtuse angle");
24+
expect(getAngleType(145)).toEqual("Obtuse angle");
25+
expect(getAngleType(189)).toEqual("Obtuse angle");
26+
});
1827
// Case 4: Straight angle
28+
test(`should return "Straight angle" when (angle === 180)`, () => {
29+
expect(getAngleType(180)).toEqual("Straight angle");
30+
31+
});
1932
// Case 5: Reflex angles
33+
test(`should return "Reflex angle" when (180 < angle <= 360)`, () => {
34+
expect(getAngleType(181)).toEqual("Reflex angle");
35+
expect(getAngleType(245)).toEqual("Reflex angle");
36+
expect(getAngleType(360)).toEqual("Reflex angle");
37+
});
38+
2039
// Case 6: Invalid angles
40+
test(`should return "Invalid angle" when (angle > 360)`, () => {
41+
expect(getAngleType(361)).toEqual("Invalid angle");
42+
expect(getAngleType(445)).toEqual("Invalid angle");
43+
expect(getAngleType(589)).toEqual("Invalid angle");
44+
});

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,21 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
88
test(`should return false when denominator is zero`, () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
1010
});
11+
12+
// positives:
13+
test(`should return true when a numerator is less than denominator`, () => {
14+
expect(isProperFraction(1, 2)).toEqual(true);
15+
});
16+
17+
test(`should return false when a numerator is greater than denominator`, () => {
18+
expect(isProperFraction(5, 4)).toEqual(false);
19+
});
20+
21+
// negatives:
22+
test(`should return true when a numerator is less than denominator`, () => {
23+
expect(isProperFraction(-1, 2)).toEqual(tue);
24+
});
25+
26+
test(`should return false when a numerator is greater than denominator`, () => {
27+
expect(isProperFraction(5, -4)).toEqual(false);
28+
});

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,34 @@ test(`Should return 11 when given an ace card`, () => {
1111

1212
// Suggestion: Group the remaining test data into these categories:
1313
// Number Cards (2-10)
14-
// Face Cards (J, Q, K)
15-
// Invalid Cards
14+
test(`Should return the numeric value when the card is a number card ("2" to "10")`, () => {
15+
const numberCards = [
16+
{ card: "2", value: 2 },
17+
{ card: "3", value: 3 },
18+
{ card: "4", value: 4 },
19+
{ card: "5", value: 5 },
20+
{ card: "6", value: 6 },
21+
{ card: "7", value: 7 },
22+
{ card: "8", value: 8 },
23+
{ card: "9", value: 9 },
24+
{ card: "10", value: 10 }
25+
];
26+
27+
numberCards.forEach(({ card, value }) => {
28+
expect(getCardValue(card)).toEqual(value);
29+
});
30+
// Face Cards (J, Q, K)
31+
test(`Should return 10 when given face card ("J", "Q", "K")`, () => {
32+
expect(getCardValue("J♣")).toEqual(10);
33+
});
34+
35+
test(`Should return 10 when given face card ("J", "Q", "K")`, () => {
36+
expect(getCardValue("Q♦")).toEqual(10);
37+
});
38+
39+
test(`Should return 10 when given face card ("J", "Q", "K")`, () => {
40+
expect(getCardValue("K♦")).toEqual(10);
41+
});
1642

1743
// To learn how to test whether a function throws an error as expected in Jest,
1844
// please refer to the Jest documentation:

0 commit comments

Comments
 (0)