Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e275bbf
add more tests
fatimarouchi Oct 15, 2026
18c03c0
implement functions
fatimarouchi Oct 15, 2026
a19670a
fix error
fatimarouchi Oct 15, 2026
f5bf95b
implement function
fatimarouchi Oct 15, 2026
6c865ba
run tests
fatimarouchi Oct 15, 2026
37f4f78
Revert latest test run
fatimarouchi Oct 15, 2026
12f4893
add test
fatimarouchi Oct 16, 2026
f47f802
add more test
fatimarouchi Oct 16, 2026
d58fb5e
Add Jest tests for angle types
fatimarouchi Oct 17, 2026
c9cc257
Add proper fraction tests
fatimarouchi Oct 17, 2026
eaa3920
Add Jest tests for card values
fatimarouchi Oct 17, 2026
6e7d6e6
Add boundary cases to angle type tests
fatimarouchi Oct 26, 2026
f4eca9e
Restrict card values to valid ranks
fatimarouchi Oct 26, 2026
d034af5
Test all valid card ranks and reject invalid formats
fatimarouchi Oct 26, 2026
7e69ad3
Cover all card ranks and invalid formats in Jest tests
fatimarouchi Oct 26, 2026
2c547d9
Correct proper fraction expectation for negative values
fatimarouchi Oct 26, 2026
dd4d5dc
test: reject invalid card ranks
fatimarouchi Oct 27, 2026
6f64b83
test: cover angle boundaries
fatimarouchi Oct 27, 2026
1c0da29
Add negative angle coverage
fatimarouchi Oct 27, 2026
cb8fa8a
Group card value cases
fatimarouchi Oct 27, 2026
5a89c66
Cover angle classification boundaries
fatimarouchi Nov 2, 2026
acbe93e
Fix proper fraction logic and tests
fatimarouchi Nov 3, 2026
2eae682
Cover proper fraction sign and boundary cases
fatimarouchi Nov 3, 2026
83a6341
Handle proper fraction edge cases
fatimarouchi Nov 3, 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 @@ -3,10 +3,37 @@ 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 angles", () => {
assert.equal(getAngleType(1), "Acute angle");
assert.equal(getAngleType(45), "Acute angle");
assert.equal(getAngleType(89), "Acute angle");
});

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

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

test("Classifies reflex angles", () => {
assert.equal(getAngleType(181), "Reflex angle");
assert.equal(getAngleType(270), "Reflex angle");
assert.equal(getAngleType(359), "Reflex angle");
});

test("Classifies angles outside the valid range as invalid", () => {
assert.equal(getAngleType(-10), "Invalid angle");
assert.equal(getAngleType(0), "Invalid angle");
assert.equal(getAngleType(360), "Invalid angle");
assert.equal(getAngleType(400), "Invalid angle");
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The tests in this script are comprehensive. Well done!

Note: The tests in the Jest test script could also be categorised in similar fashion.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,31 @@ 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
test("returns true when the numerator's magnitude is less than the denominator's", () => {
assert.equal(isProperFraction(1, 2), true);
assert.equal(isProperFraction(-1, 2), true);
assert.equal(isProperFraction(1, -2), true);
assert.equal(isProperFraction(-1, -2), true);
});

test("returns false when the numerator's magnitude equals or exceeds the denominator's", () => {
assert.equal(isProperFraction(2, 2), false);
assert.equal(isProperFraction(-2, 2), false);
assert.equal(isProperFraction(2, -2), false);
assert.equal(isProperFraction(-2, -2), false);
assert.equal(isProperFraction(3, 2), false);
assert.equal(isProperFraction(-3, 2), false);
assert.equal(isProperFraction(3, -2), false);
assert.equal(isProperFraction(-3, -2), false);
});

test("returns true when the numerator is zero and the denominator is nonzero", () => {
assert.equal(isProperFraction(0, 5), true);
assert.equal(isProperFraction(0, -5), true);
});

test("returns false when the denominator is zero", () => {
assert.equal(isProperFraction(1, 0), false);
assert.equal(isProperFraction(-1, 0), false);
assert.equal(isProperFraction(0, 0), false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,50 @@ 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("Returns the correct value for every valid rank and suit", () => {
const expectedValues = {
A: 11,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
9: 9,
10: 10,
J: 10,
Q: 10,
K: 10,
};
const suits = ["♠", "♥", "♦", "♣"];

test("Valid single-digit card", () => {
assert.equal(getCardValue("9♠"), 9);
for (const [rank, value] of Object.entries(expectedValues)) {
for (const suit of suits) {
assert.equal(getCardValue(`${rank}${suit}`), value);
}
}
});

test("Arbitrary non-card string", () => {
assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error");
});
test("Throws an error for invalid card formats", () => {
const invalidCards = [
"A",
"invalid",
"1♠",
"11♠",
"02♠",
"0x02♦",
"2.1♦",
"0002♦",
"2.5♠",
" 2♠",
"A?",
"",
];

// TODO: What other invalid card cases can you think of?
for (const card of invalidCards) {
assert.throws(() => getCardValue(card), {
message: `Expected a number followed by a suit, but got "${card}"`,
});
}
});
21 changes: 20 additions & 1 deletion implement-and-rewrite-tests/implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,24 @@
// execute the code to ensure all tests pass.

export function getAngleType(angle) {
// TODO: Implement this function
if (angle === 90) {
return "Right angle";
}
if (angle > 0 && angle < 90) {
return "Acute angle";
}

if (angle > 90 && angle < 180) {
return "Obtuse angle";
}

if (angle === 180) {
return "Straight angle";
}

if (angle > 180 && angle < 360) {
return "Reflex angle";
}

return "Invalid angle";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
// execute the code to ensure all tests pass.

export function isProperFraction(numerator, denominator) {
// TODO: Implement this function
return Math.abs(numerator) < Math.abs(denominator);
}
29 changes: 28 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 @@ -23,6 +23,33 @@
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

const cardValues = new Map([
["A", 11],
["2", 2],
["3", 3],
["4", 4],
["5", 5],
["6", 6],
["7", 7],
["8", 8],
["9", 9],
["10", 10],
["J", 10],
["Q", 10],
["K", 10],
]);

export function getCardValue(card) {
// TODO: Implement this function
const suit = card.slice(-1);
const rank = card.slice(0, -1);

if (!["♠", "♥", "♦", "♣"].includes(suit)) {
throw new Error(`Expected a number followed by a suit, but got "${card}"`);
}

if (cardValues.has(rank)) {
return cardValues.get(rank);
}

throw new Error(`Expected a number followed by a suit, but got "${card}"`);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,52 @@
import { getAngleType } from "../implement/1-get-angle-type.js";

// TODO: Write tests in Jest syntax to cover all cases/outcomes,
// including boundary and invalid cases.

// Case 1: Acute angles
test(`should return "Acute angle" when (0 < angle < 90)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(0.1)).toEqual("Acute angle");
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(0.5)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89.9)).toEqual("Acute angle");
expect(getAngleType(89.5)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});

// Case 2: Right angle
test('should return "Right angle" when angle is 90', () => {
expect(getAngleType(90)).toEqual("Right angle");
});
// Case 3: Obtuse angles
test('should return "Obtuse angle" when (90 < angle < 180)', () => {
expect(getAngleType(90.1)).toEqual("Obtuse angle");
expect(getAngleType(90.5)).toEqual("Obtuse angle");
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(120)).toEqual("Obtuse angle");
expect(getAngleType(179.9)).toEqual("Obtuse angle");
expect(getAngleType(179.5)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});
// Case 4: Straight angle
test('should return "Straight angle" when angle is 180', () => {
expect(getAngleType(180)).toEqual("Straight angle");
});
// Case 5: Reflex angles
test('should return "Reflex angle" when (180 < angle < 360)', () => {
expect(getAngleType(180.1)).toEqual("Reflex angle");
expect(getAngleType(180.5)).toEqual("Reflex angle");
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359.9)).toEqual("Reflex angle");
expect(getAngleType(359.5)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});
// Case 6: Invalid angles

test('should return "Invalid angle" for invalid angles', () => {
Comment thread
fatimarouchi marked this conversation as resolved.
Resolved
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(-0.5)).toEqual("Invalid angle");
expect(getAngleType(-10)).toEqual("Invalid angle");
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(400)).toEqual("Invalid angle");
});
Comment thread
fatimarouchi marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
import { isProperFraction } from "../implement/2-is-proper-fraction.js";

// 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`, () => {
test("should return false when the denominator is zero", () => {
expect(isProperFraction(1, 0)).toEqual(false);
expect(isProperFraction(0, 0)).toEqual(false);
});

test("should return true for a proper fraction", () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

test("should return false when the numerator and denominator have equal magnitudes", () => {
expect(isProperFraction(5, 5)).toEqual(false);
expect(isProperFraction(-5, 5)).toEqual(false);
expect(isProperFraction(5, -5)).toEqual(false);
expect(isProperFraction(-5, -5)).toEqual(false);
});

test("should return false when the numerator's magnitude exceeds the denominator's", () => {
expect(isProperFraction(7, 3)).toEqual(false);
expect(isProperFraction(-7, 3)).toEqual(false);
expect(isProperFraction(7, -3)).toEqual(false);
expect(isProperFraction(-7, -3)).toEqual(false);
});

test("should return true when numerator is zero", () => {
expect(isProperFraction(0, 5)).toEqual(true);
expect(isProperFraction(0, -5)).toEqual(true);
});

test("should return true when both numerator and denominator are negative and form a proper fraction", () => {
expect(isProperFraction(-1, -2)).toEqual(true);
});

test("should return true for negative numerator and positive denominator", () => {
expect(isProperFraction(-1, 2)).toEqual(true);
});

test("should return true for positive numerator and negative denominator when the numerator is smaller", () => {
expect(isProperFraction(1, -2)).toEqual(true);
});

test("should return false for negative numerator and positive denominator when the numerator is larger", () => {
expect(isProperFraction(-3, 2)).toEqual(false);
});

test("should return false for positive numerator and negative denominator when the numerator is larger", () => {
expect(isProperFraction(3, -2)).toEqual(false);
});
Comment thread
fatimarouchi marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
import { getCardValue } from "../implement/3-get-card-value.js";

// TODO: Write tests in Jest syntax to cover all possible outcomes.
test("Returns the value of number cards from 2 to 10", () => {
const suits = ["♠", "♥", "♦", "♣"];

// Case 1: Ace (A)
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
for (let rank = 2; rank <= 10; rank += 1) {
for (const suit of suits) {
expect(getCardValue(`${rank}${suit}`)).toEqual(rank);
}
}
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
// Invalid Cards
test("Returns 10 for face cards", () => {
const suits = ["♠", "♥", "♦", "♣"];

// 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
for (const rank of ["J", "Q", "K"]) {
for (const suit of suits) {
expect(getCardValue(`${rank}${suit}`)).toEqual(10);
}
}
});

test("Returns 11 for aces", () => {
for (const suit of ["♠", "♥", "♦", "♣"]) {
expect(getCardValue(`A${suit}`)).toEqual(11);
}
});

test("Throws an error for invalid card formats", () => {
const invalidCards = [
"A",
"invalid",
"1♠",
"11♠",
"02♠",
"0x02♦",
"2.1♦",
"0002♦",
"2.5♠",
" 2♠",
"A?",
"",
];

for (const card of invalidCards) {
expect(() => getCardValue(card)).toThrow(
`Expected a number followed by a suit, but got "${card}"`
);
}
});
Loading