Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
ce76c0b
add empty lines for better readability in angle type tests
MattCarolus10 Oct 8, 2026
eb2d17d
implement getAngleType function to return "Right angle" for 90°
MattCarolus10 Oct 8, 2026
56c856c
add test case for classifying acute angles in getAngleType function
MattCarolus10 Oct 8, 2026
2e4e5e1
implement getAngleType function to return "Acute angle" for angles be…
MattCarolus10 Oct 8, 2026
fd1f878
add test case for classifying obtuse angles in getAngleType function
MattCarolus10 Oct 8, 2026
67bf79b
implement getAngleType function to return "Obtuse angle" for angles b…
MattCarolus10 Oct 8, 2026
b1a6630
add test case for classifying straight angles in getAngleType function
MattCarolus10 Oct 8, 2026
db4a27e
fix: correct expected output for straight angle classification test
MattCarolus10 Oct 8, 2026
7e8ad2f
fix: return "Straight angle" for angle equal to 180°
MattCarolus10 Oct 8, 2026
eeb2846
add test case for classifying reflex angles in getAngleType function
MattCarolus10 Oct 8, 2026
1807a2d
fix: add missing semicolons in getAngleType function
MattCarolus10 Oct 8, 2026
ad85b14
fix: add missing semicolons and correct test syntax in angle classifi…
MattCarolus10 Oct 8, 2026
325a7ee
fix: add missing semicolons and format test cases in angle classifica…
MattCarolus10 Oct 8, 2026
2d57566
fix: update invalid angle classification in getAngleType function
MattCarolus10 Oct 8, 2026
69af44c
fix: update invalid angle test case in getAngleType function
MattCarolus10 Oct 8, 2026
3eb0813
feat: implement isProperFraction function to evaluate proper fractions
MattCarolus10 Oct 8, 2026
41d025e
fix: correct isProperFraction logic to return boolean values
MattCarolus10 Oct 8, 2026
115eb01
fix: correct assertion in isProperFraction test to match expected boo…
MattCarolus10 Oct 8, 2026
e029b5a
fix: correct return value in isProperFraction function to return bool…
MattCarolus10 Oct 8, 2026
55d9b0f
fix: return boolean true in isProperFraction function instead of string
MattCarolus10 Oct 8, 2026
09732da
fix: update isProperFraction logic to correctly evaluate proper fract…
MattCarolus10 Oct 8, 2026
268b7e4
test: add assertion for improper fraction case in isProperFraction test
MattCarolus10 Oct 8, 2026
f02a167
test: add additional test cases for isProperFraction function
MattCarolus10 Oct 8, 2026
f423445
test: add assertion for negative numerator case in isProperFraction test
MattCarolus10 Oct 8, 2026
3f5bc58
test: add assertion for negative denominator case in isProperFraction…
MattCarolus10 Oct 8, 2026
388bb92
fix: refine isProperFraction logic to handle negative numerator and d…
MattCarolus10 Oct 8, 2026
addec7e
refactor: remove unnecessary blank line in isProperFraction test
MattCarolus10 Oct 8, 2026
7b32fd3
refactor: improve formatting and consistency in isProperFraction func…
MattCarolus10 Oct 8, 2026
3007cee
refactor: remove unnecessary comments from isProperFraction implement…
MattCarolus10 Oct 8, 2026
7335f61
refactor: remove TODO comments from isProperFraction test file
MattCarolus10 Oct 8, 2026
fd4c2d8
refactor: comment out unused test cases and implement basic getCardVa…
MattCarolus10 Oct 9, 2026
3ff46c7
refactor: uncomment valid single-digit card test in getCardValue test…
MattCarolus10 Oct 9, 2026
9f20280
refactor: fix getCardValue function to return numeric value for numbe…
MattCarolus10 Oct 9, 2026
92c9dd3
refactor: add test for face cards to return correct value
MattCarolus10 Oct 9, 2026
08a8dac
refactor: fix face card test cases to use correct syntax for getCardV…
MattCarolus10 Oct 9, 2026
5422d78
refactor: fix formatting and structure in getCardValue function for c…
MattCarolus10 Oct 9, 2026
ab0f20e
refactor: uncomment test for arbitrary non-card string and enhance er…
MattCarolus10 Oct 9, 2026
0ac8992
refactor: add newline at the end of 3-get-card-value.js for consistency
MattCarolus10 Oct 9, 2026
9546060
refactor: clean up comments and improve formatting in getCardValue fu…
MattCarolus10 Oct 9, 2026
310b716
refactor: remove TODO comments and improve formatting in test cases f…
MattCarolus10 Oct 9, 2026
cd6cf1e
refactor: add additional test cases for card value validation and err…
MattCarolus10 Oct 9, 2026
c08bc7b
refactor: add test case for handling extra characters in card input
MattCarolus10 Oct 9, 2026
23f8f8d
refactor: improve formatting in missing or broken suit test cases
MattCarolus10 Oct 9, 2026
732e5ac
refactor: ensure rank is consistently uppercased in getCardValue func…
MattCarolus10 Oct 9, 2026
3b3d156
refactor: fix syntax in test case for handling extra characters in ca…
MattCarolus10 Oct 9, 2026
cdb038b
refactor: fix syntax error in test case for handling extra characters…
MattCarolus10 Oct 9, 2026
5d45a20
refactor: fix syntax error in test case for adding junk characters to…
MattCarolus10 Oct 9, 2026
362a572
refactor: add test case for right angle in getAngleType function
MattCarolus10 Oct 9, 2026
34bd7f8
refactor: add test case for obtuse angles in getAngleType function
MattCarolus10 Oct 9, 2026
068bdef
refactor: add test case for straight angle in getAngleType function
MattCarolus10 Oct 9, 2026
2c43396
refactor: add tests for reflex and invalid angles in getAngleType fun…
MattCarolus10 Oct 9, 2026
d478206
refactor: add additional test cases for invalid angles in getAngleTyp…
MattCarolus10 Oct 9, 2026
94d3efb
refactor: remove unnecessary whitespace in getAngleType test file
MattCarolus10 Oct 9, 2026
a9c25bf
refactor: remove commented-out cases in getAngleType test file
MattCarolus10 Oct 9, 2026
0297184
refactor: clean up whitespace and comments in getAngleType test file
MattCarolus10 Oct 9, 2026
a4aed0f
test: add test case for negative denominator in isProperFraction func…
MattCarolus10 Oct 9, 2026
9249f9a
test: add test case for valid denominator in isProperFraction function
MattCarolus10 Oct 9, 2026
c96b8e8
test: add test case for zero numerator in isProperFraction function
MattCarolus10 Oct 9, 2026
71fad68
test: add test case for equality of numerator and denominator in isPr…
MattCarolus10 Oct 9, 2026
bc356fb
test: clarify test description for proper fraction denominator compar…
MattCarolus10 Oct 9, 2026
02239f4
fix: ensure proper fraction logic handles equality of numerator and d…
MattCarolus10 Oct 9, 2026
32e11b4
test: add test case for face cards "J", "Q", and "K" in getCardValue …
MattCarolus10 Oct 9, 2026
84c10da
test: add additional test case for Number cards in getCardValue function
MattCarolus10 Oct 9, 2026
b78ad1b
fix: correct syntax by closing the Number card test case
MattCarolus10 Oct 9, 2026
91c33aa
test: add additional test case for invalid cards in getCardValue func…
MattCarolus10 Oct 9, 2026
2f56990
fix: remove redundant invalid card tests in getCardValue function
MattCarolus10 Oct 9, 2026
845c0d9
test: add test case to verify countChar returns 0 for non-existent ch…
MattCarolus10 Oct 9, 2026
10fd986
fix: implement countChar function to accurately count occurrences of …
MattCarolus10 Oct 9, 2026
9693c4b
test: add test cases for numbers ending with 2 in getOrdinalNumber fu…
MattCarolus10 Oct 9, 2026
3ad4ad1
test: add test cases for numbers ending with 3 in getOrdinalNumber fu…
MattCarolus10 Oct 9, 2026
ba47123
test: fix formatting in getOrdinalNumber test cases and add missing t…
MattCarolus10 Oct 9, 2026
fa8c3b8
fix: update getOrdinalNumber function to correctly calculate ordinal …
MattCarolus10 Oct 9, 2026
c01df9b
fix: correct logic in getOrdinalNumber function to handle ordinal suf…
MattCarolus10 Oct 9, 2026
b4e1243
fix: correct variable name in getOrdinalNumber function to ensure pro…
MattCarolus10 Oct 9, 2026
f84d7a0
fix: remove unnecessary console.log and ensure proper formatting in g…
MattCarolus10 Oct 9, 2026
2d138e0
fix: correct return value for ordinal suffix of 1 in getOrdinalNumber…
MattCarolus10 Oct 9, 2026
9dff0ae
fix: update return values in getOrdinalNumber function to use dynamic…
MattCarolus10 Oct 9, 2026
183aacc
test: add test case for repeating the string one time in repeatStr fu…
MattCarolus10 Oct 9, 2026
42606b6
test: add test case for returning an empty string when count is 0 in …
MattCarolus10 Oct 9, 2026
09bf246
test: add case to handle negative integer input in repeatStr function
MattCarolus10 Oct 9, 2026
2b76b09
fix: implement repeatStr function with error handling for negative co…
MattCarolus10 Oct 9, 2026
32c195a
fix: implement repeatStr function to return repeated string based on …
MattCarolus10 Oct 9, 2026
171b264
refactor: remove redundant comments from repeatStr test cases
MattCarolus10 Oct 9, 2026
a4b8f77
refactor: remove redundant comments from getOrdinalNumber test file
MattCarolus10 Oct 9, 2026
b7bd710
refactor: remove redundant comments from countChar test file
MattCarolus10 Oct 9, 2026
5de7ae0
refactor: remove TODO comments and suggestions from getCardValue test…
MattCarolus10 Oct 9, 2026
a2cb8ad
refactor: remove TODO comment and clean up test formatting in isPrope…
MattCarolus10 Oct 9, 2026
f97fa01
refactor: remove TODO comments and clean up test cases in getAngleTyp…
MattCarolus10 Oct 9, 2026
208e10a
refactor: remove TODO comments from getAngleType test file
MattCarolus10 Oct 9, 2026
a13105a
refactor: remove unnecessary comments from getAngleType function
MattCarolus10 Oct 9, 2026
d8e8974
refactor: add test case for password containing at least one uppercas…
MattCarolus10 Oct 10, 2026
8b50775
refactor: add test case for password containing at least one lowercas…
MattCarolus10 Oct 10, 2026
34edfce
refactor: add test case for password containing at least one number
MattCarolus10 Oct 10, 2026
a0fc1e8
refactor: add test case for password containing at least one special …
MattCarolus10 Oct 10, 2026
4b5f2f7
refactor: clean up test case formatting for password validation
MattCarolus10 Oct 10, 2026
88908c7
refactor: add test case to ensure password is not a previous password
MattCarolus10 Oct 10, 2026
36105df
refactor: update isValidPassword function to accept an additional par…
MattCarolus10 Oct 10, 2026
5337940
refactor: fix isValidPassword function to correctly check for previou…
MattCarolus10 Oct 10, 2026
8849988
refactor: fix parameter name in isValidPassword function for clarity
MattCarolus10 Oct 10, 2026
570fb97
refactor: fix condition in isValidPassword function to check against …
MattCarolus10 Oct 10, 2026
3cabf33
refactor: improve readability by adjusting whitespace in isValidPassw…
MattCarolus10 Oct 10, 2026
7fec32a
refactor: fix formatting issues in isValidPassword function for consi…
MattCarolus10 Oct 10, 2026
79e90d0
remove password validator stretch exercise
MattCarolus10 Oct 10, 2026
0bfe696
reset practice-tdd to main starter files
MattCarolus10 Oct 10, 2026
1732a61
restore sprint-3-stretch-exercises from main
MattCarolus10 Oct 10, 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 @@ -3,10 +3,38 @@ import test from "node:test";

import { getAngleType } from "../implement/1-get-angle-type.js";

// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles

test("Classifies right angles", () => {

const right = getAngleType(90);
assert.equal(right, "Right angle");
});

test("Classifies acute angles", () =>{

const acute = getAngleType(45);
assert.equal(acute, "Acute angle");
});

test("Classifies obtuse angle", () => {

const obtuse = getAngleType(140);
assert.equal(obtuse, "Obtuse angle");
});

test("Classifies straight angle", () => {

const straight = getAngleType(180);
assert.equal(straight, "Straight angle");
});

test("Classifies reflex angle", () => {

const reflex = getAngleType(250);
assert.equal(reflex, "Reflex angle");
});

test("Classifies invalid angle", () => {

assert.equal(getAngleType("-1"), "Invalid angle");
assert.equal(getAngleType("365"), "Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import test from "node:test";

import { isProperFraction } from "../implement/2-is-proper-fraction.js";

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

test("Basic proper fraction", () => {
// Example: 1/2 is a proper fraction
assert.equal(isProperFraction(1, 2), true);
assert.equal(isProperFraction(2, 1), false);
assert.equal(isProperFraction(-2, 1), true);
assert.equal(isProperFraction(1, -2), false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,54 @@ import test from "node:test";

import { getCardValue } from "../implement/3-get-card-value.js";

// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.

test("Valid single-digit card", () => {
assert.equal(getCardValue("9♠"), 9);
});

test("Ace card returns 11", () => {
assert.equal(getCardValue("A♠"), 11);
});

test("Face cards returns 10", () => {
assert.equal(getCardValue("J♣"), 10);
assert.equal(getCardValue("Q♦"), 10);
assert.equal(getCardValue("K♥"), 10);
});
test("Arbitrary non-card string", () => {
assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error");
assert.throws(
() => getCardValue("invalid"),
/Expected a number followed by a suit, but got "invalid"/,
"Expected clear error"
);
});

test("Negative values string", () => {
assert.throws(
() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/,
"Expected clear error"
);
});

test("Lowercase ranks", () => {
assert.equal(getCardValue("a♦"), 11);
assert.equal(getCardValue("j♦"), 10);
});

test("Missing or broken suit", () => {
assert.throws(
() => (getCardValue("9")), /Expected/
);
assert.throws(
() => (getCardValue("")), /Expected/
);
});

test("Two digit rank", () => {
assert.equal(getCardValue("10♦"), 10);
});

test("Adding junks with extra character", () => {
() => assert.throws(getCardValue("9♦y"), /Expected/
);
});

// TODO: What other invalid card cases can you think of?
37 changes: 19 additions & 18 deletions implement-and-rewrite-tests/implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
// Implement a function getAngleType
//
// Don't forget to write tests in implement-tests-with-node-test.
//
// When given an angle in degrees, it should return a string indicating the type of angle:
// - "Acute angle" for angles greater than 0° and less than 90°
// - "Right angle" for exactly 90°
// - "Obtuse angle" for angles greater than 90° and less than 180°
// - "Straight angle" for exactly 180°
// - "Reflex angle" for angles greater than 180° and less than 360°
// - "Invalid angle" for angles outside the valid range.
export function getAngleType(angle){
if (angle === 90){
return "Right angle";
}
if (angle > 0 && 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";
} else
return "Invalid angle"
}


// Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.)

// Acceptance criteria:
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

export function getAngleType(angle) {
// TODO: Implement this function
}
31 changes: 15 additions & 16 deletions implement-and-rewrite-tests/implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// Implement a function isProperFraction,
//
// Don't forget to write tests in implement-tests-with-node-test.
//
// When given two numbers, a numerator and a denominator, it should return true if
// the given numbers form a proper fraction, and false otherwise.

// Assumption: The parameters are valid numbers (not NaN or Infinity).

// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition.

// Acceptance criteria:
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

export function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (numerator < denominator) {
return true;
}
if (numerator > denominator) {
return false;
}
if (numerator === denominator){
return false
}
if (-numerator < denominator) {
return true;
}
if (numerator > -denominator) {
return false;
}
}
54 changes: 30 additions & 24 deletions implement-and-rewrite-tests/implement/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck

// Don't forget to write tests in implement-tests-with-node-test.

// Implement a function getCardValue, when given a string representing a playing card,
// should return the numerical value of the card.

// A valid card string will contain a rank followed by the suit.
// The rank can be one of the following strings:
// "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"
// The suit can be one of the following emojis:
// "♠", "♥", "♦", "♣"
// For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦".
export function getCardValue(card) {
const suit = card.slice(-1);
const rank = card.slice(0, -1).toUpperCase();

// When the card is an ace ("A"), the function should return 11.
// When the card is a face card ("J", "Q", "K"), the function should return 10.
// When the card is a number card ("2" to "10"), the function should return its numeric value.
const validSuit = ["♠", "♥", "♦", "♣"];
const validRank = [
"A",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
];

// When the card string is invalid (not following the above format), the function should
// throw an error.
if (!validSuit.includes(suit) || !validRank.includes(rank)) {
throw new Error(`Expected a number followed by a suit, but got "${card}"`);
}
if (rank === "A") {
return 11;
}
if (rank === "J" || rank === "Q" || rank === "K") {
return 10;
}
return Number(rank);
}

// Acceptance criteria:
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

export function getCardValue(card) {
// TODO: Implement this function
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import { getAngleType } from "../implement/1-get-angle-type.js";

// 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
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});

// Case 2: Right angle
// Case 3: Obtuse angles
// Case 4: Straight angle
// Case 5: Reflex angles
// Case 6: Invalid angles
test(`Should return "Right angle" when (angle === 90)`, () => {
expect(getAngleType(90)).toEqual("Right angle");
});

test(`Should return "Obtuse Angle" when (angle > 90 and angle < 180)`, () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(120)).toEqual("Obtuse angle");
expect(getAngleType(170)).toEqual("Obtuse angle");
});

test(`Should return "Straight angle" when (angle === 180)`, () => {
expect(getAngleType(180)).toEqual("Straight angle");
});

test(`Should return "Reflex angle" when (angle > 180 and angle < 360)`, () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(195)).toEqual("Reflex angle");
expect(getAngleType(290)).toEqual("Reflex angle");
});

test(`Should return "Invalid angle when (angle < 0 and angle > 360)`, () => {
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(361)).toEqual("Invalid angle");
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import { isProperFraction } from "../implement/2-is-proper-fraction.js";

// 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(`Should return false when denominator is negative`, () => {
expect(isProperFraction(1, -2)).toEqual(false);
});

test(`Should return true when denominator is > numerator`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

test(`Should return true when numerator is zero`, () => {
expect(isProperFraction(0, 4)).toEqual(true);
});

test(`Should return false when numerator === denominator`, () => {
expect(isProperFraction(5, 5)).toEqual(false);
});
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import { getCardValue } from "../implement/3-get-card-value.js";

// 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)
// Invalid Cards
test(`Should return 10 when given "J" "Q" "K" face card`, () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q♥")).toEqual(10);
expect(getCardValue("K♣")).toEqual(10);
});

// 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
test(`Should return 2 to 10 when given Number card`, () => {
expect(getCardValue("2♣")).toEqual(2);
expect(getCardValue("5♥")).toEqual(5);
expect(getCardValue("8♠")).toEqual(8);
});

test(`Should throw error when given invalid card`, () => {
expect(() => getCardValue("x♣")).toThrow();
expect(() => getCardValue("1♥1")).toThrow();
expect(() => getCardValue("b♣")).toThrow();
expect(() => getCardValue("k♦j")).toThrow();
expect(() => getCardValue("")).toThrow();
expect(() => getCardValue("9")).toThrow();
expect(() => getCardValue("-8♦")).toThrow();
});
Loading