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,6 +16,19 @@

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";
}
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -35,3 +48,18 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");

const acute = getAngleType(45);
assertEquals(acute, "Acute angle");

const obtuse = getAngleType(135);
assertEquals(obtuse, "Obtuse angle");

const straight = getAngleType(180);
assertEquals(straight, "Straight angle");

const reflex = getAngleType(270);
assertEquals(reflex, "Reflex angle");

const invalid = getAngleType(400);
assertEquals(invalid, "Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

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

// The line below allows us to load the isProperFraction function into tests in other files.
Expand All @@ -31,3 +35,26 @@ function assertEquals(actualOutput, targetOutput) {

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(2, 4), true);
assertEquals(isProperFraction(4, 2), false);

assertEquals(isProperFraction(0, 2), true);
assertEquals(isProperFraction(2, 0), false);
assertEquals(isProperFraction(0, -5), true);
assertEquals(isProperFraction(5, 0), false);

assertEquals(isProperFraction(3, 3), false);
assertEquals(isProperFraction(-3, 3), false);
assertEquals(isProperFraction(3, -3), false);
assertEquals(isProperFraction(-3, -3), false);

assertEquals(isProperFraction(-1, 2), true);
assertEquals(isProperFraction(1, -2), true);
assertEquals(isProperFraction(-3, -4), true);

assertEquals(isProperFraction(0.5, 1), true);
assertEquals(isProperFraction(1.5, 1), false);
assertEquals(isProperFraction(1.1, 1), false);

assertEquals(isProperFraction(1e9, 1e10), true);
assertEquals(isProperFraction(1e10, 1e9), false);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@

function getCardValue(card) {
// TODO: Implement this function
if (typeof card !== "string") {
throw new Error("Card must be a string");
}

const match = card.match(/^(A|10|[2-9]|J|Q|K)([♠♥♦♣])$/);
if (!match) {
throw new Error("Invalid card format");
}

const rank = match[1];
if (rank === "A") return 11;
if (rank === "J" || rank === "Q" || rank === "K") return 10;
return Number(rank);
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,43 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// Case 2: Right angle
test(`should return "Right angle" when angle is exactly 90`, () => {
expect(getAngleType(90)).toEqual("Right angle");
});

// Case 3: Obtuse angles
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
// Representative obtuse values across the range
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(135)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});

// Case 4: Straight angle
test(`should return "Straight angle" for 180`, () => {
expect(getAngleType(180)).toEqual("Straight angle");
});

test(`should NOT return "Straight angle" for values just below or above 180`, () => {
expect(getAngleType(179.999)).not.toEqual("Straight angle");
expect(getAngleType(180.001)).not.toEqual("Straight angle");
});

test(`should classify 179 as 'Obtuse angle' and 181 as 'Reflex angle'`, () => {
expect(getAngleType(179)).toEqual("Obtuse angle");
expect(getAngleType(181)).toEqual("Reflex angle");
});

// Case 5: Reflex angles
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
// Representative reflex values across the range
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});

// Case 6: Invalid angles
test(`should return "Invalid angle" for angles < 0 or > 360`, () => {
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,67 @@ 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);
// Tests using top-level `test()` calls

test("denominator 0 returns false", () => {
expect(isProperFraction(1, 0)).toBe(false);
});

test("1/2 is a proper fraction", () => {
expect(isProperFraction(1, 2)).toBe(true);
});

test("2/4 is a proper fraction (non-reduced)", () => {
expect(isProperFraction(2, 4)).toBe(true);
});

test("5/4 is not a proper fraction", () => {
expect(isProperFraction(5, 4)).toBe(false);
});

test("2/2 is not a proper fraction (equal numerator and denominator)", () => {
expect(isProperFraction(2, 2)).toBe(false);
});

test("0/5 is proper", () => {
expect(isProperFraction(0, 5)).toBe(true);
});

test("0/-5 is proper (negative denominator)", () => {
expect(isProperFraction(0, -5)).toBe(true);
});

test("negative numerator handled via absolute value", () => {
expect(isProperFraction(-1, 2)).toBe(true);
});

test("negative denominator handled via absolute value", () => {
expect(isProperFraction(1, -2)).toBe(true);
});

test("both negative handled via absolute value", () => {
expect(isProperFraction(-3, -4)).toBe(true);
});

test("-3/3 is not proper (equal abs values)", () => {
expect(isProperFraction(-3, 3)).toBe(false);
});

test("decimal numerator works (0.5/1)", () => {
expect(isProperFraction(0.5, 1)).toBe(true);
});

test("decimal where numerator > denominator (1/0.9999)", () => {
expect(isProperFraction(1, 0.9999)).toBe(false);
});

// Optional: uncomment if implementation is updated to reject non-finite values
// test('NaN inputs return false', () => {
// expect(isProperFraction(NaN, 1)).toBe(false);
// expect(isProperFraction(1, NaN)).toBe(false);
// });

// test('Infinity inputs return false', () => {
// expect(isProperFraction(Infinity, 1)).toBe(false);
// expect(isProperFraction(1, Infinity)).toBe(false);
// });
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,28 @@ const getCardValue = require("../implement/3-get-card-value");
// TODO: Write tests in Jest syntax to cover all possible outcomes.

// Case 1: Ace (A)
test(`Should return 11 when given an ace card`, () => {
test("Should return 11 when given an ace card", () => {
expect(getCardValue("A♠")).toEqual(11);
});

test("face cards return 10", () => {
expect(getCardValue("J♣")).toEqual(10);
expect(getCardValue("Q♦")).toEqual(10);
expect(getCardValue("K♦")).toEqual(10);
});

test("number cards return their numeric value", () => {
expect(getCardValue("2♥")).toEqual(2);
expect(getCardValue("10♥")).toEqual(10);
expect(getCardValue("9♥")).toEqual(9);
});

test("invalid input throw", () => {
expect(() => getCardValue("invalid")).toThrow();
expect(() => getCardValue("A")).toThrow();
expect(() => getCardValue(null)).toThrow();
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
Expand All @@ -17,4 +35,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