Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f17635b
Implement getAngleType function and add assertion tests
Iswanna Oct 20, 2025
3766d27
Add assertions to test function outputs
Iswanna Oct 20, 2025
f9eea26
Add test for when numerator is zero for stretch task
Iswanna Oct 20, 2025
cfda58c
Update getCardValue function to return correct numerical values and t…
Iswanna Oct 20, 2025
b7a2183
Add and verify Jest test cases for the function
Iswanna Oct 22, 2025
f028f06
Include package-lock.json to ensure consistent dependency versions
Iswanna Oct 22, 2025
fec9455
Write Jest tests to verify function behavior
Iswanna Oct 22, 2025
0032765
Change random number check to return a string instead of throwing an …
Iswanna Oct 22, 2025
69ddec4
Write Jest test cases for getCardValue function implementation
Iswanna Oct 22, 2025
8c717df
Add more Jest test cases for getCardValue implementation
Iswanna Oct 22, 2025
028ec7d
Update getAngleType implementation and add more test cases to verify …
Iswanna Oct 28, 2025
6bcf17a
Fix inconsistent code indentation
Iswanna Oct 28, 2025
00515f5
Add test cases for negative numerator/denominator and other edge case…
Iswanna Oct 28, 2025
31446ec
Remove console.log debugging code from 3-get-card-value.js file
Iswanna Oct 28, 2025
121ebe4
Add test cases and update getCardValue to handle all card ranks
Iswanna Oct 28, 2025
b46a6d3
Add additional test to verify getAngleType correctly handles float in…
Iswanna Oct 29, 2025
273a36a
Update getAngleType and tests to classify zero degree as "Zero angle"…
Iswanna Oct 29, 2025
48f2143
Add more Jest test cases for acute angles in getAngleType
Iswanna Oct 29, 2025
9705d12
Add more jest test cases for obtuse angles in getAngleType
Iswanna Oct 29, 2025
5c5e00b
Add a Jest test case for straight angle in getAngleType
Iswanna Oct 29, 2025
a66ab62
Add more Jest test cases for reflex angles in getAngleType
Iswanna Oct 29, 2025
3b9f415
Add Jest test case for full rotation (360°) in getAngleType
Iswanna Oct 29, 2025
5e0b672
Add more Jest test cases for invalid angles in getAngleType
Iswanna Oct 29, 2025
8daafbd
Add test for 0 input to verify getAngleType returns 'Zero angle'
Iswanna Oct 29, 2025
050e86a
Change expected output from true to false in isProperFraction test fo…
Iswanna Oct 29, 2025
df7ccfb
Add more Jest test cases for getCardValue to include 2 and 10
Iswanna Oct 29, 2025
46aee35
Add tests for getCardValue with "1♠" and empty string arguments to en…
Iswanna Oct 29, 2025
47809af
Change expected output to true for proper fractions with negative num…
Iswanna Oct 29, 2025
cfecb6c
Add edge case test cases for isProperFraction: floats, large numbers,…
Iswanna Oct 29, 2025
9a88261
Change expected output to true for proper fraction with negative nume…
Iswanna Oct 29, 2025
7a4e526
Refactor isProperFraction to improve readability and reduce repetition
Iswanna Oct 29, 2025
5411c34
Change the target output in the comment to true for proper fraction w…
Iswanna Oct 29, 2025
3b5e67d
Change false to true in the test description for proper fraction with…
Iswanna Oct 29, 2025
bbde7ad
Test multiple values in each test case
Iswanna Oct 29, 2025
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 @@ -8,11 +8,27 @@
// Then, write the next test! :) Go through this process until all the cases are implemented

function getAngleType(angle) {
if (angle === 90) {
if (typeof angle !== "number" || angle < 0 || angle > 360) {
return "Invalid angle";
}

if (angle === 0) {
return "Zero angle";
} else if (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 if (angle === 360) {
return "Full rotation";
}
// 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.

return "Invalid angle";
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -39,25 +55,63 @@ function assertEquals(actualOutput, targetOutput) {
// Then the function should return "Right angle"
const right = getAngleType(90);
assertEquals(right, "Right angle");
const rightEdge = getAngleType(90.0);
assertEquals(rightEdge, "Right angle");

// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// When the angle is greater than 0 degrees and less than 90 degrees,
// Then the function should return "Acute angle"
const acute = getAngleType(45);
assertEquals(acute, "Acute angle");
const acute1 = getAngleType(45);
assertEquals(acute1, "Acute angle");
const acute3 = getAngleType(89.999);
assertEquals(acute3, "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
const obtuse1 = getAngleType(91);
assertEquals(obtuse1, "Obtuse angle");
const obtuse2 = getAngleType(120);
assertEquals(obtuse2, "Obtuse angle");
const obtuse3 = getAngleType(179.999);
assertEquals(obtuse3, "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 straight1 = getAngleType(180);
assertEquals(straight1, "Straight angle");
const straightEdge = getAngleType(180.0);
assertEquals(straightEdge, "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 reflex1 = getAngleType(181);
assertEquals(reflex1, "Reflex angle");
const reflex2 = getAngleType(270);
assertEquals(reflex2, "Reflex angle");
const reflex3 = getAngleType(359.999);
assertEquals(reflex3, "Reflex angle");

// Case 6: Identify Full Rotation:
// When the angle is exactly 360 degrees,
// Then the function should return "Full rotation"
const fullRotation = getAngleType(360);
assertEquals(fullRotation, "Full rotation");

// Case 7: Handle Invalid Angles:
// When the angle is negative or greater than 360,
// Then the function should return "Invalid angle"
const invalid1 = getAngleType(-10);
assertEquals(invalid1, "Invalid angle");
const invalid2 = getAngleType(400);
assertEquals(invalid2, "Invalid angle");
const invalid3 = getAngleType("abc");
assertEquals(invalid3, "Invalid angle");

// Case 8: Identify Zero Angle:
// When the angle is exactly 0 degrees,
// Then the function should return "Zero angle"
const acute2 = getAngleType(0);
assertEquals(acute2, "Zero angle");
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,32 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (numerator < denominator) {
// Invalid input: must be integers
if (!Number.isInteger(numerator) || !Number.isInteger(denominator)) {
return false;
}

// Denominator cannot be zero
if (denominator === 0) {
return false;
}

// Numerator cannot be zero
if (numerator === 0) {
return false;
}

// Proper fraction: absolute numerator smaller than absolute denominator
if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
}

// All other cases are not proper fractions
return false;
}

// The line below allows us to load the isProperFraction function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
// This will be useful in the "rewrite tests with jest" step
module.exports = isProperFraction;

// here's our helper again
Expand Down Expand Up @@ -44,16 +63,90 @@ 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: false
const zeroNumerator = isProperFraction(0, 5);
assertEquals(zeroNumerator, false);

// Negative Denominator check:
// Input: numerator = 3, denominator = -5
// Target output: true
const negativeDenominator = isProperFraction(3, -5);
assertEquals(negativeDenominator, true);

// Both Negative check:
// Input: numerator = -2, denominator = -3
// Target output: true
const bothNegative = isProperFraction(-2, -3);
assertEquals(bothNegative, true);

// Zero Denominator check:
// Input: numerator = 1, denominator = 0
// Target output: false
// Explanation: Division by zero is invalid; fraction cannot be proper.
const zeroDenominator = isProperFraction(1, 0);
assertEquals(zeroDenominator, false);

// Float Numerator check:
// Input: numerator = 2.5, denominator = 3
// Target output: false
// Explanation: Fractions with a non-integer numerator are not considered proper fractions.
const floatNumerator = isProperFraction(2.5, 3);
assertEquals(floatNumerator, false);

// Float Denominator check:
// Input: numerator = 2, denominator = 3.5
// Target output: false
// Explanation: Fractions with a non-integer denominator are invalid and should not be considered proper fractions.
const floatDenominator = isProperFraction(2, 3.5);
assertEquals(floatDenominator, false);

// Both Numerator and Denominator as Floats check:
// Input: numerator = 1.5, denominator = 2.5
// Target output: false
// Explanation: Fractions with both numerator and denominator as floats are invalid and should not be considered proper fractions.
const floatBoth = isProperFraction(1.5, 2.5);
assertEquals(floatBoth, false);

// Large Number check:
// Input: numerator = 99, denominator = 100
// Target output: true
// Explanation: 99/100 is a valid proper fraction, even with large values.
const largeNumbers = isProperFraction(99, 100);
assertEquals(largeNumbers, true);

// Negative Zero check:
// Input: numerator = -0, denominator = 5
// Target output: false
// Explanation: Negative zero is equivalent to zero; not a proper fraction.
const negativeZero = isProperFraction(-0, 5);
assertEquals(negativeZero, false);

// Denominator less than -1 check:
// Input: numerator = 1, denominator = -1
// Target output: false
// Explanation: Equal magnitude makes it improper, regardless of sign.
const negOneDenominator = isProperFraction(1, -1);
assertEquals(negOneDenominator, false);

// Proper Fraction check:
// Input: numerator = 2, denominator = 4
// Target output: true
// Explanation: 2/4 is a proper fraction because the absolute value of the numerator is less than the absolute value of the denominator.
const twoOverFour = isProperFraction(2, 4);
assertEquals(twoOverFour, true);
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,29 @@
// write one test at a time, and make it pass, build your solution up methodically
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
function getCardValue(card) {
let rank = card.substring(0, card.length - 1); // Remove the suit emoji
let actualOutput;

if (rank === "A") {
return 11;
actualOutput = 11;
} else if (rank === "J" || rank === "Q" || rank === "K" || rank === "10") {
actualOutput = 10;
} else if (
rank === "2" ||
rank === "3" ||
rank === "4" ||
rank === "5" ||
rank === "6" ||
rank === "7" ||
rank === "8" ||
rank === "9"
) {
actualOutput = Number(rank);
} else {
actualOutput = "Invalid card rank.";
}

return actualOutput;
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -28,30 +48,47 @@ function assertEquals(actualOutput, targetOutput) {
}
// Acceptance criteria:

// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A),
// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit,
// and all characters before will be a number 2-10, or one letter of J, Q, K, A),
// When the function getCardValue is called with this card string as input,
// Then it should return the numerical card value
const aceofSpades = getCardValue("A♠");
assertEquals(aceofSpades, 11);
const aceOfSpades = getCardValue("A♠");
assertEquals(aceOfSpades, 11);

// 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♥");
const fiveOfHearts = getCardValue("5♥");
// ====> write your test here, and then add a line to pass the test in the function above
assertEquals(fiveOfHearts, 5);

// 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 jackOfDiamonds = getCardValue("J♦");
assertEquals(jackOfDiamonds, 10);

const queenOfClubs = getCardValue("Q♣");
assertEquals(queenOfClubs, 10);

const kingOfHearts = getCardValue("K♥");
assertEquals(kingOfHearts, 10);

// 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 tenOfSpades = getCardValue("10♠");
assertEquals(tenOfSpades, 10);

// 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 invalidRandomCard = getCardValue("15♠");
assertEquals(invalidRandomCard, "Invalid card rank.");

const oneOfSpades = getCardValue("1♠");
assertEquals(oneOfSpades, "Invalid card rank.");

const emptyCard = getCardValue("");
assertEquals(emptyCard, "Invalid card rank.");

Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,70 @@ const getAngleType = require("../implement/1-get-angle-type");

test("should identify right angle (90°)", () => {
expect(getAngleType(90)).toEqual("Right angle");
expect(getAngleType(90.0)).toEqual("Right angle");
});

// REPLACE the comments with the tests
// make your test descriptions as clear and readable as possible

// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// When the angle is greater than 0 degrees and less than 90 degrees,
// Then the function should return "Acute angle"
test("should identify acute angle (<90°)", () => {
expect(getAngleType(50)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89.999)).toEqual("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"
test("should identiify obtuse angle (>90° and <180°)", () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(120)).toEqual("Obtuse angle");
expect(getAngleType(179.999)).toEqual("Obtuse angle");
});

// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
test("should identify straight angle (180°)", () => {
expect(getAngleType(180)).toEqual("Straight angle");
expect(getAngleType(180.0)).toEqual("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"
test("should identify reflex angle (>180° and <360°)", () => {
expect(getAngleType(250)).toEqual("Reflex angle");
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359.999)).toEqual("Reflex angle");
});

// Case 6: Identify Full Rotation:
// When the angle is exactly 360 degrees,
// Then the function should return "Full rotation"
test("should identify full roatation angle 360°", () => {
expect(getAngleType(360)).toEqual("Full rotation");
});

// Case 7: Handle Invalid Angles:
// When the angle is negative or greater than 360 or any other data type
// Then the function should return "Invalid angle"
test("should return 'Invalid angle' for negative, >360, or non-numeric values", () => {
expect(getAngleType(-10)).toEqual("Invalid angle");
expect(getAngleType(400)).toEqual("Invalid angle");
expect(getAngleType("abc")).toEqual("Invalid angle");
expect(getAngleType(true)).toEqual("Invalid angle");
expect(getAngleType(null)).toEqual("Invalid angle");
expect(getAngleType(undefined)).toEqual("Invalid angle");
});

// Case 8: Identify Zero Angle:
// When the angle is exactly 0 degrees,
// Then the function should return "Zero angle"
test("should return 'Zero angle' when the input is 0", () => {
expect(getAngleType(0)).toEqual("Zero angle");
})
Loading