Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
bfd3913
1-get-angle-type Comment out pseudo code Give-when-then
Oct 9, 2026
1f731d2
2-is-proper-fraction Add comments to clarify the isProperFraction fu…
Oct 9, 2026
4ef98cd
3-get-card-value.js Add comments to clarify the isProperFraction func…
Oct 9, 2026
c44e20a
Implement getAngleType function to determine angle types based on inp…
Oct 9, 2026
06782aa
2-is-proper-fraction.js implement the function isProperFraction, adde…
Oct 9, 2026
b405180
1-get-angle-type.js fixed typo for test
AlanGit-debug2604 Oct 10, 2026
327decd
1-get-angle-type.test.js write 9 additional test cases. Ran tests.
AlanGit-debug2604 Oct 10, 2026
88a6000
3-get-card-value.js added implementation code, define string as input…
AlanGit-debug2604 Oct 10, 2026
401ad2b
2-is-proper-fraction.test wrote 8 additional test cases: equal , impr…
AlanGit-debug2604 Oct 11, 2026
acfaabd
2-is-proper-fraction edited denominator=0 to correct exception for …
AlanGit-debug2604 Oct 11, 2026
a963f0f
3-getCardValue function to provide specific error messages for invali…
AlanGit-debug2604 Oct 11, 2026
19d4b52
Add tests for invalid rank and suit inputs in getCardValue function
AlanGit-debug2604 Oct 11, 2026
52e4cd1
Refactor getCardValue function to improve error handling for invalid …
Oct 12, 2026
3064fb8
Tests for getCardValue function to improve clarity and error messagin…
Oct 12, 2026
8edda76
test: rewrite getAngleType tests with Jest
Oct 13, 2026
af9a958
2-is-proper-fraction jest test: expand isProperFraction tests to cove…
AlanGit-debug2604 Oct 13, 2026
77f89cc
3-get-card-value write jest tests to cover additional edge cases and…
AlanGit-debug2604 Oct 13, 2026
01e3987
2-is-proper-fraction jest test: numbering cases in comment for easy c…
AlanGit-debug2604 Oct 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,58 @@ test("Classifies right angles", () => {
const right = getAngleType(90);
assert.equal(right, "Right angle");
});

test("Classifies obtuse angles", () => {
const right = getAngleType(91);
assert.equal(right, "Obtuse angle");
});

test("Classifies obtuse angles", () => {
const right = getAngleType(179);
assert.equal(right, "Obtuse angle");
});

test("Classifies Straight angles", () => {
const right = getAngleType(180);
assert.equal(right, "Straight angle");
});

test("Classifies Reflex angles", () => {
const right = getAngleType(181);
assert.equal(right, "Reflex angle");
});

test("Classifies Reflex angles", () => {
const right = getAngleType(359);
assert.equal(right, "Reflex angle");
});

test("Classifies Reflex angles", () => {
const right = getAngleType(360);
assert.equal(right, "Reflex angle");
});

test("Classifies Invalid angles", () => {
const right = getAngleType(361);
assert.equal(right, "Invalid angle");
});

test("Classifies Invalid angles", () => {
const right = getAngleType(361);
assert.equal(right, "Invalid angle");
});

test("Classifies Invalid angles", () => {
const right = getAngleType(-1);
assert.equal(right, "Invalid angle");
});




// - "Acute angle" for angles greater than 0° and less than 90°
// - "Right angle" for exactly 90°
// - "Obtuse angle" for angles greater than 90° and less than 180°
// - "Straight angle" for exactly 180°
// - "Reflex angle" for angles greater than 180° and less than 360°
// - "Invalid angle" for angles outside the valid range.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,35 @@ test("Basic proper fraction", () => {
// Example: 1/2 is a proper fraction
assert.equal(isProperFraction(1, 2), true);
});

test("Equal numerator and denominator is not a proper fraction", () => {
assert.equal(isProperFraction(2, 2), false);
});

test("Improper fraction is false", () => {
assert.equal(isProperFraction(3, 2), false);
});

test("Zero numerator with positive denominator is a proper fraction", () => {
assert.equal(isProperFraction(0, 2), true);
});

test("Non-numeric numerator throws TypeError", () => {
assert.throws(() => isProperFraction("1", 2), TypeError);
});

test("Non-numeric denominator throws TypeError", () => {
assert.throws(() => isProperFraction(1, "2"), TypeError);
});

test("NaN numerator throws TypeError", () => {
assert.throws(() => isProperFraction(Number.NaN, 2), TypeError);
});

test("Infinity denominator throws TypeError", () => {
assert.throws(() => isProperFraction(1, Number.POSITIVE_INFINITY), TypeError);
});

test("Denominator is 0 throws TypeError", () => {
assert.throws(() => isProperFraction(1, 0), TypeError);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,40 @@ test("Valid single-digit card", () => {
assert.equal(getCardValue("9♠"), 9);
});

test("Arbitrary non-card string", () => {
assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error");
test("Invalid Rank", () => {
assert.throws(
() => getCardValue("1♥"),
/Invalid Rank/,
"Expected clear error"
);
});

test("Invalid Suit", () => {
assert.throws(
() => getCardValue("9x"),
/Invalid Suit/,
"Expected clear error"
);
});

test("Non-string input", () => {
assert.throws(
() => getCardValue(9),
/Input not a string/,
"Expected clear error"
);
});
// TODO: What other invalid card cases can you think of?
//Invalid Rank or
//Invalid String
////Out of range input
//Input: (Rank) "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" and (Suit), also invalid input
//Input type: String
//Process Turn input into Num : "A" to 11 ; ("J", "Q", "K") to 10
//Output : a valid Num , or invalid throw error
//const rank
//const suit
//Edge cases 0: not string
//Edge cases 1: ANy first letter which is not a Rank;
//Edge cases 2: Any second character which is not a Suit
//Edge cases 3: Both Rank plus Suit input invalid;
29 changes: 29 additions & 0 deletions implement-and-rewrite-tests/implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,33 @@

export function getAngleType(angle) {
// TODO: Implement this function

if (angle < 0 || angle > 360) {
return `Invalid angle`;
}
if (angle < 90) {
return `Acute angle`;
}
if (angle == 90) {
return `Right angle`;
}
if (angle === 180) {
return `Straight angle`;
}
if (angle < 180) {
return `Obtuse angle`;
}
return `Reflex angle`;
}

//Pseudo codes
//First define type: Num (whole number)
//Then range: 0 - 360
//Cases:
//1. 0-89 : Actute angle
//2. 90 : Right angle
//3. 91-179: Obtuse angle
//4. 180: Straight angle
//5. 181-359 : Reflex angle
//6. 360 and beyond Invalid angle
//Key word to use : If?
24 changes: 24 additions & 0 deletions implement-and-rewrite-tests/implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,28 @@

export function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (typeof numerator !== "number" || typeof denominator !== "number") {
throw new TypeError("Both arguments must be numbers");
}
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)) {
throw new TypeError("Both arguments must be numbers");
}

if (denominator === 0) {
throw new TypeError("Denominator cannot be zero");
}

if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
}

return false;
}

//Cases show cases
//Proper function ; improper function
//Input type: Num
//Process : number to logic test
//Output type: boolean or error
//Edge case : negative number
//Edge case: decimal
51 changes: 51 additions & 0 deletions implement-and-rewrite-tests/implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,55 @@

export function getCardValue(card) {
// TODO: Implement this function
if (typeof card !== "string") {
throw new TypeError("Input not a string");
}
const Rank = card.slice(0, -1);
const Suit = card.slice(-1);
const validRanks = [
"A",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
];
const validSuits = ["♠", "♥", "♦", "♣"];

if (!validRanks.includes(Rank)) {
throw new Error("Invalid Rank");
}

if (!validSuits.includes(Suit)) {
throw new Error("Invalid Suit");
}

if (Rank === "A") {
return 11;
}

if (["J", "Q", "K"].includes(Rank)) {
return 10;
}

return Number(Rank);
}

//Case showcases
//Input: (Rank) "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" and (Suit), also invalid input
//Input type: String
//Process Turn input into Num : "A" to 11 ; ("J", "Q", "K") to 10
//Output : a valid Num , or invalid throw error
//const rank
//const suit
//Edge cases 0: not string
//Edge cases 1: ANy first letter which is not a Rank;
//Edge cases 2: Not a Rank plus Suit input;
//Edge cases 3: Suit mistyped ; or second character is not a suit
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,61 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// Case 2: Right angle
test(`should return "Right angle" when angle = 90`, () => {
expect(getAngleType(90)).toEqual("Right angle");
});
// Case 3: Obtuse angles
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
// Test various obtuse angles, including boundary cases
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(135)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse 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 "Reflex angle" when (180 < angle < 360)`, () => {
// Test various reflex angles, including boundary cases
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(225)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test(`should return "Invalid angle" when (angle < 0 or angle > 360)`, () => {
// Test various invalid angles, including boundary cases
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(361)).toEqual("Invalid angle");
expect(getAngleType(-0.5)).toEqual("Invalid angle");
});

//test("Classifies right angles", () => {
// const right = getAngleType(90);

//test("Classifies obtuse angles", () => {
// const right = getAngleType(91);

//test("Classifies obtuse angles", () => {
// const right = getAngleType(179);

//test("Classifies Straight angles", () => {
// const right = getAngleType(180);

//test("Classifies Reflex angles", () => {
// const right = getAngleType(181);

//test("Classifies Reflex angles", () => {
// const right = getAngleType(359);

//test("Classifies Reflex angles", () => {
// const right = getAngleType(360);

//test("Classifies Invalid angles", () => {
// const right = getAngleType(361);

//test("Classifies Invalid angles", () => {
// const right = getAngleType(361);

//test("Classifies Invalid angles", () => {
// const right = getAngleType(-1);
Loading
Loading