Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e8606f9
Work on "Right angle"
HM-127BTY Oct 7, 2026
53621cd
Added tests for all the angles, next working on code
HM-127BTY Oct 7, 2026
5721c8b
Added code for Acute angle
HM-127BTY Oct 7, 2026
5e692d8
Added code for Obtuse angle
HM-127BTY Oct 7, 2026
b61b4b4
Added code for Straight angle
HM-127BTY Oct 7, 2026
7ccf911
Added code for Reflex angles
HM-127BTY Oct 7, 2026
426aabb
Added code for Invalid angle
HM-127BTY Oct 7, 2026
1c3277f
fixed errors and rearranged code to be easier to read
HM-127BTY Oct 8, 2026
c4786d8
Set up testing requirements for the fractions
HM-127BTY Oct 8, 2026
707ac48
Done the code for fractions coving test requests.
HM-127BTY Oct 8, 2026
16f4f20
cleaned up the code
HM-127BTY Oct 8, 2026
e3a8f17
added basic tests needed and non - card string.
HM-127BTY Oct 8, 2026
ae7ef77
working on code and trying to fix errors
HM-127BTY Oct 8, 2026
d4db679
finished code and tests for 3 types:
HM-127BTY Oct 8, 2026
9970ef6
cleaned up errors i encountered .
HM-127BTY Oct 8, 2026
2830bf3
Added in test for Right angle.
HM-127BTY Oct 9, 2026
c7af1dd
Added test for Obtuse angles
HM-127BTY Oct 9, 2026
2fc4cd2
Added test for Straight angles
HM-127BTY Oct 9, 2026
8662c14
Added tests for Right angles
HM-127BTY Oct 9, 2026
6ae03b0
Added tests for Invalid angles
HM-127BTY Oct 9, 2026
3727932
Added in commented tests to update as I progress though tests.
HM-127BTY Oct 9, 2026
5d6c6ef
Added code for Improper fraction: Numerator = Denominator
HM-127BTY Oct 9, 2026
b155253
Added code for Improper fraction: Numerator > Denominator
HM-127BTY Oct 9, 2026
6f64f2e
Added code for -Numerator > Denominator
HM-127BTY Oct 9, 2026
b37a765
Setup code for more tests.
HM-127BTY Oct 9, 2026
9770764
Added code for return 10 for J, Q, K.
HM-127BTY Oct 9, 2026
67f4dd7
Added code for throw error invalid card
HM-127BTY Oct 9, 2026
77cf05b
Added in testing code for Incorrect Suit and fixed errors with lackin…
HM-127BTY Oct 9, 2026
3f42554
fixing erros in code and including "Incorrect card number" test
HM-127BTY Oct 9, 2026
328f3c1
fixed errors and put in more test code for Incorrect card given
HM-127BTY Oct 9, 2026
0cca1dc
Added code and test for Full and Zero Angle.
HM-127BTY Oct 10, 2026
2633baa
Added jest tests for Zero and Full angles
HM-127BTY Oct 10, 2026
9cf8fc2
Added in extra invalid for negative number and fixed errors for full …
HM-127BTY Oct 10, 2026
876923e
Added more negative number tests and additional improper fractions fo…
HM-127BTY Oct 10, 2026
899e435
Changed zero and full angles to Invalid angles
HM-127BTY Oct 12, 2026
248c2e8
changed last "else if" to "else"
HM-127BTY Oct 12, 2026
e6b8b53
Added tests for 0 with negative denominator or numerator
HM-127BTY Oct 12, 2026
23c6ee7
made change to include any value under 1 to be Incorrect card number …
HM-127BTY Oct 13, 2026
1236e2f
Added in a if for Number.isNaN to check if for word or symbol input i…
HM-127BTY Oct 13, 2026
0845379
Added tests for invalid values
HM-127BTY Oct 13, 2026
0569019
Added extra jest tests for incorrect card given.
HM-127BTY Oct 13, 2026
1a20c17
fixed bug with having two tests doing - numerators.
HM-127BTY Oct 13, 2026
ba66435
added both as negative test
HM-127BTY Oct 13, 2026
cdd5f00
Added test for both being 0
HM-127BTY Oct 14, 2026
8b09c49
Added tests missing from requests
HM-127BTY Oct 14, 2026
f78ab0d
Fixed spelling error in thrown error.
HM-127BTY Oct 14, 2026
7046cb7
Found bug in all toThrow tests, had toThrow; so was getting false pos…
HM-127BTY Oct 14, 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 @@ -10,3 +10,40 @@ test("Classifies right angles", () => {
const right = getAngleType(90);
assert.equal(right, "Right angle");
});
// "Acute angle" for angles greater than 0° and less than 90°
test("Classifies Acute angles", () => {
const right = getAngleType(45);
assert.equal(right, "Acute angle");
});
// - "Obtuse angle" for angles greater than 90° and less than 180°
test("Classifies Obtuse angles", () => {
const right = getAngleType(135);
assert.equal(right, "Obtuse angle");
});
// - "Straight angle" for exactly 180°
test("Classifies Straight angles", () => {
const right = getAngleType(180);
assert.equal(right, "Straight angle");
});
// - "Reflex angle" for angles greater than 180° and less than 360°
test("Classifies Reflex angles", () => {
const right = getAngleType(225);
assert.equal(right, "Reflex angle");
});
// - "Invalid angle" for angles outside the valid range.
test("Classifies Invalid angles", () => {
const right = getAngleType(361);
assert.equal(right, "Invalid angle");
const right = getAngleType(-361);
assert.equal(right, "Invalid angle");
});
// - "Invalid angle" for angles that are at 0°
test("Classifies Invalid angles for 0", () => {
const right = getAngleType(0);
assert.equal(right, "Invalid angle");
});
// - "Invalid angle" for angles that are at 360°
test("Classifies Invalid angles for 360", () => {
const right = getAngleType(360);
assert.equal(right, "Invalid angle");
});
Comment on lines +33 to +39

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There should be one more boundary case for invalid angle. Can you think of it? Please add it back. Thank you.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added invalid angle for negative numbers.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,63 @@ 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", () => {
test("Basic proper fraction: Numerator < Denominator", () => {
// Example: 1/2 is a proper fraction
assert.equal(isProperFraction(1, 2), true);
});

test("Improper fraction: Numerator = Denominator", () => {
assert.equal(isProperFraction(2, 2), false);
});

test("Improper negative fraction: Numerator = Denominator", () => {
assert.equal(isProperFraction(-2, -2), false);
});

test("improper fraction: Numerator > Denominator", () => {
assert.equal(isProperFraction(2, 1), false);
});

test("Improper fraction: Denominator = 0", () => {
assert.equal(isProperFraction(1, 0), false);
});

test("Improper fraction: Nominator = 0", () => {
assert.equal(isProperFraction(0, 2), false);
});

test("Proper fraction with negative number: -Numerator < Denominator", () => {
assert.equal(isProperFraction(-1, 2), true);
});

test("Proper fraction with negative number: Numerator < -Denominator", () => {
assert.equal(isProperFraction(1, -2), true);
});

test("Improper fraction with negative number: -Numerator > Denominator", () => {
assert.equal(isProperFraction(-2, 1), false);
});
Comment on lines +26 to +44

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There should be 3 more test suites related to either zero or negative values. Can you think of them? Please add them back. Thank you.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I did not have 0 denominator, both numerator and denominator as negative and negative denominator

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For positive numbers and zero, there is enough coverage.
For combination of positive and negative numbers you have:

  • (-1, 2)
  • (1, -2)
  • (-2, 1)
  • (??, ??) <--- what should this one be?

For negative numbers, you have (-1, -2) and should still have one more case, what is it?
You are almost there, add the two missing cases and you are good to go.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Do you mean something like: -1,0 and 0,-1?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I did add them into the tests... ahh... Both negative? >.<

@hackertainment hackertainment Oct 13, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hmm... good try, just still not enough coverage. When we design test cases, we need to consider the context of the program. In your solution, you compared the absolute value of numerator and denominator. Therefore, the only possibilities are < or = or > in mathematics. Your test cases then design around them with positive values, zero, and negative values, which include:

  • positive test cases
    • numerator < denominator such as (1, 2) which you have covered
    • numerator = denominator such as (2, 2) which you have covered
    • numerator > denominator such as (2, 1) which you have covered
  • zero test cases
    • numerator is zero such as (0, 2) which you have covered
    • denominator is zero such as (1, 0) which you have covered
    • both are zero such as (0, 0) which might be missed (but minor, because this is even not a fraction)
  • negative test cases
    • numerator > denominator such as (-1, -2) which you have added (very good)
    • numerator < denominator such as (-2, -1) which might be missed (but important)
    • numerator = denominator such as (-2, -2) which might be missed (but important)
  • positive and negative combined cases
    • (-1, 2) which you have covered
    • (1, -2) which you have covered
    • (-2, 1) which you have covered
    • (2, -1) which might be missed (but important)

As a result, there should be at least 12 (or 13 if also testing 0/0) test cases to cover all unique combinations. Please fix this file by adding the missed test cases. Thanks a lot.

I hope you learnt the test case "design process", especially how to use minimum number of tests to provide maximum coverage. If you want to learn more about designing test cases, please feel free to book a mentored coding session with a volunteer.


test("Improper fraction with negative number: Numerator > -Denominator", () => {
assert.equal(isProperFraction(2, -1), false);
});

test("Proper fraction with negative numbers: -Numerator < -Denominator", () => {
assert.equal(isProperFraction(-1, -2), true);
});

test("Proper fraction with negative Numerator and Zero: -Numerator < 0", () => {
assert.equal(isProperFraction(-1, 0), false);
});

test("Proper fraction with Zero and negative Denominator: 0 < -Denominator", () => {
assert.equal(isProperFraction(0, -2), false);
});

test("Proper fraction with both being Zero", () => {
assert.equal(isProperFraction(0, 0), false);
});

test("Improper fraction with negative numbers: -Numerator > -Denominator", () => {
assert.equal(isProperFraction(-3, -2), false);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Both valid and invalid cards, there should be more test cases covering various combinations. Please add them. Thank you.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,52 @@ test("Valid single-digit card", () => {
});

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"
);
});

// TODO: What other invalid card cases can you think of?
//Incorrect suit
test("Incorrect suit", () => {
assert.throws(
() => getCardValue("2☺"),
/Incorrect suit given/,
"Incorrect suit"
);
});

//Incorrect card value to high
test("Incorrect card number: High value", () => {
assert.throws(
() => getCardValue("20♦"),
/Incorrect card number given/,
"Incorrect card number given"
);
});
//Incorrect card value when negative
test("Incorrect card number: Negative Number", () => {
assert.throws(
() => getCardValue("-2♦"),
/Incorrect card number given/,
"Incorrect card number given"
);
});
//Incorrect card value when symbol
test("Incorrect card number: Symbol", () => {
assert.throws(
() => getCardValue("🐱♦"),
/Incorrect card number given/,
"Incorrect card number given"
);
});
//Incorrect card value when letter
test("Incorrect card number: Letter", () => {
assert.throws(
() => getCardValue("H♦"),
/Incorrect card number given/,
"Incorrect card number given"
);
});
17 changes: 17 additions & 0 deletions implement-and-rewrite-tests/implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,21 @@

export function getAngleType(angle) {
// TODO: Implement this function
if (angle === 90) {
return "Right angle";
} else if (angle > 0 && angle < 90) {
return "Acute 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 === 0) {
return "Invalid angle";
} else if (angle === 360) {
return "Invalid angle";
} else (angle < 0 || angle > 360) {
return "Invalid angle";
}
}
8 changes: 8 additions & 0 deletions implement-and-rewrite-tests/implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@

export function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (denominator === 0) {
return false;
} else if (numerator === 0) {
return false;
} else if (Math.abs(numerator) >= Math.abs(denominator)) {
return false;
}
return true;
}
21 changes: 21 additions & 0 deletions implement-and-rewrite-tests/implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,25 @@

export function getCardValue(card) {
// TODO: Implement this function
if (card.length >= 4) {
throw new Error(`expected a number followed by a suit, but got "invalid"`);
}

let suit = card.slice(-1);
let cardNumber = card.slice(0, -1);
let value = Number(cardNumber);

if (!(suit === "♠" || suit === "♥" || suit === "♦" || suit === "♣")) {
throw new Error("Incorrect suit given");
} else if (cardNumber === "J" || cardNumber === "Q" || cardNumber === "K") {
return 10;
} else if (cardNumber === "A") {
return 11;
} else if (Number.isNaN(value)) {
throw new Error("Incorrect card number given");
} else if (value >= 2 && value <= 10) {
return value;
} else if (value < 2 || value > 10) {
throw new Error("Incorrect card number given");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,36 @@ 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
// Case 4: Straight angle
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(167)).toEqual("Obtuse angle");
expect(getAngleType(179)).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 "Right angle" when (180 < angle < 360)`, () => {
expect(getAngleType(186)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test(`should return "Invalid angle" when (0 > angle > 360)`, () => {
expect(getAngleType(361)).toEqual("Invalid angle");
expect(getAngleType(396)).toEqual("Invalid angle");
expect(getAngleType(-57)).toEqual("Invalid angle");
});
Comment on lines +35 to +39

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There should be two boundary cases in this test suite. Can you think of them? Please add them. Thank you.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah I see, I did not have Zero angle and Full angle. Was just looking at what was mentioned for the tests.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just they should be counted as invalid (per question's definition).

// Case 7: Zero angles
test(`should return "Invalid angle" when (angle = 0)`, () => {
expect(getAngleType(0)).toEqual("Invalid angle");
});
// Case 8: Full angles
test(`should return "Invalid angle" when (angle = 360)`, () => {
expect(getAngleType(360)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,107 @@ 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`, () => {
test(`should return false when numerator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

// Special case: denominator is zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(0, 1)).toEqual(false);
});

// Special case: both are zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(0, 0)).toEqual(false);
});

// Special case: Basic proper fraction: Numerator < Denominator
test(`should return true when: Numerator < Denominator`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(3, 6)).toEqual(true);
expect(isProperFraction(45, 60)).toEqual(true);
});

// Special case: Basic proper negative fraction: -Numerator < Denominator
test(`should return true when: Numerator < Denominator`, () => {
expect(isProperFraction(-1, 2)).toEqual(true);
expect(isProperFraction(-3, 6)).toEqual(true);
expect(isProperFraction(-45, 60)).toEqual(true);
});

// Special case: Basic proper negative fraction: Numerator < -Denominator
test(`should return true when: Numerator < Denominator`, () => {
expect(isProperFraction(1, -2)).toEqual(true);
expect(isProperFraction(3, -6)).toEqual(true);
expect(isProperFraction(45, -60)).toEqual(true);
});

// Special case: Improper fraction: Numerator = Denominator
test(`should return false when: Numerator = Denominator`, () => {
expect(isProperFraction(1, 1)).toEqual(false);
expect(isProperFraction(12, 12)).toEqual(false);
expect(isProperFraction(56, 56)).toEqual(false);
});

// Special case: Improper negative fraction: -Numerator = -Denominator
test(`should return false when: Numerator = Denominator`, () => {
expect(isProperFraction(-1, -1)).toEqual(false);
expect(isProperFraction(-12, -12)).toEqual(false);
expect(isProperFraction(-56, -56)).toEqual(false);
});

// Special case: Improper fraction: Numerator > Denominator
test(`should return false when: Numerator > Denominator`, () => {
expect(isProperFraction(3, 2)).toEqual(false);
expect(isProperFraction(7, 4)).toEqual(false);
expect(isProperFraction(30, 20)).toEqual(false);
});

// Special case: Proper fraction with negative number: -Numerator < Denominator
test(`should return true when: -Numerator < Denominator`, () => {
expect(isProperFraction(-1, 2)).toEqual(true);
expect(isProperFraction(-6, 8)).toEqual(true);
expect(isProperFraction(-10, 20)).toEqual(true);
});

// Special case: Proper fraction with both negative number: -Numerator < -Denominator
test(`should return true when: -Numerator < -Denominator`, () => {
expect(isProperFraction(-1, -2)).toEqual(true);
expect(isProperFraction(-6, -8)).toEqual(true);
expect(isProperFraction(-10, -20)).toEqual(true);
});

// Special case: Improper fraction with negative number: Numerator > -Denominator
test(`should return false when: -Numerator > Denominator`, () => {
expect(isProperFraction(2, -1)).toEqual(false);
expect(isProperFraction(5, -4)).toEqual(false);
expect(isProperFraction(20, -10)).toEqual(false);
});

// Special case: Improper fraction with negative number: Numerator > -Denominator
test(`should return false when: -Numerator > Denominator`, () => {
expect(isProperFraction(-2, 1)).toEqual(false);
expect(isProperFraction(-5, 4)).toEqual(false);
expect(isProperFraction(-20, 10)).toEqual(false);
});
Comment on lines +62 to +95

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There should be two more negative test suites and two zero related test suites. Please add them back. Thank you.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I did not have 0 denominator, both numerator and denominator as negative and negative denominator

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The -Numerator < Denominator cases are duplicated. That means still one test suite missing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah seen, fixed the error.


// Special case: Improper fraction with both negative: -Numerator > -Denominator
test(`should return false when: -Numerator > Denominator`, () => {
expect(isProperFraction(-2, -1)).toEqual(false);
expect(isProperFraction(-5, -4)).toEqual(false);
expect(isProperFraction(-20, -10)).toEqual(false);
});

// Special case: Improper fraction with negative Numerator and 0: -Numerator > 0
test(`should return false when: -Numerator > Denominator`, () => {
expect(isProperFraction(-2, 0)).toEqual(false);
expect(isProperFraction(-5, 0)).toEqual(false);
expect(isProperFraction(-20, 0)).toEqual(false);
});

// Special case: Improper fraction with 0 and negative Denominator: 0 > -Denominator
test(`should return false when: -Numerator > Denominator`, () => {
expect(isProperFraction(0, -1)).toEqual(false);
expect(isProperFraction(0, -4)).toEqual(false);
expect(isProperFraction(0, -10)).toEqual(false);
});
Loading