Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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,58 @@ test("Classifies right angles", () => {
const right = getAngleType(90);
assert.equal(right, "Right angle");
});

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

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

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

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

test("Handles invalid angles (negative)", () => {
const invalidNegative = getAngleType(-30);
assert.equal(invalidNegative, "Invalid angle");
});

test("classifies acute angle boundary ", () => {
const acuteBoundary = getAngleType(1);
assert.equal(acuteBoundary, "Acute angle");
});

test("classifies obtuse angle boundary ", () => {
const obtuseBoundary = getAngleType(180);
assert.equal(obtuseBoundary, "Straight angle");
});

test("classifies reflex angle boundary ", () => {
const reflexBoundary = getAngleType(270);
assert.equal(reflexBoundary, "Reflex angle");
});

test("classifies right angle boundary ", () => {
const rightBoundary = getAngleType(90);
assert.equal(rightBoundary, "Right angle");
});

test("classifies straight angle boundary ", () => {
const straightBoundary = getAngleType(180);
assert.equal(straightBoundary, "Straight angle");
});

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

test("Numerator is zero", () => {
// Example: 0/5 is a proper fraction
assert.equal(isProperFraction(0, 5), true);
});

test("Numerator is equal to denominator", () => {
// Example: 3/3 is not a proper fraction
assert.equal(isProperFraction(3, 3), false);
});

test("Numerator is greater than denominator", () => {
// Example: 5/3 is not a proper fraction
assert.equal(isProperFraction(5, 3), false);
});

test("Negative numerator and positive denominator", () => {
// Example: -1/2 is a proper fraction
assert.equal(isProperFraction(-1, 2), true);
});

test("Positive numerator and negative denominator", () => {
// Example: 1/-2 is a proper fraction
assert.equal(isProperFraction(1, -2), true);
});

test("Negative numerator and negative denominator", () => {
// Example: -1/-2 is a proper fraction
assert.equal(isProperFraction(-1, -2), true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,57 @@ test("Arbitrary non-card string", () => {
assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error");
});

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

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

test("Valid ten card", () => {
assert.equal(getCardValue("10♥"), 10);
});

test("Invalid card with missing suit", () => {
assert.throws(() => getCardValue("5"), "Expected clear error");
});

test("Invalid card with missing rank", () => {
assert.throws(() => getCardValue("♠"), "Expected clear error");
});

test("Invalid card with extra characters", () => {
assert.throws(() => getCardValue("10♠extra"), "Expected clear error");
});

test("Invalid card with invalid rank", () => {
assert.throws(() => getCardValue("11♠"), "Expected clear error");
});

test("Invalid card with invalid suit", () => {
assert.throws(() => getCardValue("10X"), "Expected clear error");
});

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

test("Invalid card with missing suit", () => {
assert.throws(() => getCardValue("5"), "Expected clear error");
});

test("Invalid card with missing rank", () => {
assert.throws(() => getCardValue("♠"), "Expected clear error");
});

test("Invalid card with extra characters", () => {
assert.throws(() => getCardValue("10♠extra"), "Expected clear error");
});

test("Invalid card with invalid rank", () => {
assert.throws(() => getCardValue("11♠"), "Expected clear error");
});

test("Invalid card with invalid suit", () => {
assert.throws(() => getCardValue("10X"), "Expected clear error");
});

27 changes: 25 additions & 2 deletions implement-and-rewrite-tests/implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Implement a function getAngleType

//
// Don't forget to write tests in implement-tests-with-node-test.
//
Expand All @@ -16,6 +17,28 @@
// 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 === 90) {
return "Right angle";
}
else if (angle > 0 && angle < 90) {
return "Acute 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";
}
}


export { getAngleType };
13 changes: 11 additions & 2 deletions implement-and-rewrite-tests/implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

export function isProperFraction(numerator, denominator) {

// TODO: Implement this function
}


function isProperFraction(numerator, denominator) {
return Math.abs(numerator) < Math.abs(denominator);

}

export { isProperFraction };


26 changes: 25 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,30 @@
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

export function getCardValue(card) {

// TODO: Implement this function
function getCardValue(card) {
const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
const validSuits = ["♠", "♥", "♦", "♣"];

// Check if the card string is valid
const rank = card.slice(0, -1);
const suit = card.slice(-1);

if (!validRanks.includes(rank) || !validSuits.includes(suit)) {
throw new Error(`Expected a number followed by a suit, but got "${card}"`);
}

// Determine the value of the card
if (rank === "A") {
return 11;
} else if (["J", "Q", "K"].includes(rank)) {
return 10;
} else {
return parseInt(rank, 10);
}


}

export { getCardValue };
Loading