From 4ea74f505b84ae78a1d7e2e3d8985c048048d778 Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Wed, 8 Jul 2026 19:46:11 +0100
Subject: [PATCH 01/10] function and assertion tests completed
---
.../implement/1-get-angle-type.js | 29 ++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
index 9e05a871e2..c6f90d208c 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
@@ -15,7 +15,19 @@
// execute the code to ensure all tests pass.
function getAngleType(angle) {
- // TODO: Implement this function
+ if(angle > 0 && angle < 90){
+ return "Acute angle"
+ }else if(angle === 90){
+ return "Right angle"
+ }else if(angle > 90 && angle < 180){
+ return "Obtuse angle"
+ }else if(angle === 180){
+ return "Straight angle"
+ }else if(angle > 180 && angle < 360){
+ return "Reflex angle"
+ }else{
+ return "Invalid angle"
+ }
}
// The line below allows us to load the getAngleType function into tests in other files.
@@ -35,3 +47,18 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");
+
+const invalid = getAngleType(0);
+assertEquals(invalid, "Invalid angle");
+
+const acute = getAngleType(89);
+assertEquals(acute, "Acute angle");
+
+const obtuse = getAngleType(91);
+assertEquals(obtuse, "Obtuse angle");
+
+const straight = getAngleType(180);
+assertEquals(straight, "Straight angle")
+
+const invalid1 = getAngleType(360);
+assertEquals(invalid1, "Invalid angle")
\ No newline at end of file
From ecd12aa869395168eef5d650843f7a0bf3d855ea Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Wed, 8 Jul 2026 19:55:44 +0100
Subject: [PATCH 02/10] reformatted
---
.../implement/1-get-angle-type.js | 34 +++++++++----------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
index c6f90d208c..ea542bf2ff 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
@@ -15,19 +15,19 @@
// execute the code to ensure all tests pass.
function getAngleType(angle) {
- if(angle > 0 && angle < 90){
- return "Acute angle"
- }else if(angle === 90){
- return "Right angle"
- }else if(angle > 90 && angle < 180){
- return "Obtuse angle"
- }else if(angle === 180){
- return "Straight angle"
- }else if(angle > 180 && angle < 360){
- return "Reflex angle"
- }else{
- return "Invalid angle"
- }
+ if (angle > 0 && angle < 90) {
+ return "Acute angle"
+ } else if (angle === 90) {
+ return "Right angle"
+ } else if (angle > 90 && angle < 180) {
+ return "Obtuse angle"
+ } else if (angle === 180) {
+ return "Straight angle"
+ } else if (angle > 180 && angle < 360) {
+ return "Reflex angle"
+ } else {
+ return "Invalid angle"
+ }
}
// The line below allows us to load the getAngleType function into tests in other files.
@@ -37,10 +37,10 @@ module.exports = getAngleType;
// This helper function is written to make our assertions easier to read.
// If the actual output matches the target output, the test will pass
function assertEquals(actualOutput, targetOutput) {
- console.assert(
- actualOutput === targetOutput,
- `Expected ${actualOutput} to equal ${targetOutput}`
- );
+ console.assert(
+ actualOutput === targetOutput,
+ `Expected ${actualOutput} to equal ${targetOutput}`
+ );
}
// TODO: Write tests to cover all cases, including boundary and invalid cases.
From a4ba8bc5f2ac9f58fdbddb3f476c374174bb1a1c Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Wed, 8 Jul 2026 20:04:01 +0100
Subject: [PATCH 03/10] added more test cases to cover all boundaries
---
.../implement/1-get-angle-type.js | 20 ++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
index ea542bf2ff..a15aa98125 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
@@ -61,4 +61,22 @@ const straight = getAngleType(180);
assertEquals(straight, "Straight angle")
const invalid1 = getAngleType(360);
-assertEquals(invalid1, "Invalid angle")
\ No newline at end of file
+assertEquals(invalid1, "Invalid angle")
+
+const acute1 = getAngleType(1);
+assertEquals(acute1, "Acute angle")
+
+const obtuse1 = getAngleType(179);
+assertEquals(obtuse1, "Obtuse angle")
+
+const reflex = getAngleType(181);
+assertEquals(reflex, "Reflex angle")
+
+const reflex1 = getAngleType(359);
+assertEquals(reflex1, "Reflex angle")
+
+const invalid2 = getAngleType(-1);
+assertEquals(invalid2, "Invalid angle")
+
+const invalid3 = getAngleType(361);
+assertEquals(invalid3, "Invalid angle")
\ No newline at end of file
From 822fcbcc2a38226dd7e1d4387ae71d2f70ec9f6d Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Wed, 8 Jul 2026 20:46:30 +0100
Subject: [PATCH 04/10] implemented the function and added test cases to cover
all boundaries
---
.../implement/2-is-proper-fraction.js | 37 ++++++++++++++++---
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js
index 970cb9b641..afbb588f4b 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js
@@ -11,7 +11,11 @@
// execute the code to ensure all tests pass.
function isProperFraction(numerator, denominator) {
- // TODO: Implement this function
+ if (Number.isFinite(numerator) && Number.isFinite(denominator)) {
+ if(numerator < denominator){
+ return true
+ }
+ } return false
}
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -20,10 +24,10 @@ module.exports = isProperFraction;
// Here's our helper again
function assertEquals(actualOutput, targetOutput) {
- console.assert(
- actualOutput === targetOutput,
- `Expected ${actualOutput} to equal ${targetOutput}`
- );
+ console.assert(
+ actualOutput === targetOutput,
+ `Expected ${actualOutput} to equal ${targetOutput}`
+ );
}
// TODO: Write tests to cover all cases.
@@ -31,3 +35,26 @@ function assertEquals(actualOutput, targetOutput) {
// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
+assertEquals(isProperFraction(2, 1), false);
+assertEquals(isProperFraction(5, 5), false);
+assertEquals(isProperFraction(0, 5), true);
+assertEquals(isProperFraction(5, 0), false);
+assertEquals(isProperFraction(0, 0), false);
+assertEquals(isProperFraction(-1, 2), true);
+assertEquals(isProperFraction(1, -2), false);
+assertEquals(isProperFraction(-2, -1), true);
+assertEquals(isProperFraction(-1, -2), false);
+assertEquals(isProperFraction(0.5, 1), true);
+assertEquals(isProperFraction(1.5, 1), false);
+assertEquals(isProperFraction(Infinity, 2), false);
+assertEquals(isProperFraction(2, Infinity), false);
+assertEquals(isProperFraction(NaN, 2), false);
+assertEquals(isProperFraction(2, NaN), false);
+assertEquals(isProperFraction(999999999, 1000000000), true);
+
+
+
+
+
+
+
From 1a96b7dbd5b616532e3989a288d3fa8c89a1ab8b Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Thu, 16 Jul 2026 20:34:04 +0100
Subject: [PATCH 05/10] completed and tested card game
---
.../implement/3-get-card-value.js | 79 +++++++++++++++++--
1 file changed, 74 insertions(+), 5 deletions(-)
diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
index ff5c532e1d..f2edf84d6c 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
@@ -22,9 +22,37 @@
// execute the code to ensure all tests pass.
function getCardValue(card) {
- // TODO: Implement this function
+ const rank = card.slice(0, card.length -1).toUpperCase()
+ const suit = card.slice(card.length -1)
+
+ const suits = ["♠", "♥", "♦", "♣"];
+ const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
+
+ // Basic validation
+ if(card === ""){
+ throw new Error("No card was played")
+ }
+ if(card.length < 2 || card.length > 3 ){
+ throw new Error("Invalid card played, rank and suit cannot be less than 1 or more than 3")
+ }
+ // Suit validation
+ if(!suits.includes(suit)){
+ throw new Error("Invalid card played, suit is missing");
+ }
+ // Rank validation
+ if(!validRanks.includes(rank)){
+ throw new Error("Invalid rank played")
+ }
+ if(rank === "A"){
+ return 11
+ }else if(rank === "J" || rank === "Q" || rank === "K"){
+ return 10
+ }else{
+ return Number(rank)
+ }
}
+
// The line below allows us to load the getCardValue function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getCardValue;
@@ -37,18 +65,59 @@ function assertEquals(actualOutput, targetOutput) {
);
}
-// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
-assertEquals(getCardValue("9♠"), 9);
+assertEquals(getCardValue("A♠"), 11);
+assertEquals(getCardValue("A♥"), 11);
+assertEquals(getCardValue("A♦"), 11);
+assertEquals(getCardValue("A♣"), 11);
+assertEquals(getCardValue("2♠"), 2);
+assertEquals(getCardValue("3♥"), 3);
+assertEquals(getCardValue("4♦"), 4);
+assertEquals(getCardValue("5♣"), 5);
+assertEquals(getCardValue("6♠"), 6);
+assertEquals(getCardValue("7♥"), 7);
+assertEquals(getCardValue("8♦"), 8);
+assertEquals(getCardValue("9♣"), 9);
+assertEquals(getCardValue("10♠"), 10);
+assertEquals(getCardValue("J♠"), 10);
+assertEquals(getCardValue("Q♥"), 10);
+assertEquals(getCardValue("K♦"), 10);
// Handling invalid cards
try {
- getCardValue("invalid");
+ getCardValue("");
// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
- console.log("Error thrown for invalid card 🎉");
+ console.log(e);
}
// What other invalid card cases can you think of?
+try{
+ getCardValue("100");
+ console.error("Error was not thrown for card with more than 3 in length");
+} catch (e){
+ console.log(e)
+}
+try{
+ getCardValue("1")
+ console.error("Error was not thrown for a card.lenght = 1")
+}catch (e){
+ console.log(e)
+}
+
+try{
+ getCardValue("♦")
+ console.error("Error was not thrown for a card play of just suits")
+}catch (e){
+ console.log(e)
+}
+
+try{
+ getCardValue("A😊")
+ console.error("Error was not thrown for a card play of a wrong suit")
+}catch (e){
+ console.log(e)
+}
+
From c727523a25f407526af488f774215702ae2dd88d Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Fri, 17 Jul 2026 19:53:02 +0100
Subject: [PATCH 06/10] adding additional test
---
.../implement/3-get-card-value.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
index f2edf84d6c..944611664d 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
@@ -93,7 +93,7 @@ try {
console.log(e);
}
-// What other invalid card cases can you think of?
+// What other invalid card cases can you think of?
try{
getCardValue("100");
console.error("Error was not thrown for card with more than 3 in length");
@@ -121,3 +121,4 @@ try{
console.log(e)
}
+
From 62aab55b7b9f742028b80ba86a8660ff88701528 Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Sun, 19 Jul 2026 14:45:32 +0100
Subject: [PATCH 07/10] all jest tests pass in 1-angle-type.js
---
.../implement/1-get-angle-type.js | 10 +++----
.../1-get-angle-type.test.js | 27 ++++++++++++++++---
2 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
index a15aa98125..1f3383ff62 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
@@ -17,13 +17,13 @@
function getAngleType(angle) {
if (angle > 0 && angle < 90) {
return "Acute angle"
- } else if (angle === 90) {
+ } if (angle === 90) {
return "Right angle"
- } else if (angle > 90 && angle < 180) {
+ } if (angle > 90 && angle < 180) {
return "Obtuse angle"
- } else if (angle === 180) {
+ } if (angle === 180) {
return "Straight angle"
- } else if (angle > 180 && angle < 360) {
+ } if (angle > 180 && angle < 360) {
return "Reflex angle"
} else {
return "Invalid angle"
@@ -78,5 +78,3 @@ assertEquals(reflex1, "Reflex angle")
const invalid2 = getAngleType(-1);
assertEquals(invalid2, "Invalid angle")
-const invalid3 = getAngleType(361);
-assertEquals(invalid3, "Invalid angle")
\ No newline at end of file
diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js
index d777f348d3..4e6978d729 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js
@@ -2,7 +2,6 @@
// We will use the same function, but write tests for it using Jest in this file.
const getAngleType = require("../implement/1-get-angle-type");
-// TODO: Write tests in Jest syntax to cover all cases/outcomes,
// including boundary and invalid cases.
// Case 1: Acute angles
@@ -13,8 +12,30 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
expect(getAngleType(89)).toEqual("Acute angle");
});
-// Case 2: Right angle
-// Case 3: Obtuse angles
+
+// Case 2: Obtuse angle
+test(`should return "obtuse angle" when (90 < angle < 180 `, () =>{
+ expect(getAngleType(91)).toEqual("Obtuse angle");
+ expect(getAngleType(179)).toEqual("Obtuse angle");
+
+})
+// Case 3: Right angles
+test(`should return "Right angle" when (angle === 90)`, () => {
+ expect(getAngleType(90)).toEqual("Right angle");
+})
+
// Case 4: Straight angle
+test(`should return "Straight angle" when (angle === 180)`, () => {
+ expect(getAngleType(180)).toEqual("Straight angle")
+})
// Case 5: Reflex angles
+test(`should return "Reflect angle" when (180 < angle < 360))`, () => {
+ expect(getAngleType(181)).toEqual("Reflex angle");
+ expect(getAngleType(359)).toEqual("Reflex angle");
+})
// Case 6: Invalid angles
+test(`should return "Invalid angle" when (0 > angle > 360)`, () => {
+ expect(getAngleType(0)).toEqual("Invalid angle");
+ expect(getAngleType(360)).toEqual("Invalid angle");
+ expect(getAngleType(-1)).toEqual("Invalid angle");
+})
From 09fe227d8b7431b1dd4b54e583845fed63595b9c Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Sun, 19 Jul 2026 15:23:54 +0100
Subject: [PATCH 08/10] all jest tests pass in 2-is-proper-fraction.js
---
.../2-is-proper-fraction.test.js | 27 +++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js
index 7f087b2ba1..7fb0cd4c9f 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js
@@ -2,9 +2,32 @@
// We will use the same function, but write tests for it using Jest in this file.
const isProperFraction = require("../implement/2-is-proper-fraction");
-// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
// Special case: numerator is zero
test(`should return false when denominator is zero`, () => {
- expect(isProperFraction(1, 0)).toEqual(false);
+ expect(isProperFraction(1,2 )).toEqual(true);
+ expect(isProperFraction(2,1)).toEqual(false);
+ expect(isProperFraction(5,5)).toEqual(false);
+ expect(isProperFraction(0,5)).toEqual(true);
+ expect(isProperFraction(5,0)).toEqual(false);
+ expect(isProperFraction(0,0)).toEqual(false);
+ expect(isProperFraction(-1,2)).toEqual(true);
+ expect(isProperFraction(1,-2)).toEqual(false);
+ expect(isProperFraction(-2,-1)).toEqual(true);
+ expect(isProperFraction(-1,-2)).toEqual(false);
+ expect(isProperFraction(0.5,1)).toEqual(true);
+ expect(isProperFraction(1.5,1)).toEqual(false);
+ expect(isProperFraction(Infinity,2)).toEqual(false);
+ expect(isProperFraction(2,Infinity)).toEqual(false);
+ expect(isProperFraction(NaN,2)).toEqual(false)
+ expect(isProperFraction(2,NaN)).toEqual(false);
+ expect(isProperFraction(999999999, 1000000000)).toEqual(true)
+
+
+
+
+
+
+
+
});
From 8270fd63f275ff3034e62af8a70cf5ef3632ecc5 Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Sun, 19 Jul 2026 16:38:41 +0100
Subject: [PATCH 09/10] refactored
---
.../implement/3-get-card-value.js | 75 ++++++++++---------
1 file changed, 38 insertions(+), 37 deletions(-)
diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
index 944611664d..94b781830f 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
@@ -22,34 +22,35 @@
// execute the code to ensure all tests pass.
function getCardValue(card) {
- const rank = card.slice(0, card.length -1).toUpperCase()
- const suit = card.slice(card.length -1)
-
- const suits = ["♠", "♥", "♦", "♣"];
- const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
-
- // Basic validation
- if(card === ""){
+ // Basic validation: validating the input before slicing
+ if (card === "") {
throw new Error("No card was played")
}
- if(card.length < 2 || card.length > 3 ){
+ if (card.length < 2 || card.length > 3) {
throw new Error("Invalid card played, rank and suit cannot be less than 1 or more than 3")
}
- // Suit validation
- if(!suits.includes(suit)){
+ const rank = card.slice(0, card.length - 1).toUpperCase()
+ const suit = card.slice(card.length - 1)
+
+ const validSuits = ["♠", "♥", "♦", "♣"];
+ const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
+
+ // Suit and rank validation
+ if (!validSuits.includes(suit)) {
throw new Error("Invalid card played, suit is missing");
}
- // Rank validation
- if(!validRanks.includes(rank)){
- throw new Error("Invalid rank played")
- }
- if(rank === "A"){
- return 11
- }else if(rank === "J" || rank === "Q" || rank === "K"){
- return 10
- }else{
- return Number(rank)
+ if (validRanks.includes(rank)) {
+ if (rank === "A") {
+ return 11;
+ } else if (rank === "J" || rank === "Q" || rank === "K") {
+ return 10;
+ } else {
+ return Number(rank);
+ }
+ } else {
+ throw new Error("Invalid rank");
}
+
}
@@ -59,10 +60,10 @@ module.exports = getCardValue;
// Helper functions to make our assertions easier to read.
function assertEquals(actualOutput, targetOutput) {
- console.assert(
- actualOutput === targetOutput,
- `Expected ${actualOutput} to equal ${targetOutput}`
- );
+ console.assert(
+ actualOutput === targetOutput,
+ `Expected ${actualOutput} to equal ${targetOutput}`
+ );
}
// Examples:
@@ -85,39 +86,39 @@ assertEquals(getCardValue("K♦"), 10);
// Handling invalid cards
try {
- getCardValue("");
+ getCardValue("");
- // This line will not be reached if an error is thrown as expected
- console.error("Error was not thrown for invalid card 😢");
+ // This line will not be reached if an error is thrown as expected
+ console.error("Error was not thrown for invalid card 😢");
} catch (e) {
- console.log(e);
+ console.log(e);
}
// What other invalid card cases can you think of?
-try{
+try {
getCardValue("100");
console.error("Error was not thrown for card with more than 3 in length");
-} catch (e){
+} catch (e) {
console.log(e)
}
-try{
+try {
getCardValue("1")
console.error("Error was not thrown for a card.lenght = 1")
-}catch (e){
+} catch (e) {
console.log(e)
}
-try{
+try {
getCardValue("♦")
console.error("Error was not thrown for a card play of just suits")
-}catch (e){
+} catch (e) {
console.log(e)
}
-try{
+try {
getCardValue("A😊")
console.error("Error was not thrown for a card play of a wrong suit")
-}catch (e){
+} catch (e) {
console.log(e)
}
From f09266784e24ed196a4e439e524c66087d97469a Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Sun, 19 Jul 2026 17:11:50 +0100
Subject: [PATCH 10/10] completed jest testing on card game and proper
fractions
---
.../implement/2-is-proper-fraction.js | 1 -
.../2-is-proper-fraction.test.js | 58 ++++++++++---------
.../3-get-card-value.test.js | 29 +++++++++-
3 files changed, 58 insertions(+), 30 deletions(-)
diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js
index afbb588f4b..9084237fa4 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js
@@ -30,7 +30,6 @@ function assertEquals(actualOutput, targetOutput) {
);
}
-// TODO: Write tests to cover all cases.
// What combinations of numerators and denominators should you test?
// Example: 1/2 is a proper fraction
diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js
index 7fb0cd4c9f..49b2e58352 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js
@@ -3,31 +3,35 @@
const isProperFraction = require("../implement/2-is-proper-fraction");
-// Special case: numerator is zero
-test(`should return false when denominator is zero`, () => {
- expect(isProperFraction(1,2 )).toEqual(true);
- expect(isProperFraction(2,1)).toEqual(false);
- expect(isProperFraction(5,5)).toEqual(false);
- expect(isProperFraction(0,5)).toEqual(true);
- expect(isProperFraction(5,0)).toEqual(false);
- expect(isProperFraction(0,0)).toEqual(false);
- expect(isProperFraction(-1,2)).toEqual(true);
- expect(isProperFraction(1,-2)).toEqual(false);
- expect(isProperFraction(-2,-1)).toEqual(true);
- expect(isProperFraction(-1,-2)).toEqual(false);
- expect(isProperFraction(0.5,1)).toEqual(true);
- expect(isProperFraction(1.5,1)).toEqual(false);
- expect(isProperFraction(Infinity,2)).toEqual(false);
- expect(isProperFraction(2,Infinity)).toEqual(false);
- expect(isProperFraction(NaN,2)).toEqual(false)
- expect(isProperFraction(2,NaN)).toEqual(false);
- expect(isProperFraction(999999999, 1000000000)).toEqual(true)
-
-
-
-
-
-
-
-
+test("should correctly identify proper fractions", () => {
+ // Whole number fractions
+ expect(isProperFraction(1, 2)).toEqual(true);
+ expect(isProperFraction(2, 1)).toEqual(false);
+ expect(isProperFraction(5, 5)).toEqual(false);
+
+ // Zero
+ expect(isProperFraction(0, 5)).toEqual(true);
+ expect(isProperFraction(5, 0)).toEqual(false);
+ expect(isProperFraction(0, 0)).toEqual(false);
+
+ // Negative numbers
+ expect(isProperFraction(-1, 2)).toEqual(true);
+ expect(isProperFraction(1, -2)).toEqual(false);
+ expect(isProperFraction(-2, -1)).toEqual(true);
+ expect(isProperFraction(-1, -2)).toEqual(false);
+
+ // Decimal numbers
+ expect(isProperFraction(0.5, 1)).toEqual(true);
+ expect(isProperFraction(1.5, 1)).toEqual(false);
+
+ // Infinity
+ expect(isProperFraction(Infinity, 2)).toEqual(false);
+ expect(isProperFraction(2, Infinity)).toEqual(false);
+
+ // NaN
+ expect(isProperFraction(NaN, 2)).toEqual(false);
+ expect(isProperFraction(2, NaN)).toEqual(false);
+
+ // Large numbers
+ expect(isProperFraction(999999999, 1000000000)).toEqual(true);
});
diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js
index cf7f9dae2e..2ab7e47d80 100644
--- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js
+++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js
@@ -2,17 +2,42 @@
// We will use the same function, but write tests for it using Jest in this file.
const getCardValue = require("../implement/3-get-card-value");
-// TODO: Write tests in Jest syntax to cover all possible outcomes.
// Case 1: Ace (A)
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});
-// Suggestion: Group the remaining test data into these categories:
+// Suggestion: Group the remaining test data into these categories: // ♠ ♥ ♦ ♣
// Number Cards (2-10)
+test(`Should return the card's numeric rank for cards 2 through 10`, () =>{
+ expect(getCardValue("2♠")).toEqual(2);
+ expect(getCardValue("3♥")).toEqual(3);
+ expect(getCardValue("4♦")).toEqual(4);
+ expect(getCardValue("5♣")).toEqual(5);
+ expect(getCardValue("6♠")).toEqual(6);
+ expect(getCardValue("7♥")).toEqual(7);
+ expect(getCardValue("8♦")).toEqual(8);
+ expect(getCardValue("9♣")).toEqual(9);
+ expect(getCardValue("10♠")).toEqual(10);
+
+})
// Face Cards (J, Q, K)
+test(`should return 10 When the card is a face card ("J", "Q", "K")`, () => {
+ expect(getCardValue("j♠")).toEqual(10);
+ expect(getCardValue("k♦")).toEqual(10);
+ expect(getCardValue("q♣")).toEqual(10);
+
+})
// Invalid Cards
+test("should throw an error when an invalid card is played", () => {
+ expect(() => getCardValue("")).toThrow("No card was played");
+ expect(() => getCardValue("1009♣")).toThrow("Invalid card played, rank and suit cannot be less " +
+ "than 1 or more than 3")
+
+});
+
+
// To learn how to test whether a function throws an error as expected in Jest,
// please refer to the Jest documentation: