Skip to content
Closed
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 @@ -16,8 +16,13 @@

function getAngleType(angle) {
// TODO: Implement this function
if (angle > 0 && angle < 90) return "Acute angle";
else if (angle === 90) return "Right angle";
else if (90 < angle && angle < 180) return "Obtuse angle";
else if (angle === 180) return "Straight angle";
else if (180 < angle && angle < 360) return "Reflex angle";
else return "Invalid angle";
}

// The line below allows us to load the getAngleType function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getAngleType;
Expand All @@ -35,3 +40,31 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");
let acute = getAngleType(1);
assertEquals(acute, "Acute angle");
acute = getAngleType(45);
assertEquals(acute, "Acute angle");
acute = getAngleType(89);
assertEquals(acute, "Acute angle");
let obtuse = getAngleType(91);
assertEquals(obtuse, "Obtuse angle");
obtuse = getAngleType(100);
assertEquals(obtuse, "Obtuse angle");
obtuse = getAngleType(179);
assertEquals(obtuse, "Obtuse angle");
const straight = getAngleType(180);
assertEquals(straight, "Straight angle");
let reflex = getAngleType(200);
assertEquals(reflex, "Reflex angle");
reflex = getAngleType(243);
assertEquals(reflex, "Reflex angle");
reflex = getAngleType(359);
assertEquals(reflex, "Reflex angle");
let invalid = getAngleType(-11);
assertEquals(invalid, "Invalid angle");
invalid = getAngleType(0);
assertEquals(invalid, "Invalid angle");
invalid = getAngleType(360);
assertEquals(invalid, "Invalid angle");
invalid = getAngleType(371);
assertEquals(invalid, "Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (Math.abs(numerator) < Math.abs(denominator)) return true;
else return false;
}

// The line below allows us to load the isProperFraction function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = isProperFraction;
Expand All @@ -31,3 +32,9 @@ function assertEquals(actualOutput, targetOutput) {

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(7, 4), false);
assertEquals(isProperFraction(-8, 5), false);
assertEquals(isProperFraction(9, 10), true);
assertEquals(isProperFraction(-3, -6), true);
assertEquals(isProperFraction(15, 11), false);
assertEquals(isProperFraction(-17, -24), true);
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,25 @@
// Acceptance criteria:
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
if (typeof card !== "string") {
throw new Error("Invalid card");
}
const validSuits = ["♠", "♥", "♦", "♣"];
const suit = card.slice(-1);
const rank = card.slice(0, -1);
if (!validSuits.includes(suit)) {
throw new Error("Invalid card");
} else if (rank === "A") return 11;
else if (["J", "Q", "K"].includes(rank)) return 10;
const number = Number(rank);
if (number >= 2 && number <= 10) return number;
throw new Error("Invalid card");
}

module.exports = getCardValue;

// The line below allows us to load the getCardValue function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getCardValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,40 @@ const getAngleType = require("../implement/1-get-angle-type");
// including boundary and invalid cases.

// Case 1: Acute angles
test(`should return "Acute angle" when (0 < angle < 90)`, () => {
test(`should return "Acute angles" when (0 < angle < 90)`, () => {
// 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");
expect(getAngleType(1)).toBe("Acute angle");
expect(getAngleType(45)).toBe("Acute angle");
expect(getAngleType(89)).toBe("Acute angle");
});

// Case 2: Right angle
test(`should return "Right angle" when (angle === 90)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(90)).toBe("Right angle");
});
// Case 3: Obtuse angles
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(97)).toBe("Obtuse angle");
expect(getAngleType(129)).toBe("Obtuse angle");
expect(getAngleType(165)).toBe("Obtuse angle");
});
// Case 4: Straight angle
test(`should return "Straight angle" when (angle ==180)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(180)).toBe("Straight angle");
});
// Case 5: Reflex angles
test(`should return "Reflex angles" when (180 < angle < 360)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(191)).toBe("Reflex angle");
expect(getAngleType(250)).toBe("Reflex angle");
expect(getAngleType(317)).toBe("Reflex angle");
});
// Case 6: Invalid angles
test(`should return "Invalid angles" when (angle >= 360 or angle<= 0 )`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(0)).toBe("Invalid angle");
expect(getAngleType(-45)).toBe("Invalid angle");
expect(getAngleType(370)).toBe("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
const isProperFraction = require("../implement/2-is-proper-fraction");

// 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`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
expect(isProperFraction(0, 1)).toEqual(true);
expect(isProperFraction(0, -1)).toEqual(true);
expect(isProperFraction(18, 1)).toEqual(false);
expect(isProperFraction(7, 3)).toEqual(false);
expect(isProperFraction(1, -2)).toEqual(true);
expect(isProperFraction(-15, -9)).toEqual(false);
expect(isProperFraction(-2, -6)).toEqual(true);
expect(isProperFraction(-137, -71)).toEqual(false);
expect(isProperFraction(-100, -189)).toEqual(true);
expect(isProperFraction(27, 5)).toEqual(false);
expect(isProperFraction(-29, 17)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,26 @@ const getCardValue = require("../implement/3-get-card-value");
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});

// Case 2: Number Cards (2-10)
test(`Should return the numeric value for number cards`, () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("5♥")).toEqual(5);
expect(getCardValue("9♦")).toEqual(9);
expect(getCardValue("10♣")).toEqual(10);
});
// Case 3: Face Cards (J, Q, K)
test(`Should return 10 for face cards`, () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q♥")).toEqual(10);
expect(getCardValue("K♦")).toEqual(10);
});
// Case 4: Invalid Cards
test(`Should throw "Invalid card" for invalid cards`, () => {
expect(() => getCardValue("1♠")).toThrow("Invalid card");
expect(() => getCardValue("B♠")).toThrow("Invalid card");
expect(() => getCardValue("A$")).toThrow("Invalid card");
expect(() => getCardValue("10X")).toThrow("Invalid card");
});
// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
Expand All @@ -17,4 +36,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

15 changes: 0 additions & 15 deletions package.json

This file was deleted.

Loading