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
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
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,19 @@ 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("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(numerator < 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";
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,18 @@ 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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,113 @@ test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});

describe("Returns numeric value when given cards ranked (2-10)", () => {
test("Returns 2 when given a card with rank 2", () => {
expect(getCardValue("2♥")).toEqual(2);
});

test("Returns 3 when given a card with rank 3", () => {
expect(getCardValue("3♣")).toEqual(3);
});

test("Returns 4 when given a card with rank 4", () => {
expect(getCardValue("4♦")).toEqual(4);
});

test("Returns 5 when given a card with rank 5", () => {
expect(getCardValue("5♣")).toEqual(5);
});

test("Returns 6 when given a card with rank 6", () => {
expect(getCardValue("6♦")).toEqual(6);
});

test("Returns 7 when given a card with rank 7", () => {
expect(getCardValue("7♠")).toEqual(7);
});

test("Returns 8 when given a card with rank eight", () => {
expect(getCardValue("8♥")).toEqual(8);
});

test("Returns 9 when given a nine card", () => {
expect(getCardValue("9♠")).toEqual(9);
});

test("Returns 10 when given a ten card", () => {
expect(getCardValue("10♣")).toEqual(10);
});
});

describe("Returns 10 when given (Q,J or K) cards", () => {
test("Returns 10 when given a Q card", () => {
expect(getCardValue("Q♥")).toEqual(10);
});

test("Returns 10 when given a J card", () => {
expect(getCardValue("J♣")).toEqual(10);
});

test("Returns 10 when given a K card", () => {
expect(getCardValue("K♠")).toEqual(10);
});
});

describe("Invalid Cards", () => {
test("Throws an error when given an empty string", () => {
expect(() => getCardValue("")).toThrow(
/Expected a valid number followed by a suit, but got ""/
);
});
test("Arbitrary non-card string", () => {
expect(() => getCardValue("invalid")).toThrow(
/Expected a valid number followed by a suit, but got "invalid"/
);
});

test("Invalid card rank with no suit", () => {
expect(() => getCardValue("15")).toThrow(
/Expected a valid number followed by a suit, but got "15"/
);
});

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

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

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

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

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

test("Invalid rank 0 but valid suit", () => {
expect(() => getCardValue("0♥")).toThrow(
/Expected a valid number followed by a suit, but got "0♥"/
);
});
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
Expand All @@ -15,4 +122,3 @@ test(`Should return 11 when given an ace card`, () => {
// 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