Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@

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.
// This will be useful in the "rewrite tests with jest" step.
Expand All @@ -35,3 +48,13 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");
const acute = getAngleType(45);
assertEquals(acute, "Acute angle");
const obtuse = getAngleType(120);
assertEquals(obtuse, "Obtuse angle");
const straight = getAngleType(180);
assertEquals(straight, "Straight angle");
const reflex = getAngleType(270);
assertEquals(reflex, "Reflex angle");
const invalid = getAngleType(400);
assertEquals(invalid, "Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {


// TODO: Implement this function
if (denominator === 0) {
return false;
}
if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
} else {
return false;
}
}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand All @@ -24,10 +34,19 @@ function assertEquals(actualOutput, targetOutput) {
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);

}

// 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(2, 1), false);
assertEquals(isProperFraction(-1, 2), true);
assertEquals(isProperFraction(1, -2), true);
assertEquals(isProperFraction(0, 2), true);
assertEquals(isProperFraction(2, 2), false);
assertEquals(isProperFraction(-2, -1), false);
assertEquals(isProperFraction(-2, -2), false);
assertEquals(isProperFraction(1, 0), false);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@

function getCardValue(card) {
// TODO: Implement this function
const rank = card.slice(0, -1); // Get the rank by slicing off the last character (the suit)
const suit = card.slice(-1); // Get the suit by taking the last character of the string

// Validate the suit
const validSuits = ["♠", "♥", "♦", "♣"];
if (!validSuits.includes(suit)) {
throw new Error("Invalid card: Invalid suit");
}
// Determine the value based on the rank
if (rank === "A") {
return 11;
} else if (["J", "Q", "K"].includes(rank)) {
return 10;
} else if (!isNaN(rank) && parseInt(rank) >= 2 && parseInt(rank) <= 10) {
return parseInt(rank);
} else {
throw new Error("Invalid card: Invalid rank");
}
}

// 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 @@ -5,16 +5,41 @@ const getAngleType = require("../implement/1-get-angle-type");
// TODO: Write tests in Jest syntax to cover all cases/outcomes,
// 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
test("should identify acute angles", () => {
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});

// Case 2: Right angle
test("should identify right angles", () => {
expect(getAngleType(90)).toEqual("Right angle");
});

// Case 3: Obtuse angles
test("should identify obtuse angles", () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(120)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});

// Case 4: Straight angle
test("should identify straight angles", () => {
expect(getAngleType(180)).toEqual("Straight angle");
});

// Case 5: Reflex angles
test("should identify reflex angles", () => {
expect(getAngleType(190)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});

// Case 6: Invalid angles
test("should identify invalid angles", () => {
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(361)).toEqual("Invalid angle");
expect(getAngleType(400)).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);
});
// Case 1: Proper fractions
test(`should return true for proper fractions`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(-1, 2)).toEqual(true);
expect(isProperFraction(1, -2)).toEqual(true);
expect(isProperFraction(-1, -2)).toEqual(true);
expect(isProperFraction(0, 2)).toEqual(true);
});

// Case 2: Improper fractions
test(`should return false for improper fractions`, () => {
expect(isProperFraction(2, 1)).toEqual(false);
expect(isProperFraction(-2, 1)).toEqual(false);
expect(isProperFraction(2, -1)).toEqual(false);
expect(isProperFraction(-2, -1)).toEqual(false);
expect(isProperFraction(2, 2)).toEqual(false);
expect(isProperFraction(-2, -2)).toEqual(false);
});
// Case 3: Invalid fractions (denominator is zero)
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
expect(isProperFraction(-1, 0)).toEqual(false);
expect(isProperFraction(0, 0)).toEqual(false);
});