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

function getAngleType(angle) {
// TODO: Implement this function
if (angle === 180) {
return "Straight angle";
}
if (angle > 180 && angle < 360) {
return "Reflex angle";
}
if (angle === 90) {
return "Right angle";
}
if (angle > 0 && angle < 90) {
return "Acute angle";
}
if (angle > 90 && angle < 180) {
return "Obtuse angle";
}
return "Invalid angle";
// Run the tests, work out what Case 2 is testing, and implement the required code here.
// Then keep going for the other cases, one at a time.
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -35,3 +52,30 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");

// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"
const acute = getAngleType(45);
assertEquals(acute, "Acute angle");

// Case 3: Identify Obtuse Angles:
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
// ====> write your test here, and then add a line to pass the test in the function above
assertEquals(obtuse, "Obtuse angle");

// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
// ====> write your test here, and then add a line to pass the test in the function above
const straight = getAngleType(180);
assertEquals(straight, "Straight angle");

// Case 5: Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
// ====> write your test here, and then add a line to pass the test in the function above
const reflex = getAngleType(270);
assertEquals(reflex, "Reflex angle");
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (denominator === 0) {
return false;
} else 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 @@ -26,8 +32,51 @@ function assertEquals(actualOutput, targetOutput) {
);
}

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

// Proper Fraction check:
// Input: numerator = 2, denominator = 3
// target output: true
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
const properFraction = isProperFraction(2, 3);
assertEquals(properFraction, true);

// Improper Fraction check:
// Input: numerator = 5, denominator = 2
// target output: false
// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false.
const improperFraction = isProperFraction(5, 2);
assertEquals(improperFraction, false);

// Negative Fraction check:
// Input: numerator = -4, denominator = 7
// target output: true
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
const negativeFraction = isProperFraction(-4, 7);
// ====> complete with your assertion
assertEquals(negativeFraction, true);

// Equal Numerator and Denominator check:
// Input: numerator = 3, denominator = 3
// target output: false
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
const equalFraction = isProperFraction(3, 3);
// ====> complete with your assertion
assertEquals(equalFraction, false);

// Stretch:
// What other scenarios could you test for?

// Zero Numerator check:
// Input: numerator = 0, denominator = 5
// target output: true
// Explanation: The fraction 0/5 is a proper fraction because the numerator is less than the denominator.
const zeroNumerator = isProperFraction(0, 5);
assertEquals(zeroNumerator, true);

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
// Zero Denominator check:
// Input: numerator = 5, denominator = 0
// target output: false
// Explanation: The fraction 5/0 is undefined because division by zero is not allowed.
const zeroDenominator = isProperFraction(5, 0);
assertEquals(zeroDenominator, false);
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
const rank = card.slice(0, card.length - 1);
if (rank === "A") {
return 11;
} else if (Number(rank) >= 2 && Number(rank) < 10) {
return Number(rank);
} else if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") {
return 10;
} else {
return "Invalid card rank";
}
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -41,12 +50,31 @@ function assertEquals(actualOutput, targetOutput) {
// Examples:
assertEquals(getCardValue("9♠"), 9);

// Handling invalid cards
try {
getCardValue("invalid");
// Handle Number Cards (2-10):
// Given a card with a rank between "2" and "9",
// When the function is called with such a card,
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
const fiveofHearts = getCardValue("5♥");
// ====> write your test here, and then add a line to pass the test in the function above
assertEquals(fiveofHearts, 5);

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card");
} catch (e) {}
// Handle Face Cards (J, Q, K):
// Given a card with a rank of "10," "J," "Q," or "K",
// When the function is called with such a card,
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
const kingofDiamonds = getCardValue("K♦");
assertEquals(kingofDiamonds, 10);

// What other invalid card cases can you think of?
// Handle Ace (A):
// Given a card with a rank of "A",
// When the function is called with an Ace,
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack.
const aceofClubs = getCardValue("A♣");
assertEquals(aceofClubs, 11);

// Handle Invalid Cards:
// Given a card with an invalid rank (neither a number nor a recognized face card),
// When the function is called with such a card,
// Then it should throw an error indicating "Invalid card rank."
const invalidCard = getCardValue("1♠");
assertEquals(invalidCard, "Invalid card 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 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(135)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});
// Case 4: Straight angle
test(`should return "Straight angle" when angle is 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(270)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test(`should return "Invalid angle" when angle is <= 0 or >= 360`, () => {
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(-10)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(400)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

test(`should return true for proper fraction with positive numerator and denominator`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

test(`should return false for improper fraction with positive numerator and denominator`, () => {
expect(isProperFraction(3, 2)).toEqual(false);
});

test(`should return true for numerator zero and positive denominator`, () => {
expect(isProperFraction(0, 5)).toEqual(true);
});

test(`should return false for denominator zero`, () => {
expect(isProperFraction(5, 0)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,27 @@ test(`Should return 11 when given an ace card`, () => {
// Face Cards (J, Q, K)
// Invalid Cards

// Case 2: Number Cards (2-10)
test(`Should return the correct value for number cards`, () => {
expect(getCardValue("2♣")).toEqual(2);
expect(getCardValue("5♦")).toEqual(5);
expect(getCardValue("10♥")).toEqual(10);
});

// Case 3: Face Cards (J, Q, K)
test(`Should return 10 for face cards`, () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q♦")).toEqual(10);
expect(getCardValue("K♥")).toEqual(10);
});

// Case 4: Invalid Cards
test(`Should return Invalid card rank for invalid cards`, () => {
expect(getCardValue("1♠")).toEqual("Invalid card rank");
expect(getCardValue("11♥")).toEqual("Invalid card rank");
expect(getCardValue("Z♦")).toEqual("Invalid card rank");
});

// 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