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 @@ -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,7 @@
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
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 +31,10 @@ 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);
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
const cardNum = card.slice(0, -1)
if (cardNum === "A") { return 11}
else if (["J", "Q", "K"].includes(cardNum)) { return 10}
else if (Number(cardNum) >= 2 && Number(cardNum) <= 10) {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 +44,27 @@ 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);
// 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) {}
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) {}
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) {}
// 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 @@ -8,3 +8,27 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});
test(`1/2`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});
test(`7/1`, () => {
expect(isProperFraction(7, 1)).toEqual(false);
});
test(`0/5`, () => {
expect(isProperFraction(0, 5)).toEqual(true);
});
test(`-1/-2`, () => {
expect(isProperFraction(-1, -2)).toEqual(true);
});
test(`-2/-1`, () => {
expect(isProperFraction(-2, -1)).toEqual(false);
});
test(`-2/5`, () => {
expect(isProperFraction(-2, 5)).toEqual(true);
});
test(`5/-2`, () => {
expect(isProperFraction(5, -2)).toEqual(false);
});
test(`5/5`, () => {
expect(isProperFraction(5, 5)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ 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 Q♦`, () => {
expect(getCardValue("Q♦")).toEqual(10);
});
test(`Should return Error when given an ♦Q`, () => {
expect(function() {getCardValue("♦Q");}).toThrow("Invalid card");
});
test(`Should return Error when given an 11♦`, () => {
expect(function() {getCardValue("11♦")}).toThrow("Invalid card");
});


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