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 @@ -12,10 +12,15 @@

// Acceptance criteria:
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.
// execute the code to ensure all tests pass.Reflex

function getAngleType(angle) {
// TODO: Implement this function
if (angle > 0 && angle < 90) return "Acute angle";
if (angle === 90) return "Right 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 All @@ -33,5 +38,20 @@ function assertEquals(actualOutput, targetOutput) {

// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");
assertEquals(getAngleType(1), "Acute angle");
assertEquals(getAngleType(45), "Acute angle");
assertEquals(getAngleType(89), "Acute angle");
assertEquals(getAngleType(90), "Right angle");
assertEquals(getAngleType(91), "Obtuse angle");
assertEquals(getAngleType(135), "Obtuse angle");
assertEquals(getAngleType(179), "Obtuse angle");
assertEquals(getAngleType(180), "Straight angle");
assertEquals(getAngleType(181), "Reflex angle");
assertEquals(getAngleType(269), "Reflex angle");
assertEquals(getAngleType(270), "Reflex angle");
assertEquals(getAngleType(271), "Reflex angle");
assertEquals(getAngleType(359), "Reflex angle");
assertEquals(getAngleType(360), "Invalid angle");
assertEquals(getAngleType(0), "Invalid angle");
assertEquals(getAngleType(-1), "Invalid angle");
assertEquals(getAngleType(400), "Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
let numeratorVal = Math.abs(numerator);
let denominatorVal = Math.abs(denominator);

if (denominator === 0) return false;
if (numeratorVal < denominatorVal) return true;
return false;
}

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

assertEquals(isProperFraction(0, 4), true);
assertEquals(isProperFraction(4, 0), false);
assertEquals(isProperFraction(7, 4), false);
assertEquals(isProperFraction(4, 7), true);
assertEquals(isProperFraction(-7, 4), false);
assertEquals(isProperFraction(7, -4), false);
assertEquals(isProperFraction(-4, 7), true);
assertEquals(isProperFraction(4, -7), true);
assertEquals(isProperFraction(4, 4), false);

// TODO: Write tests to cover all cases.
// What combinations of numerators and denominators should you test?

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

function getCardValue(card) {
// TODO: Implement this function
let rank = card.slice(0, -1);
let suit = card.slice(-1);
const suitArray = ["♠", "♥", "♦", "♣"];
if (!suitArray.includes(suit)) throw new Error("Invalid card");
if (rank === "A") return 11;
if (rank === "Q" || rank === "K" || rank === "J") return 10;
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 All @@ -39,13 +46,37 @@ 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("A♣"), 11);
assertEquals(getCardValue("Q♠"), 10);
assertEquals(getCardValue("K♣"), 10);
assertEquals(getCardValue("J♦"), 10);
assertEquals(getCardValue("2♠"), 2);
assertEquals(getCardValue("10♣"), 10);

// Handling invalid cards
try {
getCardValue("invalid");
getCardValue("AX");
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}
try {
getCardValue("B♣");
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}

try {
getCardValue("1♦");
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}

// This line will not be reached if an error is thrown as expected
try {
getCardValue("11♣");
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,39 @@ 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 various acute angles, including boundary cases
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
describe("getAngleType", function () {
test("Acute angles", function () {
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});

test("Right angle", function () {
expect(getAngleType(90)).toEqual("Right angle");
});

test("Obtuse angles", function () {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(135)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});
test("Straight angle", function () {
expect(getAngleType(180)).toEqual("Straight angle");
});

test("Reflex angles", function () {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(269)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(271)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});
test("Invalid angle", function () {
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(400)).toEqual("Invalid angle");
expect(getAngleType(-1)).toEqual("Invalid angle");
});
});

// Case 2: Right angle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,34 @@ 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);
describe("isProperFraction", () => {
test("returns true when numerator is zero", () => {
expect(isProperFraction(0, 4)).toEqual(true);
});

test("returns false when denominator is zero", () => {
expect(isProperFraction(4, 0)).toEqual(false);
});

test("returns true for proper positive fractions", () => {
expect(isProperFraction(4, 7)).toEqual(true);
});

test("returns false for improper fractions", () => {
expect(isProperFraction(7, 4)).toEqual(false);
});

test("handles proper negative fractions", () => {
expect(isProperFraction(-4, 7)).toEqual(true);
expect(isProperFraction(4, -7)).toEqual(true);
});

test("handles improper negative fractions", () => {
expect(isProperFraction(-7, 4)).toEqual(false);
expect(isProperFraction(7, -4)).toEqual(false);
});

test("returns false when numerator equals denominator", () => {
expect(isProperFraction(4, 4)).toEqual(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,31 @@ 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`, () => {
expect(getCardValue("A♠")).toEqual(11);
describe("getCardValue", () => {
describe("Valid Card", () => {
test("Ace cards return 11", () => {
expect(getCardValue("A♠")).toEqual(11);
expect(getCardValue("A♣")).toEqual(11);
});
test("Face cards return 10", () => {
expect(getCardValue("Q♠")).toEqual(10);
expect(getCardValue("K♣")).toEqual(10);
expect(getCardValue("J♦")).toEqual(10);
});
test("Number cards return their value", () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("10♣")).toEqual(10);
});
});

describe("Invalid Card", () => {
test("Throw error for invalid inputs", () => {
expect(() => getCardValue("AX")).toThrow("Invalid card");
expect(() => getCardValue("B♣")).toThrow("Invalid card");
expect(() => getCardValue("1♦")).toThrow("Invalid card");
expect(() => getCardValue("11♣")).toThrow("Invalid card");
});
});
});

// Suggestion: Group the remaining test data into these categories:
Expand All @@ -17,4 +39,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

Loading