Skip to content

Commit 927466a

Browse files
committed
Sprint 3 implement and rewrite-test with jest is done, i modified get-card-value adding line 37 to line 40 and i also completed the rewrite-test with jest section - i revert a commit so i work on it again and re- commit it( problem was the jest edited the jason file -version)
1 parent b37f1b2 commit 927466a

25 files changed

Lines changed: 2798 additions & 0 deletions

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ function getCardValue(card) {
3434

3535
const faceCardValues = {'A': 11, 'J': 10, 'Q': 10, 'K': 10};
3636

37+
if(faceCardValues[value] === undefined && (Number(value) < 2 || Number(value) > 10)) {
38+
throw new Error("Invalid card");
39+
}
40+
41+
3742
if (faceCardValues[value] !== undefined) {
3843
return faceCardValues[value];
3944
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,37 @@ 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+
// Test various acute angles, including boundary cases
19+
expect(getAngleType(90)).toEqual("Right angle");
20+
21+
});
22+
1723
// Case 3: Obtuse angles
24+
test(`should return "Obtuse angle" when ( 90 < angle < 180)`, () => {
25+
// Test various acute angles, including boundary cases
26+
expect(getAngleType(91)).toEqual("Obtuse angle");
27+
expect(getAngleType(125)).toEqual("Obtuse angle");
28+
expect(getAngleType(179)).toEqual("Obtuse angle");
29+
});
30+
1831
// Case 4: Straight angle
32+
test(`should return "Straight angle" when (angle === 180)`, () => {
33+
// Test various acute angles, including boundary cases
34+
expect(getAngleType(180)).toEqual("Straight angle");
35+
});
1936
// Case 5: Reflex angles
37+
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
38+
// Test various reflex angles, including boundary cases
39+
expect(getAngleType(181)).toEqual("Reflex angle");
40+
expect(getAngleType(270)).toEqual("Reflex angle");
41+
expect(getAngleType(359)).toEqual("Reflex angle");
42+
});
2043
// Case 6: Invalid angles
44+
test(`should return "Invalid angle" when (angle < 0 || angle > 360)`, () => {
45+
// Test various invalid angles
46+
expect(getAngleType(-1)).toEqual("Invalid angle");
47+
expect(getAngleType(361)).toEqual("Invalid angle");
48+
expect(getAngleType(0)).toEqual("Invalid angle");
49+
});
50+

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,24 @@
33
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.
6+
test(`should return True when denominator is positive and less than numerator`, () => {
7+
expect(isProperFraction(1, 2)).toEqual(true);
8+
expect(isProperFraction(-1, 2)).toEqual(true );
9+
expect(isProperFraction(1, 10)).toEqual(true);
10+
});
11+
12+
test(`should return false when denominator is less than numerator`, () => {
13+
expect(isProperFraction(22, 20)).toEqual(false);
14+
expect(isProperFraction(11, 10)).toEqual(false);
15+
});
16+
17+
test(`should return false when denominator and numerator are equal`, () => {
18+
expect(isProperFraction(1, 1)).toEqual(false);
19+
expect(isProperFraction(-1, -1)).toEqual(false);
20+
});
621

722
// Special case: numerator is zero
823
test(`should return false when denominator is zero`, () => {
924
expect(isProperFraction(1, 0)).toEqual(false);
25+
expect(isProperFraction(-1, 0)).toEqual(false);
1026
});

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

Lines changed: 26 additions & 0 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+
test(`Should return 10 when given a number card`, () => {
15+
expect(getCardValue("2♠")).toEqual(2);
16+
expect(getCardValue("3♦")).toEqual(3);
17+
expect(getCardValue("4♣")).toEqual(4);
18+
expect(getCardValue("5♠")).toEqual(5);
19+
expect(getCardValue("6♦")).toEqual(6);
20+
expect(getCardValue("7♣")).toEqual(7);
21+
expect(getCardValue("8♠")).toEqual(8);
22+
expect(getCardValue("9♦")).toEqual(9);
23+
expect(getCardValue("10♣")).toEqual(10);
24+
});
1425
// Face Cards (J, Q, K)
26+
test(`Should return 10 when given a number card`, () => {
27+
expect(getCardValue("K♠")).toEqual(10);
28+
expect(getCardValue("q♦")).toEqual(10);
29+
expect(getCardValue("J♣")).toEqual(10);
30+
});
31+
1532
// Invalid Cards
33+
test(`Should return Invalid Cards when given invalid inputs`, () => {
34+
expect(() => getCardValue("")).toThrow();
35+
expect(() => getCardValue("11")).toThrow();
36+
expect(() => getCardValue("♠10")).toThrow();
37+
expect(() => getCardValue("invalid")).toThrow();
38+
expect(() => getCardValue("1♠")).toThrow();
39+
expect(() => getCardValue("ab")).toThrow();
40+
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:

coverage/clover.xml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<coverage generated="1783361519767" clover="3.2.0">
3+
<project timestamp="1783361519767" name="All files">
4+
<metrics statements="81" coveredstatements="80" conditionals="33" coveredconditionals="31" methods="10" coveredmethods="10" elements="124" coveredelements="121" complexity="0" loc="81" ncloc="81" packages="3" files="7" classes="7"/>
5+
<package name="1-implement-and-rewrite-tests.implement">
6+
<metrics statements="73" coveredstatements="72" conditionals="31" coveredconditionals="30" methods="6" coveredmethods="6"/>
7+
<file name="1-get-angle-type.js" path="/home/cyf/Documents/Dagim/prep/Module-Structuring-and-Testing-Data/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js">
8+
<metrics statements="33" coveredstatements="33" conditionals="16" coveredconditionals="16" methods="2" coveredmethods="2"/>
9+
<line num="19" count="24" type="cond" truecount="4" falsecount="0"/>
10+
<line num="21" count="5" type="stmt"/>
11+
<line num="23" count="19" type="cond" truecount="2" falsecount="0"/>
12+
<line num="25" count="2" type="stmt"/>
13+
<line num="27" count="17" type="cond" truecount="4" falsecount="0"/>
14+
<line num="29" count="4" type="stmt"/>
15+
<line num="31" count="13" type="cond" truecount="2" falsecount="0"/>
16+
<line num="33" count="3" type="stmt"/>
17+
<line num="35" count="10" type="cond" truecount="4" falsecount="0"/>
18+
<line num="37" count="4" type="stmt"/>
19+
<line num="41" count="6" type="stmt"/>
20+
<line num="47" count="1" type="stmt"/>
21+
<line num="52" count="10" type="stmt"/>
22+
<line num="60" count="1" type="stmt"/>
23+
<line num="61" count="1" type="stmt"/>
24+
<line num="63" count="1" type="stmt"/>
25+
<line num="64" count="1" type="stmt"/>
26+
<line num="66" count="1" type="stmt"/>
27+
<line num="67" count="1" type="stmt"/>
28+
<line num="69" count="1" type="stmt"/>
29+
<line num="70" count="1" type="stmt"/>
30+
<line num="72" count="1" type="stmt"/>
31+
<line num="73" count="1" type="stmt"/>
32+
<line num="75" count="1" type="stmt"/>
33+
<line num="76" count="1" type="stmt"/>
34+
<line num="78" count="1" type="stmt"/>
35+
<line num="79" count="1" type="stmt"/>
36+
<line num="81" count="1" type="stmt"/>
37+
<line num="82" count="1" type="stmt"/>
38+
<line num="84" count="1" type="stmt"/>
39+
<line num="85" count="1" type="stmt"/>
40+
<line num="87" count="1" type="stmt"/>
41+
<line num="88" count="1" type="stmt"/>
42+
</file>
43+
<file name="2-is-proper-fraction.js" path="/home/cyf/Documents/Dagim/prep/Module-Structuring-and-Testing-Data/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js">
44+
<metrics statements="14" coveredstatements="14" conditionals="2" coveredconditionals="2" methods="2" coveredmethods="2"/>
45+
<line num="15" count="16" type="stmt"/>
46+
<line num="16" count="16" type="stmt"/>
47+
<line num="17" count="16" type="cond" truecount="2" falsecount="0"/>
48+
<line num="19" count="6" type="stmt"/>
49+
<line num="22" count="10" type="stmt"/>
50+
<line num="27" count="1" type="stmt"/>
51+
<line num="31" count="7" type="stmt"/>
52+
<line num="41" count="1" type="stmt"/>
53+
<line num="43" count="1" type="stmt"/>
54+
<line num="44" count="1" type="stmt"/>
55+
<line num="45" count="1" type="stmt"/>
56+
<line num="46" count="1" type="stmt"/>
57+
<line num="47" count="1" type="stmt"/>
58+
<line num="48" count="1" type="stmt"/>
59+
</file>
60+
<file name="3-get-card-value.js" path="/home/cyf/Documents/Dagim/prep/Module-Structuring-and-Testing-Data/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js">
61+
<metrics statements="26" coveredstatements="25" conditionals="13" coveredconditionals="12" methods="2" coveredmethods="2"/>
62+
<line num="26" count="27" type="stmt"/>
63+
<line num="27" count="27" type="stmt"/>
64+
<line num="28" count="27" type="stmt"/>
65+
<line num="31" count="27" type="cond" truecount="2" falsecount="0"/>
66+
<line num="32" count="6" type="stmt"/>
67+
<line num="35" count="21" type="stmt"/>
68+
<line num="37" count="21" type="cond" truecount="5" falsecount="0"/>
69+
<line num="38" count="1" type="stmt"/>
70+
<line num="42" count="20" type="cond" truecount="2" falsecount="0"/>
71+
<line num="43" count="8" type="stmt"/>
72+
<line num="46" count="12" type="stmt"/>
73+
<line num="47" count="12" type="cond" truecount="3" falsecount="1"/>
74+
<line num="48" count="12" type="stmt"/>
75+
<line num="54" count="1" type="stmt"/>
76+
<line num="58" count="7" type="stmt"/>
77+
<line num="66" count="1" type="stmt"/>
78+
<line num="68" count="1" type="stmt"/>
79+
<line num="69" count="1" type="stmt"/>
80+
<line num="72" count="1" type="stmt"/>
81+
<line num="73" count="1" type="stmt"/>
82+
<line num="74" count="1" type="stmt"/>
83+
<line num="75" count="1" type="stmt"/>
84+
<line num="77" count="1" type="stmt"/>
85+
<line num="78" count="1" type="stmt"/>
86+
<line num="81" count="0" type="stmt"/>
87+
<line num="83" count="1" type="stmt"/>
88+
</file>
89+
</package>
90+
<package name="2-practice-tdd">
91+
<metrics statements="6" coveredstatements="6" conditionals="0" coveredconditionals="0" methods="3" coveredmethods="3"/>
92+
<file name="count.js" path="/home/cyf/Documents/Dagim/prep/Module-Structuring-and-Testing-Data/Sprint-3/2-practice-tdd/count.js">
93+
<metrics statements="2" coveredstatements="2" conditionals="0" coveredconditionals="0" methods="1" coveredmethods="1"/>
94+
<line num="2" count="1" type="stmt"/>
95+
<line num="5" count="1" type="stmt"/>
96+
</file>
97+
<file name="get-ordinal-number.js" path="/home/cyf/Documents/Dagim/prep/Module-Structuring-and-Testing-Data/Sprint-3/2-practice-tdd/get-ordinal-number.js">
98+
<metrics statements="2" coveredstatements="2" conditionals="0" coveredconditionals="0" methods="1" coveredmethods="1"/>
99+
<line num="2" count="2" type="stmt"/>
100+
<line num="5" count="1" type="stmt"/>
101+
</file>
102+
<file name="repeat-str.js" path="/home/cyf/Documents/Dagim/prep/Module-Structuring-and-Testing-Data/Sprint-3/2-practice-tdd/repeat-str.js">
103+
<metrics statements="2" coveredstatements="2" conditionals="0" coveredconditionals="0" methods="1" coveredmethods="1"/>
104+
<line num="4" count="1" type="stmt"/>
105+
<line num="7" count="1" type="stmt"/>
106+
</file>
107+
</package>
108+
<package name="4-stretch">
109+
<metrics statements="2" coveredstatements="2" conditionals="2" coveredconditionals="1" methods="1" coveredmethods="1"/>
110+
<file name="password-validator.js" path="/home/cyf/Documents/Dagim/prep/Module-Structuring-and-Testing-Data/Sprint-3/4-stretch/password-validator.js">
111+
<metrics statements="2" coveredstatements="2" conditionals="2" coveredconditionals="1" methods="1" coveredmethods="1"/>
112+
<line num="2" count="1" type="cond" truecount="1" falsecount="1"/>
113+
<line num="6" count="1" type="stmt"/>
114+
</file>
115+
</package>
116+
</project>
117+
</coverage>

0 commit comments

Comments
 (0)