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,19 @@
// 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 (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 +47,23 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");

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

// Identify Obtuse Angles
const obtuse = getAngleType(120);
assertEquals(obtuse, "Obtuse angle");

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

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

// Identify Invalid Angles
const invalid = getAngleType(400);
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 numerator < denominator;
}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand All @@ -29,5 +29,18 @@ function assertEquals(actualOutput, targetOutput) {
// TODO: Write tests to cover all cases.
// What combinations of numerators and denominators should you test?

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

// Example #2: 1/0 is not a proper fraction
assertEquals(isProperFraction(1, 0), false);

// Example #3: 5/5 is not a proper fraction
assertEquals(isProperFraction(5, 5), false);

// Example #4: 7/4 is not a proper fraction
assertEquals(isProperFraction(7, 4), false);

// Example #5: -1/2 and -5/-2 are proper fractions
assertEquals(isProperFraction(-1, 2), true);
assertEquals(isProperFraction(-5, -2), true);
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,31 @@
// execute the code to ensure all tests pass.

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

const values = {
A: 11,
J: 10,
Q: 10,
K: 10,
};

const validSuits = ["♠", "♥", "♦", "♣"];

if (!validSuits.includes(suit)) {
throw new Error("Invalid card");
}

if (values[rank]) {
return values[rank];
}

if (Number(rank) >= 2 && Number(rank) <= 10) {
return Number(rank);
}

throw new Error("Invalid card");
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand Down Expand Up @@ -52,3 +76,38 @@ try {
}

// What other invalid card cases can you think of?
// Invalid rank
try {
getCardValue("1♠");

console.error("Error was not thrown for invalid rank 😢");
} catch (e) {
console.log("Error thrown for invalid rank 🎉");
}

// Invalid suit
try {
getCardValue("9X");

console.error("Error was not thrown for invalid suit 😢");
} catch (e) {
console.log("Error thrown for invalid suit 🎉");
}

// Missing suit
try {
getCardValue("A");

console.error("Error was not thrown for missing suit 😢");
} catch (e) {
console.log("Error thrown for missing suit 🎉");
}

// Missing rank
try {
getCardValue("♠");

console.error("Error was not thrown for missing rank 😢");
} catch (e) {
console.log("Error thrown for missing rank 🎉");
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,29 @@ 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)`, () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(120)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});

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

// Case 5: Reflex angles
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
expect(getAngleType(270)).toEqual("Reflex angle");
});

// Case 6: Invalid angles
test(`should return "Invalid angle" for invalid angles`, () => {
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,28 @@ 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
// Special case: denominator is zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

// Case #1: numerator is smaller than denominator
test(`should return true when numerator is smaller than denominator`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

// Case #2: numerator is equal to denominator
test(`should return false when numerator and denominator are equal`, () => {
expect(isProperFraction(5, 5)).toEqual(false);
});

// Case #3: numerator is bigger than denominator
test(`should return false when numerator is greater than denominator`, () => {
expect(isProperFraction(7, 4)).toEqual(false);
});

// Case #4: numerator and/or denominator are negative numbers
test(`should handle negative numbers`, () => {
expect(isProperFraction(-1, 2)).toEqual(true);
expect(isProperFraction(-5, -2)).toEqual(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,23 @@ test(`Should return 11 when given an ace card`, () => {
// please refer to the Jest documentation:
// https://jestjs.io/docs/expect#tothrowerror

// Number Cards (2-10)
test(`Should return the number value when given a number card`, () => {
expect(getCardValue("2♥")).toEqual(2);
expect(getCardValue("5♦")).toEqual(5);
expect(getCardValue("10♣")).toEqual(10);
});

// Face Cards (J, Q, K)
test(`Should return 10 when given a face card`, () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q♥")).toEqual(10);
expect(getCardValue("K♦")).toEqual(10);
});

// Invalid Cards
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("invalid")).toThrow();
expect(() => getCardValue("1♠")).toThrow();
expect(() => getCardValue("9X")).toThrow();
});
Loading