Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ede90ec
modified the import function to come first. written the condition of …
leerogerfn Oct 7, 2026
c7e5979
written condition for straight angle and confirm the test is success.
leerogerfn Oct 7, 2026
6973f9e
written condition for obtuse angle and test successful.
leerogerfn Oct 7, 2026
855ddcc
written condition for right angle and confirm the test successful.
leerogerfn Oct 7, 2026
56b9d32
written condition for acute angle and test successful.
leerogerfn Oct 7, 2026
f406580
written condition for invalid angle. confirm the test successful.
leerogerfn Oct 7, 2026
70fd5b5
initialise the test.
leerogerfn Oct 7, 2026
5b8ba78
written functions and test successful for success fraction
leerogerfn Oct 7, 2026
09cd676
initialised test for 3-get-card-value
leerogerfn Oct 7, 2026
d8839f1
written function for get-card-value
leerogerfn Oct 9, 2026
a0ed029
Complete the Jest test for 1-get-angle-type-test.
leerogerfn Oct 10, 2026
4c5ad3a
completed the jest test for 2-proper-fraction-test.js
leerogerfn Oct 10, 2026
f0d67f2
initialise package.json
leerogerfn Oct 10, 2026
5114047
modified the throw error in jest test in 1-get-card-value.
leerogerfn Oct 11, 2026
c67d63d
format document
leerogerfn Oct 11, 2026
ccb7a54
revise function and test for getAngleType
leerogerfn Oct 15, 2026
3334102
revised function and test for isProperFraction
leerogerfn Oct 15, 2026
6f0f79f
revised test and function for getCardValue
leerogerfn Oct 16, 2026
ddb16d2
revised function and test for getAngleType.
leerogerfn Oct 16, 2026
cd2a653
added test result for denominator and numerator are equal.
leerogerfn Oct 16, 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
@@ -1,12 +1,41 @@
import { getAngleType } from "../implement/1-get-angle-type.js";
import assert from "node:assert";
import test from "node:test";

import { getAngleType } from "../implement/1-get-angle-type.js";

// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles

test("Classifies right angles", () => {
const right = getAngleType(90);
assert.equal(right, "Right angle");
test("Classifies acute angle", () => {
assert.equal(getAngleType(45), "Acute angle");
});

test("Classifies right angle", () => {
assert.equal(getAngleType(90), "Right angle");
});

test("Classifies obtuse angle", () => {
assert.equal(getAngleType(120), "Obtuse angle");
});

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

test("Classifies reflex angle", () => {
assert.equal(getAngleType(200), "Reflex angle");
});

test("Classifies boundary and invalid angles", () => {
assert.equal(getAngleType(365), "invalid angle");
assert.equal(getAngleType(-10), "invalid angle");
assert.equal(getAngleType(0), "invalid angle");
assert.equal(getAngleType(""), "invalid angle");
assert.equal(getAngleType("angle"), "invalid angle");
assert.equal(getAngleType("null"), "invalid angle");
assert.equal(getAngleType(360), "invalid angle");
assert.equal(getAngleType(181), "Reflex angle");
assert.equal(getAngleType(91), "Obtuse angle");
assert.equal(getAngleType(179), "Obtuse angle");
assert.equal(getAngleType(89), "Acute angle");
assert.equal(getAngleType(1), "Acute angle");
});
Comment on lines +28 to 41

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two cases included here are general cases for invalid angles. There are two boundary cases as well. Can you think of them? If so, please add them as well. Thank you.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about numerator the same as denominator? how about zero in numerator or denominator? Should they return true or false? Please add them as well. Thank you.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good that two new test cases about testing zero and negative have been added. How about numerator is equal to denominator? Please add it as well. Thank you.

Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { isProperFraction } from "../implement/2-is-proper-fraction.js";
import assert from "node:assert";
import test from "node:test";

import { isProperFraction } from "../implement/2-is-proper-fraction.js";

// TODO: Write tests to cover all cases.
// What combinations of numerators and denominators should you test?

test("Basic proper fraction", () => {
// Example: 1/2 is a proper fraction
assert.equal(isProperFraction(1, 2), true);
});

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

test("Basic proper fraction", () => {
assert.equal(isProperFraction(0, 2), false);
});

test("Basic proper fraction", () => {
assert.equal(isProperFraction(2, -5), false);
});

test("Basic proper fraction", () => {
assert.equal(isProperFraction(1, 1), false);
});
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
import { getCardValue } from "../implement/3-get-card-value.js";
import assert from "node:assert";
import test from "node:test";

import { getCardValue } from "../implement/3-get-card-value.js";

// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.

test("Valid single-digit card", () => {
test("Valid number card", () => {
assert.equal(getCardValue("9♠"), 9);
});

test("Valid face card", () => {
assert.equal(getCardValue("K♦"), 10);
});

test("Valid ace card", () => {
assert.equal(getCardValue("A♥"), 11);
});

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

test("Invalid Rank", () => {
assert.throws(
() => getCardValue("12♥"),
/Valid rank: 2-10, A, J, Q, K only/,
"Expected clear error"
);
});

// TODO: What other invalid card cases can you think of?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be more test cases for invalid card, how about a card with correct number/face without suit? how about a card with correct suit but no number/face? how about a card missing both number/face and suite? how about a card with suit followed by a number/face? would 11♠ be valid or not? Please add more invalid card cases. Thank you.

18 changes: 16 additions & 2 deletions implement-and-rewrite-tests/implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

export function getAngleType(angle) {
// TODO: Implement this function
function getAngleType(angle) {
if (angle >= 360 || angle <= 0 || angle === "" || isNaN(angle)) {
return "invalid angle";
} else if (angle > 180 && angle < 360) {
return "Reflex angle";
} else if (angle === 180) {
return "Straight angle";
} else if (angle < 180 && angle > 90) {
return "Obtuse angle";
} else if (angle === 90) {
return "Right angle";
} else if (angle < 90 && angle > 0) {
return "Acute angle";
}
}

export { getAngleType };
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
// execute the code to ensure all tests pass.

export function isProperFraction(numerator, denominator) {
// TODO: Implement this function
return numerator > 0 && denominator > 0 && numerator < denominator;
}

console.log(isProperFraction(2, 6));
47 changes: 46 additions & 1 deletion implement-and-rewrite-tests/implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,52 @@
// Acceptance criteria:
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.
//const rank = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
//const suit = ["♠", "♥", "♦", "♣"];
//console.log(suit[1]);
//const card = `${number}${suit}`

//if the user input the rank only, the output is throwing an error.
//expect the format is 2 digit and follow the suit.
//validate input example: 3♠.
//Required the user input the card must include a suit. extract the final character from the input.

export function getCardValue(card) {
// TODO: Implement this function
const rank = card.slice(0, -1);
const suit = card.slice(-1);
const validRank = [
"A",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
].includes(rank);
const validSuit = ["♠", "♥", "♦", "♣"].includes(suit);
const validCard = validRank + validSuit;

if (!validCard || !validSuit || card.length > 3 || card.length < 2) {
throw new Error(
`Expected a number or face followed by a suit, but got "invalid"`
);
}

if (!validRank) {
throw new Error(`Valid rank: 2-10, A, J, Q, K only.`);
}

if (rank === "A") {
return 11;
} else if (["J", "Q", "K"].includes(rank)) {
return 10;
} else {
return Number(rank);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,36 @@ 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 (angle < 180 && angle > 90)`, () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(120)).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 (angle > 180 && angle < 360)`, () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(190)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});

// Case 6: Invalid angles
test(`should return "Invalid value" when (angel >= 360 || angle <= 0 || angel = "")`, () => {
expect(getAngleType(-10)).toEqual("invalid angle");
expect(getAngleType(365)).toEqual("invalid angle");
expect(getAngleType(360)).toEqual("invalid angle");
expect(getAngleType(0)).toEqual("invalid angle");
expect(getAngleType()).toEqual("invalid angle");
expect(getAngleType(null)).toEqual("invalid angle");
expect(getAngleType("angle")).toEqual("invalid angle");
});
Comment on lines 38 to +47

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two cases included here are general cases for invalid angles. There are two boundary cases as well. Can you think of them? If so, please add them as well. Thank you.

Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js";
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

test(`should return true when denominator is more than numerator`, () => {
expect(isProperFraction(1, 4)).toEqual(true);
});

test(`should return false when denominator is less than numerator`, () => {
expect(isProperFraction(4, 1)).toEqual(false);
});

test(`should return false when denominator and numerator are negative`, () => {
expect(isProperFraction(-5, -2)).toEqual(false);
});

test(`should return false when denominator and numerator are equal`, () => {
expect(isProperFraction(1, 1)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,46 @@ test(`Should return 11 when given an ace card`, () => {

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
test(`Should return 7 when given an seven card`, () => {
expect(getCardValue("7♥")).toEqual(7);
});
// Face Cards (J, Q, K)
test(`Should return 10 when given J/Q/K`, () => {
expect(getCardValue("J♦")).toEqual(10);
expect(getCardValue("Q♣")).toEqual(10);
expect(getCardValue("K♠")).toEqual(10);
});
// Invalid Cards
test(`Expected a number followed by a suit, but got invalid`, () => {
expect(() => getCardValue("10")).toThrow(
`Expected a number or face followed by a suit, but got "invalid"`
);
});

test(`Expected a number followed by a suit, but got invalid`, () => {
expect(() => getCardValue("")).toThrow(
`Expected a number or face followed by a suit, but got "invalid"`
);
});

test(`Expected a number followed by a suit, but got invalid`, () => {
expect(() => getCardValue("♥")).toThrow(
`Expected a number or face followed by a suit, but got "invalid"`
);
});

test(`Expected a number followed by a suit, but got invalid`, () => {
expect(() => getCardValue("♥10")).toThrow(
`Expected a number or face followed by a suit, but got "invalid"`
);
});

test(`Valid rank: 2-10, A, J, Q, K only`, () => {
expect(() => getCardValue("12♥")).toThrow(
`Valid rank: 2-10, A, J, Q, K only`
);
});
Comment on lines 21 to +50

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as my another comment https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/pull/1678/changes#r4282076991 , please add more invalid card cases. Thank you.


// To learn how to test whether a function throws an error as expected in Jest,
// please refer to the Jest documentation:
// https://jestjs.io/docs/expect#tothrowerror

Loading
Loading