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,38 @@ test("Classifies right angles", () => {
const right = getAngleType(90);
assert.equal(right, "Right angle");
});

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

test("Classifies obtuse angles", () => {
const obtuse = getAngleType(179);
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(359);
assert.equal(reflex, "Reflex angle");
});

test("Classifies negative angles as invalid angles", () => {
const invalid = getAngleType(-180);
assert.equal(invalid, "Invalid angle");
});

test("Classifies invalid angles", () => {
const invalid = getAngleType(361);
assert.equal(invalid, "Invalid angle");
});

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

test("Basic proper fraction", () => {
assert.equal(isProperFraction(1, 2), true);
})

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

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

test("Basic proper fraction", () => {
assert.equal(isProperFraction(0, 0), false);
})

test("Basic proper fraction", () => {
assert.equal(isProperFraction(-1, 1), true);
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,48 @@ test("Valid single-digit card", () => {
assert.equal(getCardValue("9♠"), 9);
});

test("Valid single-digit card", () => {
assert.equal(getCardValue("A♠"), 11);
});

test("Valid single-digit card", () => {
assert.equal(getCardValue("7♦"), 7);
});

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

test("Valid numeric vale", () => {
assert.equal(getCardValue("K♣"), 10);
});

test("Valid numeric vale", () => {
assert.equal(getCardValue("Q♦"), 10);
});

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"),
/The card you entered is invalid\. Please enter a valid card\./,
"Expected a clear error for an invalid card"
);
});

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

test("Invalid string", () => {
assert.throws(() => getCardValue("11♠"), /The card you entered is invalid/);
});

test("Invalid string", () => {
assert.throws(() => getCardValue("1♥"), /The card you entered is invalid/);
});

test("Invalid string", () => {
assert.throws(() => getCardValue("JX"), /The card you entered is invalid/);
});

test("Invalid string", () => {
assert.throws(() => getCardValue("♠A"), /The card you entered is invalid/);
});
22 changes: 21 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,25 @@
// execute the code to ensure all tests pass.

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

if (angle === 90) {
return "Right 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 numerator < denominator;
}
43 changes: 42 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,47 @@
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

//const cardRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
// const emoji = ["♠", "♥", "♦", "♣"];

const cardRanks = [
"A",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
];
const suits = ["♠", "♥", "♦", "♣"];

export function getCardValue(card) {
// TODO: Implement this function
if (typeof card !== "string" || card.length < 2) {
throw new Error(
"The card you entered is invalid. Please enter a valid card."
);
}

const rank = card.slice(0, -1);
const suit = card.slice(-1);

if (!cardRanks.includes(rank) || !suits.includes(suit)) {
throw new Error(
"The card you entered is invalid. Please enter a valid card."
);
}

if (rank === "A") {
return 11;
} else if (["J", "Q", "K"].includes(rank)) {
return 10;
} else {
return Number(rank);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,39 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// Case 2: Right angle
test(`should return "Right angle" when (angle === 90)`, () => {
// Test various right angles, including boundary cases
expect(getAngleType(90)).toEqual("Right angle");
});

// Case 3: Obtuse angles
test(`should return "Obtuse angle" when (angle > 90 && angle < 180)`, () => {
// Test various obtuse angles, including boundary cases
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
expect(getAngleType(169)).toEqual("Obtuse angle");
expect(getAngleType(101)).toEqual("Obtuse angle");
});

// Case 4: Straight angle
test(`should return "Straight angle" when (angle === 180)`, () => {
// Test various straight angles, including boundary cases
expect(getAngleType(180)).toEqual("Straight angle");
});

// Case 5: Reflex angles
test(`should return "Reflex angle" when (angle > 180 && angle < 360)`, () => {
// Test various reflex angles, including boundary cases
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
expect(getAngleType(305)).toEqual("Reflex angle");
expect(getAngleType(200)).toEqual("Reflex angle");
});

// Case 6: Invalid angles
test(`should return "Invalid angle" when (angle === Invalid)`, () => {
// Test various invalid angles, including boundary cases
expect(getAngleType(361)).toEqual("Invalid angle");
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(-181)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,27 @@ 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
// Special case: denominator is zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

// Special case: numerator is One
test(`should return true when denominator is two`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

// Special case: numerator is two
test(`should return false when denominator is 2`, () => {
expect(isProperFraction(2, 2)).toEqual(false);
});

// Special case: numerator is negative number
test(`should return true when denominator is 1`, () => {
expect(isProperFraction(-1, 1)).toEqual(false);
});

// Special case: numerator is zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(0, 0)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,27 @@ test(`Should return 11 when given an ace card`, () => {
// Face Cards (J, Q, K)
// Invalid Cards

// Case 2: Number Cards (2-10)
test(`Should return the numerical value when given a number card`, () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("5♥")).toEqual(5);
expect(getCardValue("10♦")).toEqual(10);
});

// Case 3: Face Cards (J, Q, K)
test(`Should return 10 when given a face card`, () => {
expect(getCardValue("J♣")).toEqual(10);
expect(getCardValue("Q♦")).toEqual(10);
expect(getCardValue("K♠")).toEqual(10);
});

// Case 4: Invalid Cards (["11♠", "JX", "♠A"])
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("11♠")).toThrow();
expect(() => getCardValue("JX")).toThrow();
expect(() => getCardValue("♠A")).toThrow();
});

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