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

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.
Expand All @@ -35,3 +40,34 @@ 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(181);
assertEquals(reflex, "Reflex angle");
reflex = getAngleType(200);
assertEquals(reflex, "Reflex angle");
reflex = getAngleType(359);
assertEquals(reflex, "Reflex angle");
let invalid = getAngleType(-1);
assertEquals(invalid, "Invalid angle");
invalid = getAngleType(0);
assertEquals(invalid, "Invalid angle");
invalid = getAngleType(360);
assertEquals(invalid, "Invalid angle");
invalid = getAngleType(361);
assertEquals(invalid, "Invalid angle");



Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
// execute the code to ensure all tests pass.

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 +34,12 @@ function assertEquals(actualOutput, targetOutput) {

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(7, 1), false);
assertEquals(isProperFraction(0, 5), true);
assertEquals(isProperFraction(-1, -2), true);
assertEquals(isProperFraction(-2, -1), false);
assertEquals(isProperFraction(-2, 5), true);
assertEquals(isProperFraction(5, -2), false);
assertEquals(isProperFraction(5, 5), false);
assertEquals(isProperFraction(5, 0), false);
assertEquals(isProperFraction(-2, 0), false);
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@
// execute the code to ensure all tests pass.

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

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -40,13 +51,62 @@ function assertEquals(actualOutput, targetOutput) {
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
assertEquals(getCardValue("9♠"), 9);

assertEquals(getCardValue("A♠"), 11);
assertEquals(getCardValue("2♥"), 2);
assertEquals(getCardValue("10♥"), 10);
assertEquals(getCardValue("Q♦"), 10);
assertEquals(getCardValue("J♣"), 10);
assertEquals(getCardValue("K♠"), 10);
// Handling invalid cards
try {
getCardValue("invalid");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card");
} catch (e) {}
} catch (e) {
assertEquals(e.message, "Invalid card")
}
try {
getCardValue("♦Q");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card");
} catch (e) {
assertEquals(e.message, "Invalid card")
}
try {
getCardValue("11♦");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card");
} catch (e) {
assertEquals(e.message, "Invalid card")
}

try {
getCardValue("AX");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card");
} catch (e) {
assertEquals(e.message, "Invalid card")
}

try {
getCardValue("KX");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card");
} catch (e) {
assertEquals(e.message, "Invalid card")
}

try {
getCardValue("5X");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card");
} catch (e) {
assertEquals(e.message, "Invalid card")
}
// What other invalid card cases can you think of?
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,31 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// Case 2: Right angle
test(`should return "Right angle" when (angle = 90)`, () => {
expect(getAngleType(90)).toEqual("Right angle");
});
// Case 3: Obtuse angles
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(100)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});
// Case 4: Straight angle
test(`should return "Straight angle" when (angle = 180)`, () => {
expect(getAngleType(180)).toEqual("Straight angle");
});
// Case 5: Reflex angles
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(200)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test(`should return "Invalid angle" when (360 <= angle or angle <= 0)`, () => {
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(361)).toEqual("Invalid angle");
});


Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ 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 0`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});
test(`should return true when numerator is less than denominator`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});
test(`should return false when numerator is greater than denominator`, () => {
expect(isProperFraction(7, 1)).toEqual(false);
});
test(`should return true when numerator is 0 and denominator is positive`, () => {
expect(isProperFraction(0, 5)).toEqual(true);
});
test(`should return true when numerator and denominator are negative`, () => {
expect(isProperFraction(-1, -2)).toEqual(true);
});
test(`should return false when numerator and denominator are negative and numerator is greater than denominator`, () => {
expect(isProperFraction(-2, -1)).toEqual(false);
});
test(`should return true when numerator is negative and denominator is positive`, () => {
expect(isProperFraction(-2, 5)).toEqual(true);
});
test(`should return false when numerator is positive and denominator is negative`, () => {
expect(isProperFraction(5, -2)).toEqual(false);
});
test(`should return false when numerator equals denominator`, () => {
expect(isProperFraction(5, 5)).toEqual(false);
});
test(`should return false when denominator is 0 and numerator is positive`, () => {
expect(isProperFraction(5, 0)).toEqual(false);
});
test(`should return false when denominator is 0 and numerator is negative`, () => {
expect(isProperFraction(-2, 0)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,47 @@ const getCardValue = require("../implement/3-get-card-value");
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});
test(`Should return 9 when given an 9♠`, () => {
expect(getCardValue("9♠")).toEqual(9);
});
test(`Should return 2 when given an 2♥`, () => {
expect(getCardValue("2♥")).toEqual(2);
});
test(`Should return 10 when given an 10♥`, () => {
expect(getCardValue("10♥")).toEqual(10);
});
test(`Should return 10 when given an J♣`, () => {
expect(getCardValue("J♣")).toEqual(10);
});
test(`Should return 10 when given an K♠`, () => {
expect(getCardValue("K♠")).toEqual(10);
});
test(`Should throw Error when given an ♦Q`, () => {
expect(function() {
getCardValue("♦Q");
}).toThrow("Invalid card");
});
test(`Should throw Error when given an 11♦`, () => {
expect(function() {
getCardValue("11♦");
}).toThrow("Invalid card");
});
test(`Should throw Error when given an AX`, () => {
expect(function() {
getCardValue("AX");
}).toThrow("Invalid card");
});
test(`Should throw Error when given an KX`, () => {
expect(function() {
getCardValue("KX");
}).toThrow("Invalid card");
});
test(`Should throw Error when given an 5X`, () => {
expect(function() {
getCardValue("5X");
}).toThrow("Invalid card");
});


// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
Expand Down