Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
4765894
Passes classify right angle test
habohlin Oct 12, 2026
f6f742f
Add test for invalid 0 degree angle and update function to pass
habohlin Oct 12, 2026
048e29d
Add test for acute 1 degree angle and update function to pass
habohlin Oct 12, 2026
36145c0
Add test for acute 89 degree angle, function already passes
habohlin Oct 12, 2026
d41cebe
Add test for obtuse 91 degree angle and update function to pass
habohlin Oct 12, 2026
52463f4
Add test for obtuse 179 degree angle, function already passes
habohlin Oct 12, 2026
3ff0de2
Add test for straight 180 degree angle and update function to pass
habohlin Oct 12, 2026
0252cf1
Add test for reflex 181 degree angle and update function to pass
habohlin Oct 12, 2026
aab5bd4
Add test for reflex 359 degree angle, function already passes
habohlin Oct 12, 2026
ad2c349
Add test for invalid 360 degree angle, function already passes
habohlin Oct 12, 2026
d4feec5
Implemented my function is proper fraction
habohlin Oct 12, 2026
79cdd8a
Failed basic proper fraction and fixed the function so it now passes
habohlin Oct 12, 2026
3a8d29e
Add test for improper fraction, it passes
habohlin Oct 12, 2026
6086f76
Add test for edge case improper fraction, it passes
habohlin Oct 12, 2026
4f3db68
Add test for negative proper fraction, it passes
habohlin Oct 12, 2026
5052e1c
Add test for negative improper fraction, it passes
habohlin Oct 12, 2026
e59a4ac
Wrote first draft of function, passes valid card test, not non-card s…
habohlin Oct 13, 2026
6656eb2
Changed error message so function passes second test
habohlin Oct 13, 2026
8efb17d
Add test for 19♠, throws error, test passes
habohlin Oct 13, 2026
96fb078
Add test for 'P♦', test passes
habohlin Oct 13, 2026
e9444cd
Add test for invalid 's♦', test passes
habohlin Oct 14, 2026
de0efff
Add test for invalid 'soUp♦', test passes
habohlin Oct 14, 2026
16db07c
Add test for invalid '-3♦', test passes
habohlin Oct 14, 2026
2f33741
Add test for invalid '5', test passes
habohlin Oct 14, 2026
ea29e28
Add test for invalid 'Q', test passes
habohlin Oct 14, 2026
0a1c1b4
Add test for valid 'A♣', test passes
habohlin Oct 14, 2026
f0f349f
Add test for valid '10♣', test passes
habohlin Oct 14, 2026
ba1b297
Add test for valid 'K♠', test passes
habohlin Oct 14, 2026
a451ef8
Change to suitable variable names in tests
habohlin Oct 14, 2026
57095e0
Add jest test for right angle, it passes
habohlin Oct 14, 2026
0c0519e
Add jest tests for obtuse angles, they pass
habohlin Oct 14, 2026
07f9f45
Add jest test for straight angle, it passes
habohlin Oct 14, 2026
42061e2
Add jest tests for Reflex angles, they pass
habohlin Oct 14, 2026
42ae1fa
Add jes tests for invalid angles, they pass
habohlin Oct 14, 2026
aa56732
Add jest test for passed 1 and 2 return true, test passes
habohlin Oct 14, 2026
bc669ac
Add jest test for passed 4 and 2 returns false, test passes
habohlin Oct 14, 2026
543fbec
Add jest test for passed 2 and 2 returns false, test passes
habohlin Oct 14, 2026
add0f70
Add jest test for passes -5 and 8 returns true, test passes
habohlin Oct 14, 2026
17305f8
Add jest test for passes -8 and 5 returns false, test passes
habohlin Oct 14, 2026
666eb6c
Add jest test for passes 0 and 5 returns true, test passes
habohlin Oct 14, 2026
6c1c939
Add jest test for passes 3 and -7 returns true, test passes
habohlin Oct 14, 2026
a00da07
Add jest test for valid card '10♣', it passes
habohlin Oct 14, 2026
a3974ae
Add jest test for valid card 'K♠', test passes
habohlin Oct 14, 2026
247bf0d
Add jest test for valid card 'A♣', test passes
habohlin Oct 14, 2026
51a2b38
Add jest test for invalid card 'invalid', throws error, test passes
habohlin Oct 14, 2026
856b861
Add jest test for invalid card '19♠', throws error, test passes
habohlin Oct 14, 2026
d89b7c3
Add jest test for invalid card 'P♦', throws error, test passes
habohlin Oct 14, 2026
bd931e3
Add jest test for invalid card 's♦', throws error, test passes
habohlin Oct 14, 2026
9fc54cf
Add jest test for invalid card 'sOup♦', throws error, test passes
habohlin Oct 14, 2026
1f7930b
Add jest test fir invalid card '-3♦', throws error, test passes
habohlin Oct 14, 2026
ead0e96
Add jest test for invalid card '5', throws error, test passes
habohlin Oct 14, 2026
fafb4c4
Add jest test for invalid card 'Q', throws error, test passes
habohlin Oct 14, 2026
9737d08
Format all files with prettier
habohlin Oct 14, 2026
abe2eb3
Rewrite test messages to describe behaviours instead of exact values
habohlin Oct 21, 2026
9543df3
Refactor to shorter return statement for boolean return value
habohlin Oct 21, 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 @@ -6,7 +6,40 @@ 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 acute angles", () => {
const acute1 = getAngleType(1);
assert.equal(acute1, "Acute angle");
const acute89 = getAngleType(89);
assert.equal(acute89, "Acute angle");
});

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

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

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

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

test("Classifies invalid angles", () => {
const invalid360 = getAngleType(360);
assert.equal(invalid360, "Invalid angle");
const invalid0 = getAngleType(0);
assert.equal(invalid0, "Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,19 @@ test("Basic proper fraction", () => {
// Example: 1/2 is a proper fraction
assert.equal(isProperFraction(1, 2), true);
});

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

test("Edge case improper fraction", () => {
assert.equal(isProperFraction(2, 2), false);
});

test("Negative proper fraction", () => {
assert.equal(isProperFraction(-5, 8), true);
});

test("Negative improper fraction", () => {
assert.equal(isProperFraction(-8, 5), false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,74 @@ test("Valid single-digit card", () => {
});

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("invalid"),
/Expected a number followed by a suit, but got "invalid"/,
"Expected clear error"
);
});

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

test("Card with number rank outside range 2-10", () => {
assert.throws(
() => getCardValue("19♠"),
/Expected a number followed by a suit, but got "19♠"/,
"Expected clear error"
);
assert.throws(
() => getCardValue("-3♦"),
/Expected a number followed by a suit, but got "-3♦"/,
"Expected clear error"
);
});

test("Card with letter rank other than the correct options", () => {
assert.throws(
() => getCardValue("P♦"),
/Expected a number followed by a suit, but got "P♦"/,
"Expected clear error"
);
assert.throws(
() => getCardValue("s♦"),
/Expected a number followed by a suit, but got "s♦"/,
"Expected clear error"
);
assert.throws(
() => getCardValue("soUp♣"),
/Expected a number followed by a suit, but got "soUp♣"/,
"Expected clear error"
);
});

test("Card with valid number rank lacking suit", () => {
assert.throws(
() => getCardValue("5"),
/Expected a number followed by a suit, but got "5"/,
"Expected clear error"
);
});

test("Card with valid letter rank lacking suit", () => {
assert.throws(
() => getCardValue("Q"),
/Expected a number followed by a suit, but got "Q"/,
"Expected clear error"
);
});

test("Card with valid suit lacking rank", () => {
assert.throws(
() => getCardValue("♠"),
/Expected a number followed by a suit, but got "♠"/,
"Expected clear error"
);
});

//Valid cases

test("Valid cards", () => {
assert.equal(getCardValue("A♣"), 11);
assert.equal(getCardValue("10♣"), 10);
assert.equal(getCardValue("K♠"), 10);
});
14 changes: 13 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,17 @@
// execute the code to ensure all tests pass.

export 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";
}
}
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
const fraction = Math.abs(numerator / denominator);

return fraction >= 0 && fraction < 1;
}
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 @@ -24,5 +24,32 @@
// execute the code to ensure all tests pass.

export function getCardValue(card) {
// TODO: Implement this function
const suitString = "♠♥♦♣";
const rankString = "JQK";

if (card) {
const suit = card[card.length - 1];
if (suitString.includes(suit)) {
const rank = card.slice(0, -1);
if (rank === "10") {
return 10;
} else if (rank.length === 1) {
if (rank === "A") {
return 11;
}

if (rankString.includes(rank)) {
return 10;
}

const rankNum = Number(rank);

if (rankNum >= 2) {
return rankNum;
}
}
}
}

throw new Error(`/Expected a number followed by a suit, but got "${card}"/`);
Comment on lines +27 to +54

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.

I like the structure of this - having the error being thrown at the bottom of the function is quite clean, as it only requires a single exception throwing statement.

Can you think of any drawbacks to this approach? Or how you might structure the function differently in terms of input validation?

(note: this is not a change request, just a question to prompt some thinking!)

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,47 @@ import { getAngleType } from "../implement/1-get-angle-type.js";
// including boundary and invalid cases.

// Case 1: Acute angles
test(`should return "Acute angle" when (0 < angle < 90)`, () => {

test(`Classifies acute angles`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});

// Case 2: Right angle

test(`Classifies right angles`, () => {
expect(getAngleType(90)).toEqual("Right angle");
});

// Case 3: Obtuse angles

test(`Classifies obtuse angles`, () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(135)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});

// Case 4: Straight angle

test(`Classifies straight angles`, () => {
expect(getAngleType(180)).toEqual("Straight angle");
});

// Case 5: Reflex angles

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

// Case 6: Invalid angles

test(`Classifies invalid angles`, () => {
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(361)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ 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(`Edge case: division by zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

test(`Basic proper fraction`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

test(`Basic improper fraction`, () => {
expect(isProperFraction(4, 2)).toEqual(false);
});

test(`Edge case improper fraction`, () => {
expect(isProperFraction(2, 2)).toEqual(false);
});

test(`Negative proper fraction`, () => {
expect(isProperFraction(-5, 8)).toEqual(true);
});

test(`Negative improper fraction`, () => {
expect(isProperFraction(-8, 5)).toEqual(false);
});

test(`Edge case proper fraction`, () => {
expect(isProperFraction(0, 5)).toEqual(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,65 @@ test(`Should return 11 when given an ace card`, () => {

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)

test(`Cards with valid number rank`, () => {
expect(getCardValue("10♣")).toEqual(10);
});

// Face Cards (J, Q, K)

test(`Cards with valid letter rank`, () => {
expect(getCardValue("K♠")).toEqual(10);
expect(getCardValue("A♣")).toEqual(11);
});

// Invalid Cards

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

test(`Card with number rank outside range 2-10`, () => {
expect(() => {
getCardValue("19♠");
}).toThrow(/Expected a number followed by a suit, but got "19♠"/);
expect(() => {
getCardValue("-3♦");
}).toThrow(/Expected a number followed by a suit, but got "-3♦"/);
});

test(`Card with letter rank other than the correct options`, () => {
expect(() => {
getCardValue("P♦");
}).toThrow(/Expected a number followed by a suit, but got "P♦"/);
expect(() => {
getCardValue("s♦");
}).toThrow(/Expected a number followed by a suit, but got "s♦"/);
expect(() => {
getCardValue("sOup♦");
}).toThrow(/Expected a number followed by a suit, but got "sOup♦"/);
});

test(`Card with valid number rank lacking suit`, () => {
expect(() => {
getCardValue("5");
}).toThrow(/Expected a number followed by a suit, but got "5"/);
});

test(`Card with valid letter rank lacking suit`, () => {
expect(() => {
getCardValue("Q");
}).toThrow(/Expected a number followed by a suit, but got "Q"/);
});

test(`Card with valid suit lacking rank`, () => {
expect(() => {
getCardValue("♠");
}).toThrow(/Expected a number followed by a suit, but got "♠"/);
});

// 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