Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
97d02c7
get angle case2
enjoy15 Oct 13, 2025
bf6c370
case3 update
enjoy15 Oct 13, 2025
1a47995
update case 4
enjoy15 Oct 13, 2025
3be3bfb
update case 5
enjoy15 Oct 13, 2025
a7b7c2f
2-fraction/case2
enjoy15 Oct 13, 2025
e110722
2-is-proper-fraction update case
enjoy15 Oct 13, 2025
716f047
10 card case
enjoy15 Oct 13, 2025
138843b
10 card case
enjoy15 Oct 13, 2025
4879aaa
Ace card
enjoy15 Oct 13, 2025
d34d343
undefined case
enjoy15 Oct 13, 2025
4d61885
1 rewrite test with jest
enjoy15 Oct 13, 2025
989855e
2-is proper-fraction test with jest
enjoy15 Oct 13, 2025
56625ec
3-get card value test with jest
enjoy15 Oct 13, 2025
47e385f
2-practice-tdd/count test
enjoy15 Oct 14, 2025
45dc764
2-practice-tdd/repeat test
enjoy15 Oct 14, 2025
00e6c6d
2-practice-tdd/get ordinal number test
enjoy15 Oct 14, 2025
35b6637
Merge branch 'coursework/sprint-3-practice-tdd' into coursework/sprin…
enjoy15 Oct 15, 2025
eb1d90f
Remove checking for angle > 90
enjoy15 Oct 25, 2025
2f42a85
convert negative numbers to positive before comparing
enjoy15 Oct 25, 2025
6db1bca
Change test result to true for -2/3
enjoy15 Oct 25, 2025
8f61c0f
Change function getCardValue to use Number instead
enjoy15 Oct 25, 2025
0e834a6
Add more tests
enjoy15 Oct 25, 2025
f14ec50
Group tests together
enjoy15 Oct 25, 2025
24bc0d7
Update comment ".. to numbers ending in 0, 4-9."
enjoy15 Oct 26, 2025
338eadc
Amend Function call with negative parameters
enjoy15 Oct 26, 2025
36e1138
validate string value before converting its value
enjoy15 Oct 26, 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 @@ -16,7 +16,7 @@ function getAngleType(angle) {
return "Acute angle";
}
// Then keep going for the other cases, one at a time.
if (angle > 90 && angle < 180) {
if (angle < 180) {
return "Obtuse angle";
}
if (angle === 180) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
// First check: both numerator and denominator should be positive
if (numerator < 0 || denominator < 0) {
return false;
}

// First check: convert negative numbers to positive before comparing
numerator = Math.abs(numerator);
denominator = Math.abs(denominator);
// Second check: numerator should be less than denominator
if (numerator < denominator) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ function getCardValue(card) {
return 11;
}

const numValue = parseInt(rank, 10);
if (numValue >= 2 && numValue <= 10) {
return numValue;
}
const numeric = Number(rank);
if (Number.isInteger(numeric) && numeric >= 2 && numeric <= 10) {
return numeric;
}

if (rank === "J" || rank === "Q" || rank === "K") {
return 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test("should return false for an improper fraction", () => {

// Case 3: Identify Negative Fractions:
test("should return false for a negative fraction", () => {
expect(isProperFraction(-2, 3)).toEqual(false);
expect(isProperFraction(-2, 3)).toEqual(true);
});

// Case 4: Identify Equal Numerator and Denominator:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,34 @@ test("should return undefined for invalid cards", () => {
const invalidCard = getCardValue("1♠");
expect(invalidCard).toEqual(undefined);
});

test("should return correct value for all number cards 2-10", () => {
expect(getCardValue("2♥")).toEqual(2);
expect(getCardValue("3♣")).toEqual(3);
expect(getCardValue("4♦")).toEqual(4);
expect(getCardValue("5♠")).toEqual(5);
expect(getCardValue("6♥")).toEqual(6);
expect(getCardValue("7♣")).toEqual(7);
expect(getCardValue("8♦")).toEqual(8);
expect(getCardValue("9♠")).toEqual(9);
expect(getCardValue("10♥")).toEqual(10);
});

test("should handle numeric-literal edge cases", () => {
expect(getCardValue("0x02♠")).toEqual(2);
expect(getCardValue("2.1♠")).toBeUndefined();
expect(getCardValue("0002♠")).toEqual(2);
});

test("should return 10 for all face cards", () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q♥")).toEqual(10);
expect(getCardValue("K♣")).toEqual(10);
});

test("should return 11 for all Aces", () => {
expect(getCardValue("A♠")).toEqual(11);
expect(getCardValue("A♥")).toEqual(11);
expect(getCardValue("A♦")).toEqual(11);
expect(getCardValue("A♣")).toEqual(11);
});
113 changes: 24 additions & 89 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,45 @@
const getOrdinalNumber = require("./get-ordinal-number");
// In this week's prep, we started implementing getOrdinalNumber

// continue testing and implementing getOrdinalNumber for additional cases
// Write your tests using Jest - remember to run your tests often for continual feedback
const getOrdinalNumber = require("./get-ordinal-number");

// Case 1: Identify the ordinal number for 1
// When the number is 1,
// Then the function should return "1st"
// To ensure thorough testing, we need broad scenario coverage. Listing individual values, however, can quickly lead to an unmanageable number of test cases.
// Instead of writing tests for individual numbers, we group all possible input values into meaningful categories and select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain.

test("should return '1st' for 1", () => {
// Numbers ending in 1 (except those ending in 11): should append 'st'
test("append 'st' to numbers ending in 1, except those ending in 11", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(101)).toEqual("101st");
});

// Case 2: Identify the ordinal number for 2
// When the number is 2,
// Then the function should return "2nd"

test("should return '2nd' for 2", () => {
// Numbers ending in 2 (except those ending in 12): should append 'nd'
test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
expect(getOrdinalNumber(22)).toEqual("22nd");
expect(getOrdinalNumber(132)).toEqual("132nd");
});

// Case 3: Identify the ordinal number for 3
// When the number is 3,
// Then the function should return "3rd"

test("should return '3rd' for 3", () => {
// Numbers ending in 3 (except those ending in 13): should append 'rd'
test("append 'rd' to numbers ending in 3, except those ending in 13", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(23)).toEqual("23rd");
expect(getOrdinalNumber(103)).toEqual("103rd");
});

// Case 4: Identify the ordinal number for 4
// When the number is 4,
// Then the function should return "4th"

test("should return '4th' for 4", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
});

// Case 5: Identify the ordinal number for 11
// When the number is 11,
// Then the function should return "11th"

test("should return '11th' for 11", () => {
// Numbers ending in 11, 12, 13: should append 'th'
test("append 'th' to numbers ending in 11, 12, 13", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
});

// Case 6: Identify the ordinal number for 12
// When the number is 12,
// Then the function should return "12th"

test("should return '12th' for 12", () => {
expect(getOrdinalNumber(12)).toEqual("12th");
});

// Case 7: Identify the ordinal number for 13
// When the number is 13,
// Then the function should return "13th"

test("should return '13th' for 13", () => {
expect(getOrdinalNumber(13)).toEqual("13th");
});

// Case 8: Identify the ordinal number for 21
// When the number is 21,
// Then the function should return "21st"

test("should return '21st' for 21", () => {
expect(getOrdinalNumber(21)).toEqual("21st");
});

// Case 9: Identify the ordinal number for 22
// When the number is 22,
// Then the function should return "22nd"

test("should return '22nd' for 22", () => {
expect(getOrdinalNumber(22)).toEqual("22nd");
});

// Case 10: Identify the ordinal number for 23
// When the number is 23,
// Then the function should return "23rd"

test("should return '23rd' for 23", () => {
expect(getOrdinalNumber(23)).toEqual("23rd");
});

// Case 11: Identify the ordinal number for 101
// When the number is 101,
// Then the function should return "101st"

test("should return '101st' for 101", () => {
expect(getOrdinalNumber(101)).toEqual("101st");
});

// Case 12: Identify the ordinal number for 111
// When the number is 111,
// Then the function should return "111th"

test("should return '111th' for 111", () => {
expect(getOrdinalNumber(111)).toEqual("111th");
expect(getOrdinalNumber(112)).toEqual("112th");
expect(getOrdinalNumber(113)).toEqual("113th");
});

// Case 13: Identify the ordinal number for 0
// When the number is 0,
// Then the function should return "0th"

test("should return '0th' for 0", () => {
// All other numbers: should append 'th'
test("append 'th' to all other numbers", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
expect(getOrdinalNumber(10)).toEqual("10th");
expect(getOrdinalNumber(14)).toEqual("14th");
expect(getOrdinalNumber(0)).toEqual("0th");
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more informative description could be "... to numbers ending in 0, 4-9."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment updated. Thank you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we run jest test, what message will we see when this test fail?