Skip to content

London | 25-ITP-May | Hendrine Zeraua | Sprint 3 | Structuring and Testing Data #661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6661734
Implement getAngleType function with unit tests for all angle cases
rarityXtreme Jul 15, 2025
ec17037
Add isProperFraction function and assertions for valid, invalid, and …
rarityXtreme Jul 15, 2025
d009f8c
Implement getCardValue function with tests
rarityXtreme Jul 15, 2025
9d54264
added completed getAngleType function from Key-implement exercise
rarityXtreme Jul 16, 2025
9f0f339
Add Jest tests for getAngleType function
rarityXtreme Jul 16, 2025
313cab7
add isProperFraction from key- Implement
rarityXtreme Jul 16, 2025
511f37e
Add edge case tests for isProperFraction function
rarityXtreme Jul 16, 2025
0dbe430
add function getCardValue from key-implement
rarityXtreme Jul 16, 2025
3c1595e
Add tests for getCardValue including edge cases and errors
rarityXtreme Jul 16, 2025
4f1c3fc
Implement countChar function
rarityXtreme Jul 16, 2025
ded4991
add test cases for countChar function
rarityXtreme Jul 16, 2025
18f5c89
implement getOrdinalNumber with suffix rules
rarityXtreme Jul 16, 2025
9865786
add test cases for getOrdinalNumber including exceptions
rarityXtreme Jul 16, 2025
d8530a7
implement repeat function with validation
rarityXtreme Jul 16, 2025
5a453cc
add test cases for repeat function including edge cases
rarityXtreme Jul 16, 2025
74254e9
implement credit card validator function
rarityXtreme Jul 16, 2025
a93be32
add Jest tests for credit card validator
rarityXtreme Jul 16, 2025
ea002b3
add while loop character finder with explanatory comments
rarityXtreme Jul 16, 2025
ceb0b9d
add passwordValidator function with full rule checks
rarityXtreme Jul 16, 2025
63ac7a2
add test cases for passwordValidator function
rarityXtreme Jul 16, 2025
927294c
amend getAngleType function to handle invalid inputs and improve test…
rarityXtreme Jul 18, 2025
7981a13
tightened card rank checks and added edge case tests
rarityXtreme Jul 18, 2025
b077682
group ordinal number tests by suffix categories for full coverage
rarityXtreme Jul 18, 2025
35f5500
group valid credit card tests into a single case
rarityXtreme Jul 18, 2025
b6b8a27
clarify ordinal test description for numbers ending in 0 or 4–9
rarityXtreme Jul 18, 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
24 changes: 24 additions & 0 deletions Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@
// Write the code to pass the test
// Then, write the next test! :) Go through this process until all the cases are implemented

// getAngleType function:
// This function takes an angle in degrees and returns the type of angle.
// I implemented 5 cases: Right, Acute, Obtuse, Straight, and Reflex angles.
// I used conditional statements (if) to check the angle's value range.

function getAngleType(angle) {
if (angle === 90) return "Right angle";
if (angle < 90) return "Acute angle";
if (angle > 90 && angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
if (angle > 180 && angle < 360) return "Reflex angle";

// read to the end, complete line 36, then pass your test here
}

// we're going to use this helper function to make our assertions easier to read
// if the actual output matches the target output, the test will pass

// assertEquals:
// This helper function is used to check if the output from getAngleType
// matches the expected value. If not, it shows an error in the terminal.
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
Expand All @@ -27,6 +41,10 @@ function assertEquals(actualOutput, targetOutput) {
// When the function getAngleType is called with this angle,
// Then it should:


// Tests for getAngleType:
// Each test checks one angle type and helps confirm my function is working.

// Case 1: Identify Right Angles:
// When the angle is exactly 90 degrees,
// Then the function should return "Right angle"
Expand All @@ -43,14 +61,20 @@ assertEquals(acute, "Acute angle");
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
assertEquals(obtuse, "Obtuse angle");

// ====> write your test here, and then add a line to pass the test in the function above

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

// 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"
const reflex = getAngleType(210);
assertEquals(reflex, "Reflex angle");
// ====> write your test here, and then add a line to pass the test in the function above
25 changes: 24 additions & 1 deletion Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (denominator === 0) return false;
return Math.abs(numerator) < Math.abs(denominator);
}

// here's our helper again
Expand Down Expand Up @@ -40,14 +41,36 @@ assertEquals(improperFraction, false);
// 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);
assertEquals(negativeFraction, true);

// ====> complete with your assertion

// 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);
assertEquals(equalFraction, false)
// ====> complete with your assertion

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

// Zero numerator
// 0/5 → true (0 is less than any non-zero number)
const zeroNumerator = isProperFraction(0, 5);
assertEquals(zeroNumerator, true);

// Negative denominator
// 3/-4 → true
const negativeDenominator = isProperFraction(3, -4);
assertEquals(negativeDenominator, true);

// Negative improper fraction
// -5/4 → false
const negativeImproper = isProperFraction(-5, 4);
assertEquals(negativeImproper, false);

// Zero denominator (invalid)
const zeroDenominator = isProperFraction(1, 0);
assertEquals(zeroDenominator, false);
34 changes: 32 additions & 2 deletions Sprint-3/1-key-implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,27 @@
// 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) {
if (rank === "A") return 11;
const rank = card.slice(0, -1);

if (rank === "A") return 11;

const numericRank = parseInt(rank);
if (!isNaN(numericRank) && numericRank >= 2 && numericRank <= 10) {
return numericRank;
}

if (["J", "Q", "K"].includes(rank)) {
return 10;
}

throw new Error("Invalid card rank.");
}

function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

// You need to write assertions for your function to check it works in different cases
Expand All @@ -33,19 +53,29 @@ assertEquals(aceofSpades, 11);
// 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♥");
assertEquals(fiveofHearts, 5)
// ====> write your test here, and then add a line to pass the test in the function above

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

// 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 aceofSpades = getCardValue("A♠");
assertEquals(aceofSpades, 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."
try {
getCardValue("Z♣");
console.error("Test failed: Expected error for invalid card rank");
} catch (e) {
assertEquals(e.message, "Invalid card rank.");
}
13 changes: 9 additions & 4 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement

}
if (typeof angle !== 'number' || isNaN(angle) || angle <= 0 || angle >= 360) {
return "Invalid angle";
}


if (angle < 90) return "Acute angle";
if (angle === 90) return "Right angle";
if (angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
if (angle < 360) return "Reflex angle";
}



Expand Down
67 changes: 65 additions & 2 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const getAngleType = require("./1-get-angle-type");

test("should identify right angle (90°)", () => {
expect(getAngleType(90)).toEqual("Right angle");
test('returns "Right angle" for angle equal to 90', () => {
expect(getAngleType(90)).toBe("Right angle");
});

// REPLACE the comments with the tests
Expand All @@ -10,15 +10,78 @@ test("should identify right angle (90°)", () => {
// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"
test('returns "Acute angle" for angles less than 90', () => {
expect(getAngleType(45)).toBe("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('returns "Obtuse angle" for angles between 90 and 180', () => {
expect(getAngleType(120)).toBe("Obtuse angle");
});

// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
test('returns "Straight angle" for angle equal to 180', () => {
expect(getAngleType(180)).toBe("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('returns "Reflex angle" for angles between 180 and 360', () => {
expect(getAngleType(270)).toBe("Reflex angle");
});
// Case 6: Handle Invalid Angles
// When the angle is less than or equal to 0,
// Or when the angle is 360 or greater,
// Or when the input is not a number,
// Then the function should return "Invalid angle"
test("returns 'Invalid angle' when angle is 0", () => {
expect(getAngleType(0)).toBe("Invalid angle");
});

test("returns 'Invalid angle' when angle is negative", () => {
expect(getAngleType(-45)).toBe("Invalid angle");
});

test("returns 'Invalid angle' when angle is exactly 360", () => {
expect(getAngleType(360)).toBe("Invalid angle");
});

test("returns 'Invalid angle' when angle is greater than 360", () => {
expect(getAngleType(400)).toBe("Invalid angle");
});

test("returns 'Invalid angle' when input is a string", () => {
expect(getAngleType("90")).toBe("Invalid angle");
});

test("returns 'Invalid angle' when input is null", () => {
expect(getAngleType(null)).toBe("Invalid angle");
});

test("returns 'Invalid angle' when input is undefined", () => {
expect(getAngleType(undefined)).toBe("Invalid angle");
});

test("returns 'Invalid angle' when input is NaN", () => {
expect(getAngleType(NaN)).toBe("Invalid angle");
});














8 changes: 5 additions & 3 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
}
if (denominator === 0) return false;
return Math.abs(numerator) < Math.abs(denominator);
}


module.exports = isProperFraction;
27 changes: 27 additions & 0 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,34 @@ test("should return true for a proper fraction", () => {
});

// Case 2: Identify Improper Fractions:
test("returns false for improper fraction (5/2)", () => {
expect(isProperFraction(5, 2)).toBe(false);
});


// Case 3: Identify Negative Fractions:
test("returns true for negative proper fraction (-4/7)", () => {
expect(isProperFraction(-4, 7)).toBe(true);
});


// Case 4: Identify Equal Numerator and Denominator:

test("returns false for equal numerator and denominator (3/3)", () => {
expect(isProperFraction(3, 3)).toBe(false);
});
// Zero numerator
test("returns true when numerator is 0 and denominator is non-zero", () => {
expect(isProperFraction(0, 5)).toBe(true);
expect(isProperFraction(0, -5)).toBe(true);
});
// Zero denominator
test("returns false when denominator is 0", () => {
expect(isProperFraction(1, 0)).toBe(false);
expect(isProperFraction(0, 0)).toBe(false);
});
// Negative denominator
test("handles negative denominators correctly", () => {
expect(isProperFraction(2, -3)).toBe(true);
expect(isProperFraction(-4, -5)).toBe(true);
});
18 changes: 15 additions & 3 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;
const rank = card.slice(0, -1);
const validNumberRanks = ["2", "3", "4", "5", "6", "7", "8", "9", "10"];

if (rank === "A") return 11;

if (validNumberRanks.includes(rank)) {
return Number(rank);
}

if (["J", "Q", "K"].includes(rank)) return 10;

throw new Error("Invalid card rank.");
}
module.exports = getCardValue;

module.exports = getCardValue;

41 changes: 36 additions & 5 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
const getCardValue = require("./3-get-card-value");

// Handle Ace
test("should return 11 for Ace of Spades", () => {
const aceofSpades = getCardValue("A♠");
expect(aceofSpades).toEqual(11);
});
const aceofSpades = getCardValue("A♠");
expect(aceofSpades).toEqual(11);
});

// Case 2: Handle Number Cards (2-10):
test("should return numeric value for number cards", () => {
expect(getCardValue("2♦")).toEqual(2);
expect(getCardValue("10♥")).toEqual(10);
expect(getCardValue("7♣")).toEqual(7);
});

// Case 3: Handle Face Cards (J, Q, K):
// Case 4: Handle Ace (A):
test("should return 10 for Jack, Queen, and King", () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q♥")).toEqual(10);
expect(getCardValue("K♦")).toEqual(10);
});

// Case 4: Handle Ace Again(A):
test("should return 11 for Ace of Hearts", () => {
expect(getCardValue("A♥")).toEqual(11);
});

// Case 5: Handle Invalid Cards:
test("should throw an error for invalid card ranks", () => {
expect(() => getCardValue("1♠")).toThrow("Invalid card rank.");
expect(() => getCardValue("Z♣")).toThrow("Invalid card rank.");
expect(() => getCardValue("11♦")).toThrow("Invalid card rank.");
expect(() => getCardValue("")).toThrow("Invalid card rank.");
});

// Case 6: Handle malformed numeric inputs that parseInt would misinterpret
test("should throw an error for malformed numeric ranks", () => {
expect(() => getCardValue("0x02♠")).toThrow("Invalid card rank.");
expect(() => getCardValue("2.1♠")).toThrow("Invalid card rank.");
expect(() => getCardValue("0002♠")).toThrow("Invalid card rank.");
expect(() => getCardValue("2ABC♠")).toThrow("Invalid card rank.");
});

Loading