Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3c34300
implemented getAngleType function
marscancode Oct 13, 2026
a3e94a4
implemented right angle classification
marscancode Oct 13, 2026
e24692a
added Obtuse angle test
marscancode Oct 13, 2026
9aafc79
added straight angle test it fails
marscancode Oct 13, 2026
db06ff6
implemented classification for straight angle test now passes
marscancode Oct 13, 2026
2e539b5
added reflex angle test and it fails
marscancode Oct 13, 2026
874aa37
implemented classification for reflex angle test now passes
marscancode Oct 13, 2026
190c45b
added test for invalid angles it fails
marscancode Oct 13, 2026
5bf0d70
added test for acute angle
marscancode Oct 13, 2026
9faf227
refactored acute angle implementation
marscancode Oct 13, 2026
b7ac8b6
added additional acute angle tests
marscancode Oct 13, 2026
f5f0c00
refactored aditional acute angle tests
marscancode Oct 13, 2026
780ce9a
added additional tests for obtuse angles
marscancode Oct 13, 2026
d242353
added additional tests for reflex angles
marscancode Oct 13, 2026
ff0d518
added additonal tests for invalid angles
marscancode Oct 13, 2026
f049f47
added final test for invalid angle 360
marscancode Oct 13, 2026
036f167
added final acute angle test for 1
marscancode Oct 13, 2026
8631a7e
added jest tests
marscancode Oct 13, 2026
7797f0c
added tests in node for isProperFraction function
marscancode Oct 14, 2026
5651ef6
Implemented isProperFraction function
marscancode Oct 14, 2026
d47c1c7
added tests in jest for the isProperFraction function
marscancode Oct 14, 2026
57a3aba
Implemented getCardValue function
marscancode Oct 15, 2026
7d65d6f
added node tests for getCardValue function
marscancode Oct 15, 2026
f989cbd
added jest test for getCardValue function
marscancode Oct 15, 2026
8d09a15
added negative number tests for isProperFraction
marscancode Oct 25, 2026
728add3
refactored isProperFraction function to handle negative numbers, tes…
marscancode Oct 25, 2026
122cf3c
added negative tests in jest for the isProperFraction, tests pass
marscancode Oct 25, 2026
d7789c6
fixed syntax on toThrow error messages
marscancode Oct 25, 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,56 @@ test("Classifies right angles", () => {
const right = getAngleType(90);
assert.equal(right, "Right angle");
});

test("Classifies acute angle", () => {
const one = getAngleType(1);
assert.equal(one, "Acute angle");

const thirty = getAngleType(30);
assert.equal(thirty, "Acute angle");

const eightyNine = getAngleType(89);
assert.equal(eightyNine, "Acute angle");

const fortyFive = getAngleType(45);
assert.equal(fortyFive, "Acute angle");
});

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

const oneHundredAndSeventyNine = getAngleType(179);
assert.equal(oneHundredAndSeventyNine, "Obtuse angle");

const oneHundredAndTen = getAngleType(110);
assert.equal(oneHundredAndTen, "Obtuse angle");
});

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

test("Classifies reflex angles", () => {
const reflexAngle = getAngleType(181);
assert.equal(reflexAngle, "Reflex angle");
const threeHundredAndFiftyNine = getAngleType(359);
assert.equal(threeHundredAndFiftyNine, "Reflex angle");
const twoHundredAndFifty = getAngleType(250);
assert.equal(twoHundredAndFifty, "Reflex angle");
});

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

const zero = getAngleType(0);
assert.equal(zero, "Invalid angle");

const fiveHundred = getAngleType(500);
assert.equal(fiveHundred, "Invalid angle");

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

test("Proper fraction numerator is 0", () => {
assert.equal(isProperFraction(0, 1), true);
});

test("Proper fraction with a negative numerator but positive denominator", () => {
assert.equal(isProperFraction(-2, 3), true);
});
test("Proper fraction with a positive numerator but negative denominator", () => {
assert.equal(isProperFraction(2, -3), true);
});

test("Proper fraction with both a negative numerator and denominator", () => {
assert.equal(isProperFraction(-2, -3), true);
});

test("Improper fraction denominator is 0", () => {
assert.equal(isProperFraction(1, 0), false);
});

test("Improper fraction numerator is larger than denominator", () => {
assert.equal(isProperFraction(6, 4), false);
});

test("Improper fraction numerator and denominator are the same value", () => {
assert.equal(isProperFraction(3, 3), 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 valid number followed by a suit, but got "invalid"/,
"Expected clear error"
);
});

// TODO: What other invalid card cases can you think of?
test("Invalid card rank with no suit", () => {
assert.throws(
() => getCardValue("15"),
/Expected a valid number followed by a suit, but got "15"/,
"Expected clear error"
);
});

test("An empty string", () => {
assert.throws(
() => getCardValue(""),
/Expected a valid number followed by a suit, but got ""/,
"Expected clear error"
);
});

test("A valid card rank but invalid suit", () => {
assert.throws(
() => getCardValue("8Z"),
/Expected a valid number followed by a suit, but got "8Z"/,
"Expected clear error"
);
});

test("A valid suit but invalid card rank", () => {
assert.throws(
() => getCardValue("26♣"),
/Expected a valid number followed by a suit, but got "26♣"/,
"Expected clear error"
);
});

test("Rank and suit with an extra letter", () => {
assert.throws(
() => getCardValue("5♣l"),
/Expected a valid number followed by a suit, but got "5♣l"/,
"Expected clear error"
);
});

test("Two suits", () => {
assert.throws(
() => getCardValue("♣♠"),
/Expected a valid number followed by a suit, but got "♣♠"/,
"Expected clear error"
);
});

test("A negative rank but valid suit", () => {
assert.throws(
() => getCardValue("-4♣"),
/Expected a valid number followed by a suit, but got "-4♣"/,
"Expected clear error"
);
});

test("Invalid rank 0 but valid suit", () => {
assert.throws(
() => getCardValue("0♥"),
/Expected a valid number followed by a suit, but got "0♥"/,
"Expected clear error"
);
});
12 changes: 11 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,15 @@
// 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,9 @@
// execute the code to ensure all tests pass.

export function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
} else {
return false;
}
}
30 changes: 29 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,33 @@
// execute the code to ensure all tests pass.

export function getCardValue(card) {
// TODO: Implement this function
const cardValue = card.slice(0, -1); // eg "10"
const cardSuit = card.slice(-1); // eg "♠"
const validValue = [
"A",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
];
const validSuit = ["♠", "♥", "♦", "♣"];
if (!validValue.includes(cardValue) || !validSuit.includes(cardSuit)) {
throw new Error(
`Expected a valid number followed by a suit, but got "${card}"`
);
} else if (cardValue === "A") {
return 11;
} else if (cardValue === "J" || cardValue === "Q" || cardValue === "K") {
return 10;
} else if (cardValue >= 2 && cardValue <= 10) {
return Number(cardValue);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { get } from "node:http";

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.

Why import get? Where is it used?

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

// TODO: Write tests in Jest syntax to cover all cases/outcomes,
Expand All @@ -12,7 +13,30 @@ 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 > 90 && angle < 180)`, () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
expect(getAngleType(110)).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 && < 360)`, () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
expect(getAngleType(250)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test(`should return "Invalid angle" for invalid angles`, () => {
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(500)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,30 @@ 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 false when numerator is larger than denominator`, () => {
expect(isProperFraction(6, 4)).toEqual(false);
});

test(`should return false when numerator and denominator are the same value`, () => {
expect(isProperFraction(3, 3)).toEqual(false);
});
test(`should return true when is a proper fraction`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

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

test(`proper fraction with a negative numerator but positive denominator`, () => {
expect(isProperFraction(-2, 3)).toEqual(true);
});

test(`proper fraction with a positive numerator but negative denominator`, () => {
expect(isProperFraction(2, -3)).toEqual(true);
});

test(`proper fraction with both a negative numerator and denominator`, () => {
expect(isProperFraction(-2, -3)).toEqual(true);
});
Comment on lines +25 to +35

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.

Note: Rather than writing a separate test for each sign combination, you could consider grouping inputs that exercise the same behaviour into one test, under a test description that is applicable to all. For example,

test("should return true when abs(numerator) < abs(denominator)", () => {
  expect(isProperFraction(1, 2)).toEqual(true);
  expect(isProperFraction(-1, 2)).toEqual(true);
  expect(isProperFraction(1, -2)).toEqual(true);
  expect(isProperFraction(-1, -2)).toEqual(true);
});

Note: Use of widely recognised pseudo-code and math notations like abs(...) or | ... | in the descriptions is an usually accepted.

No change required

Loading
Loading