Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
5061ffe
feat: add conditional structure to check angles in the function
Grajales-K Feb 5, 2026
9b386e9
Merge branch 'CodeYourFuture:main' into coursework/sprint-3-implement…
Grajales-K Feb 13, 2026
9d4fb3c
testing a comment line
Grajales-K Feb 14, 2026
f9a510e
test: add assert casses to the helper to verify getAngleType logic an…
Grajales-K Feb 20, 2026
9207345
test: add cases for proper and improper fractions
Grajales-K Feb 20, 2026
468706d
test: enhance isProperFraction function with additional edge cases
Grajales-K Feb 23, 2026
8ebeba7
test: implement validation checks for card value and suit in getCardV…
Grajales-K Feb 23, 2026
2a5a3e9
test: add assertions and edge case tests for getCardValue function
Grajales-K Feb 23, 2026
91cf155
Co-authored-by: RahwaZeslusHaile <RahwaZeslusHaile@users.noreply.gith…
Grajales-K Feb 23, 2026
f49cc6f
fix: remove unnecessary line breaks in calculateBMI function
Grajales-K Feb 23, 2026
580d40f
test: refactor angle type tests for consistency and readability
Grajales-K Feb 23, 2026
b8ab592
test: enhance isProperFraction function to handle zero numerator and …
Grajales-K Feb 23, 2026
7d6cba2
test: expand isProperFraction tests to cover all edge cases and scena…
Grajales-K Feb 23, 2026
4bec805
test: rewrite and expand tests for getCardValue function with success…
Grajales-K Feb 24, 2026
477a236
refactor: remove the unnessary explanation code lines
Grajales-K Mar 4, 2026
c063baa
Refactor: removed boolean variables and implemented the includes() me…
Grajales-K Mar 4, 2026
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";
}
return "Invalid angle";

}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -25,13 +37,31 @@ module.exports = getAngleType;
// This helper function is written to make our assertions easier to read.
// If the actual output matches the target output, the test will pass
function assertEquals(actualOutput, targetOutput) {

console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
`❌ Error: expected ${actualOutput} to equal ${targetOutput}`
);

if (actualOutput === targetOutput) {
console.log(`✅ Test passed: ${actualOutput} equals ${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");
const acute = getAngleType(45);
assertEquals(acute, "Acute angle");
const obtuse = getAngleType(110);
assertEquals(obtuse, "Obtuse angle");
const straight = getAngleType(180);
assertEquals(straight, "Straight angle");
const reflex = getAngleType(240);
assertEquals(reflex, "Reflex angle");
const invalid = getAngleType(-10);
assertEquals(invalid, "Invalid angle");
console.log("✓ All test executed!");

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function

if(denominator === 0 || numerator === 0){
return false
}

if (numerator < 0) {
numerator = numerator * -1;
}

if (denominator < 0) {
denominator = denominator * -1;
}
return numerator < denominator;
}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand All @@ -30,4 +42,16 @@ function assertEquals(actualOutput, targetOutput) {
// What combinations of numerators and denominators should you test?

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(5, 9), true);
assertEquals(isProperFraction(3, 4), true);
assertEquals(isProperFraction(2, 8), true);
assertEquals(isProperFraction(1, 6), true);
assertEquals(isProperFraction(0, 5), true);
assertEquals(isProperFraction(-3, -5), true);



// Example: 3/2 is a improper fraction
assertEquals(isProperFraction(3, 0), false);
assertEquals(isProperFraction(-7, 5), false);
console.log("✓ All test executed!");
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,32 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
if (card.length < 2 || card.length > 3) {
throw new Error("Invalid card");
}
const suits = ["♠", "♥", "♦", "♣"];
const suit = card[card.length - 1];

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

let rank = card.substring(0, card.length - 1);

if (rank === "A") {
return 11;
}
if (rank === "J" || rank === "Q" || rank === "K") {
return 10;
}

let number = Number(rank);

if (isNaN(number) || number < 2 || number > 10) {
throw new Error("Invalid card rank");
}

return number;
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -31,22 +56,52 @@ module.exports = getCardValue;

// Helper functions to make our assertions easier to read.
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
if (actualOutput !== targetOutput) {
console.error(
`❌ FAILED: Expected ${targetOutput} but received ${actualOutput}`
);
} else {
console.log(`✅ PASSED: Value is ${actualOutput} as expected`);
}
}

function assertThrows(invalidCard) {
try {
getCardValue(invalidCard);
console.error(
`❌ FAILED: "${invalidCard}" should have thrown an error, but it didn't`
);
} catch (e) {
console.log(`✅ PASSED: Error catch para "${invalidCard}" [${e.message}]`);
}
}

// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
assertEquals(getCardValue("9♠"), 9);
console.log("--- Running Success Tests ---");
assertEquals(getCardValue("2♠"), 2);
assertEquals(getCardValue("10♥"), 10);
assertEquals(getCardValue("A♣"), 11);
assertEquals(getCardValue("K♦"), 10);
assertEquals(getCardValue("J♠"), 10);
assertEquals(getCardValue("Q♥"), 10);
assertEquals(getCardValue("7♦"), 7);

console.log("\n--- Running Edge Case Tests ---");
assertThrows("d");
assertThrows("15♥");
assertThrows("A");
assertThrows("JPP");
assertThrows("Q🌸");

// Handling invalid cards
try {
getCardValue("invalid");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card");
} catch (e) {}
} catch (e) {
console.log("✓ Error thrown as expected for invalid card");
}

// What other invalid card cases can you think of?
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,33 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// Case 2: Right angle
test(`should return "Right angle" when (angle = 90)`, () => {
expect(getAngleType(90)).toEqual("Right angle");
});

// Case 3: Obtuse angles
test(`Should return "Obtuse angle" when the (angle > 90 && angle < 180)`, () => {
expect(getAngleType(160)).toEqual("Obtuse angle");
expect(getAngleType(110)).toEqual("Obtuse angle");
expect(getAngleType(140)).toEqual("Obtuse angle");
});

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

// Case 5: Reflex angles
test('should return "Reflex angle" when (angle > 180 && angle < 360)', () => {
expect(getAngleType(181)).toBe("Reflex angle");
expect(getAngleType(270)).toBe("Reflex angle");
expect(getAngleType(300)).toBe("Reflex angle");
});

// Case 6: Invalid angles
test(`Should return "Invalid angle" when the input is invalid`, () => {
expect(getAngleType(0)).toEqual("Invalid angle");
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 @@ -4,7 +4,26 @@ 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);
// test: proper fraction
// --- case 1: Proper Fractions ---
test('should return true for valid proper fractions, including negative numbers', () => {
expect(isProperFraction(5, 9)).toBe(true);
expect(isProperFraction(3, 4)).toBe(true);
expect(isProperFraction(2, 8)).toBe(true);
expect(isProperFraction(1, 6)).toBe(true);
expect(isProperFraction(-3, -5)).toBe(true);
});

// --- case 2: Improper Fractions ---
test('should return false for improper fractions where numerator >= denominator', () => {
expect(isProperFraction(-7, 5)).toBe(false);
expect(isProperFraction(10, 3)).toBe(false);
expect(isProperFraction(5, 5)).toBe(false);
});

// --- case 3: 0 Numerator and 0 Denominator ---
test('should return false when numerator or denominator is zero', () => {
expect(isProperFraction(3, 0)).toBe(false);
expect(isProperFraction(0, 3)).toBe(false);
expect(isProperFraction(0, 0)).toBe(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ 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);
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
Expand All @@ -18,3 +13,43 @@ test(`Should return 11 when given an ace card`, () => {
// please refer to the Jest documentation:
// https://jestjs.io/docs/expect#tothrowerror

describe("getCardValue", () => {

// Group 1: success cases (Valid cards)
test("should return 11 when given an Ace (A)", () => {
expect(getCardValue("A♠")).toBe(11);
expect(getCardValue("A♥")).toBe(11);
});

test("should return 10 when given a face card (J, Q, K)", () => {
expect(getCardValue("J♣")).toBe(10);
expect(getCardValue("Q♦")).toBe(10);
expect(getCardValue("K♠")).toBe(10);
});

test("should return the numeric value for number cards (2-10)", () => {
expect(getCardValue("2♥")).toBe(2);
expect(getCardValue("7♦")).toBe(7);
expect(getCardValue("10♣")).toBe(10);
});

// Group 2: error cases (Invalid cards)
describe("Invalid cards", () => {
test("should throw an error for invalid card length or missing components", () => {
expect(() => getCardValue("A")).toThrow("Invalid card");
expect(() => getCardValue("100♥")).toThrow("Invalid card");
expect(() => getCardValue("")).toThrow("Invalid card");
});

test("should throw an error for an invalid suit emoji", () => {
expect(() => getCardValue("A🌸")).toThrow("Invalid card suit");
expect(() => getCardValue("10X")).toThrow("Invalid card suit");
});

test("should throw an error for an invalid rank", () => {
expect(() => getCardValue("1♥")).toThrow("Invalid card rank");
expect(() => getCardValue("15♦")).toThrow("Invalid card rank");
expect(() => getCardValue("Z♠")).toThrow("Invalid card rank");
});
});
});