Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,28 @@
// execute the code to ensure all tests pass.

function getAngleType(angle) {
// TODO: Implement this function
// [ChunYanWong] Implement this function
if (angle === 90) {
return "Right angle";
}

if (angle < 90 && angle > 0) {
return "Acute 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";
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
// [ChunYanWong] Implement this function
if (denominator === 0) {
return false;
}

// Compare absolute values
return Math.abs(numerator) < Math.abs(denominator);
}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,30 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
// [ChunYanWong] Implement this function
const suit = card.slice(-1);
const rank = card.slice(0, -1);


// Ace value
if (rank === "A") {
return 11;
}

// Face card values
if (["J", "Q", "K"].includes(rank)) {
return 10;
}

// Number card values ("2" through "10")
const numericValue = parseInt(rank, 10);
if (!isNaN(numericValue) && numericValue >= 2 && numericValue <= 10) {
return numericValue;
}

throw new Error("Invalid card string");


}

// 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 @@ -6,15 +6,36 @@ 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 angle" 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");
});


// [ChunYanWong]
// Case 2: Right angle
test('should return "Right angle" for exactly 90', () => {
expect(getAngleType(90)).toEqual("Right angle");
});
// Case 3: Obtuse angles
test('should return "Obtuse angle" for values between 90 and 180', () => {
expect(getAngleType(90.1)).toEqual("Obtuse angle");
expect(getAngleType(135)).toEqual("Obtuse angle");
expect(getAngleType(179.9)).toEqual("Obtuse angle");
});
// Case 4: Straight angle
test('should return "Straight angle" for exactly 180', () => {
expect(getAngleType(180)).toEqual("Straight angle");
});
// Case 5: Reflex angles
test('should return "Reflex angle" for values between 180 and 360', () => {
expect(getAngleType(180.1)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359.9)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test('should return "Invalid angle" for values greater than 360', () => {
expect(getAngleType(400)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ 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`, () => {
test('should return false when denominator is zero', () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

//[Chun Yan Wong]

test('returns true when numerator absolute value is less than denominator absolute value', () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(-1, 2)).toEqual(true);
expect(isProperFraction(3, -5)).toEqual(true);
});

test('returns false when numerator absolute value is equal to denominator absolute value', () => {
expect(isProperFraction(2, 2)).toEqual(false);
expect(isProperFraction(-3, 3)).toEqual(false);
});

test('returns false when numerator absolute value is greater than denominator absolute value', () => {
expect(isProperFraction(5, 2)).toEqual(false);
expect(isProperFraction(-7, 3)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,31 @@ test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
// Invalid Cards
// Number cards (2–10)
test('returns correct numeric values for number cards', () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("5♥")).toEqual(5);
expect(getCardValue("9♦")).toEqual(9);
expect(getCardValue("10♣")).toEqual(10);
});

// Face cards
test('returns 10 for face cards', () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q♥")).toEqual(10);
expect(getCardValue("K♦")).toEqual(10);
});

// Ace
test('returns 11 for Ace', () => {
expect(getCardValue("A♣")).toEqual(11);
});

// Invalid cards
test('invalid card strings should throw an error', () => {
expect(() => getCardValue("A")).toThrow();
expect(() => getCardValue("B")).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
Expand Down
Loading