Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
dc81a0f
implement a function done
MaharitB Oct 9, 2026
daed937
put back the export line
MaharitB Oct 9, 2026
fc67493
wrote the function and body of the function
MaharitB Oct 9, 2026
7218c4e
implement a function done
MaharitB Oct 12, 2026
764fa71
fixed some errors on the code
MaharitB Oct 12, 2026
fb8933e
test passe for obtuse
MaharitB Oct 12, 2026
eee5696
test for acute and straight angle passed
MaharitB Oct 12, 2026
873bd2a
added test for reflex angle and invalid angles and all test passed
MaharitB Oct 13, 2026
971803f
wrote a test for proper function
MaharitB Oct 13, 2026
47a15f8
test failed and amend the code
MaharitB Oct 13, 2026
8f94698
testes passed
MaharitB Oct 13, 2026
dfe51bb
wrote test with a negative input...
MaharitB Oct 13, 2026
de57932
test failed for negative denominator . Added a Math.abs function so…
MaharitB Oct 13, 2026
0c40097
test failed and amend the code.
MaharitB Oct 13, 2026
d688c88
test added for numertest ator =0, test failed
MaharitB Oct 13, 2026
bc3a95c
amended the code for tesft fail.now test passed
MaharitB Oct 13, 2026
20c2bb0
added a test of (0,0) test passed
MaharitB Oct 13, 2026
1e64e02
test passed after modifing the error message
MaharitB Oct 13, 2026
d645a0c
modified the throw new error message and the test passed
MaharitB Oct 13, 2026
cfb7d08
did a test and failed . now amended my code
MaharitB Oct 14, 2026
f9c3407
edited the code based on the tests failed.
MaharitB Oct 14, 2026
68f1eca
added three tests and one of them is throw for invalid rank.still one…
MaharitB Oct 14, 2026
0cd8cf7
declared and initialized validSuit and validRank and edited the code …
MaharitB Oct 14, 2026
a618e0e
now all tests passed except 1 that should return 10 for J,Q,K
MaharitB Oct 14, 2026
5cff5b3
fixed the test now iall test passed
MaharitB Oct 14, 2026
589b0d3
added a test on invalid input. test passed
MaharitB Oct 14, 2026
4784665
added an if statment for the test writen and test passed
MaharitB Oct 14, 2026
c6355a8
wrote the tests and they all passed
MaharitB Oct 15, 2026
adaacaa
wrote two test both passed
MaharitB Oct 15, 2026
6c09cd2
added some more test all test passed
MaharitB Oct 15, 2026
edbd513
added tests for valid input of cards
MaharitB Oct 15, 2026
2ea44a4
amend code based on the test run and failed.now test passes
MaharitB Oct 15, 2026
cfd0d48
added a test that throws invalid input. test passed
MaharitB Oct 15, 2026
ae41393
test throw error is written and test passed
MaharitB Oct 15, 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,31 @@ test("Classifies right angles", () => {
const right = getAngleType(90);
assert.equal(right, "Right angle");
});
test("Classifies obtuse angles", () => {
const obtuse = getAngleType(91);
assert.equal(obtuse, "Obtuse angle");
});
test("Classifies acute angle", () => {
const acute = getAngleType(75);
assert.equal(acute, "Acute angle");
});
test("Classifies straight angle", () => {
const straight = getAngleType(180);
assert.equal(straight, "Straight angle");
});
test("Classifies reflex angle", () => {
const reflex = getAngleType(270);
assert.equal(reflex, "Reflex angle");
});
test("Classifiesreflex angle", () => {
const invalid = getAngleType(0);
assert.equal(invalid, "Invalid angle");
});
test("Classifiesreflex angle", () => {
const invalid = getAngleType(-90);
assert.equal(invalid, "Invalid angle");
});
test("Classifiesreflex angle", () => {
const invalid = getAngleType(360);
assert.equal(invalid, "Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,28 @@ test("Basic proper fraction", () => {
// Example: 1/2 is a proper fraction
assert.equal(isProperFraction(1, 2), true);
});
test("Basic proper function", () => {
assert.equal(isProperFraction(2, 4), true);
});
test("Not prpoer function", () => {
assert.equal(isProperFraction(4, 1), false);
});
test("Not proper function", () => {
assert.equal(isProperFraction(1, 1), false);
});
test("Basic proper function", () => {
assert.equal(isProperFraction(-1, 2), true);
});

test("Basic proper function", () => {
assert.equal(isProperFraction(1, -2), true);
});
test("Not proper function", () => {
assert.equal(isProperFraction(1, 0), false);
});
test("Not proper function", () => {
assert.equal(isProperFraction(0, 1), false);
});
test("Not proper function", () => {
assert.equal(isProperFraction(0, 0), false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,51 @@ 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("Arbitrary non-card string", () => {
assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error");
test("returns 11 for ace cards", () => {
assert.equal(getCardValue("A♠"), 11);
assert.equal(getCardValue("A♥"), 11);
});
test("returns 10 for cards with", () => {
assert.equal(getCardValue("J♠"), 10);
assert.equal(getCardValue("Q♥"), 10);
assert.equal(getCardValue("K♣"), 10);
});

// TODO: What other invalid card cases can you think of?
test("throws for invalid rank or suit", () => {
assert.throws(
() => getCardValue("invalid"),
/Expected a number followed by a suit, but got "invalid"/,
"Expected clear error"
);
});
test("throws for invalid rank", () => {
assert.throws(
() => getCardValue("11♠"),
/Expected a valid Rank and suit instead got "11♠"/,
"Expected clear error"
);
});
test("throws for invalid suit", () => {
assert.throws(
() => getCardValue("AA"),
/Expected a valid Rank and suit instead got "AA"/,
"Expected clear error"
);
});
test("throws for invalid rank", () => {
assert.throws(
() => getCardValue("1♣"),
/Expected a valid Rank and suit instead got "1♣"/,
"Expected clear error"
);
});
test("throws invalid input", () => {
assert.throws(
() => getCardValue("100"),
/Expected a valid Rank and suit instead got "100"/,
"Expected clear error"
);
});
13 changes: 11 additions & 2 deletions implement-and-rewrite-tests/implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
// 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
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";
}
6 changes: 4 additions & 2 deletions implement-and-rewrite-tests/implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// 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 (Math.abs(numerator) < Math.abs(denominator) && numerator !== 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If 0,5 is passed to the fn, what is will be the output of the function? is it the correct output?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

also please add the above input as one of the test cases.

return true;
}
return false;
}
49 changes: 48 additions & 1 deletion implement-and-rewrite-tests/implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,52 @@
// execute the code to ensure all tests pass.

export function getCardValue(card) {

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 overall code is good and works fine, however few things can be improved to make it better.

  • do we need to use let for defining the suit and cardInput? do we expect the value of these variables to be changed later? If not is there another way of defining the variables that's better suited for this scenario?

// TODO: Implement this function
let suit = card.slice(-1);
let cardInput = card.length;
const validSuit = ["♠", "♥", "♣", "♦"];
const validRank = [
"A",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
];

if (suit == "♠" || suit == "♥" || suit == "♣" || suit == "♦") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you already have all the validSuit defined in an array, would it make more sense to check the if the suit already exist in the array rather than checking individually?

if (cardInput == 2) {
if (card[0] == "A") {
return 11;
}
if (card[0] == "J" || card[0] == "Q" || card[0] == "K") {
return 10;
}
if (card[0] >= 2 && card[0] < 10) {
return Number(card[0]);
}
}
if (cardInput == 3 && card.slice(0, 2) === "10") {
return 10;
}
}
if (card == "invalid") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is it better to perform all the validation before or after any calculations? which is better?

throw new Error(`Expected a number followed by a suit, but got "${card}"`);
}

if (!validRank.includes(card[0])) {
throw new Error(`Expected a valid Rank and suit instead got "${card}"`);
}
if (!validSuit.includes(suit)) {
throw new Error(`Expected a valid Rank and suit instead got "${card}"`);
}
if (cardInput >= 3 && card[0] !== "10") {
throw new Error(`Expected a valid Rank and suit instead got "${card}"`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,38 @@ import { getAngleType } from "../implement/1-get-angle-type.js";
// 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");
describe(`valid 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");
});
test(`should return"Right angle" when (angle = 90)`, () => {
expect(getAngleType(90)).toEqual("Right angle");
});
test(`should return "Obtuse angle"when (90<angle<180)`, () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(135)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});
test(`should return "Straight angle" when (angle = 180)`, () => {
expect(getAngleType(180)).toEqual("Straight angle");
});
test(`should return "Reflex angle" when (180 < angle <360)`, () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});
});

describe(`Invalid angles`, () => {
test(`should return "Invalid angls"when given Invalid angle`, () => {
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(-1)).toEqual("Invalid angle");
});
});
// Case 2: Right angle
// Case 3: Obtuse angles
// Case 4: Straight angle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,27 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js";
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});
test(`should return true when (denominator > numerator)`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});
test(`should return false when (denominator< numerator)`, () => {
expect(isProperFraction(2, 1)).toEqual(false);
});
test(`should return true when (denominator < numerator)`, () => {
expect(isProperFraction(1, -2)).toEqual(true);
});
test(`should return false when(numerator = 0)`, () => {
expect(isProperFraction(0, 1)).toEqual(false);
});
test(`should return false when(numerator = 0 and numerator = 0)`, () => {
expect(isProperFraction(0, 0)).toEqual(false);
});
test(`should return true when(numerator < denominator)`, () => {
expect(isProperFraction(-1, 2)).toEqual(true);
});
test(`should return true when numerator > denominator)`, () => {
expect(isProperFraction(-1, -2)).toEqual(true);
});
test(`should return false when(numerator < denominator)`, () => {
expect(isProperFraction(-2, -1)).toEqual(false);
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
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`, () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since we've added a ton of validation for checking if the input is correct, wouldn't it make more sense to test it to confirm if its working fine?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Think about malformed inputs etc.

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.

Thank you for the constructive feedback . I really appreciate it.
I included tests that prove if the validation works.It is at the bottom the of test file.

expect(getCardValue("A♠")).toEqual(11);
});
test(`should retun the numeric value when given "numbered" cards`, () => {
expect(getCardValue("2♣")).toEqual(2);
expect(getCardValue("6♥")).toEqual(6);
expect(getCardValue("10♦")).toEqual(10);
});
test(`should retun 10 when given(J,Q,K)cards`, () => {
expect(getCardValue("J♣")).toEqual(10);
expect(getCardValue("Q♥")).toEqual(10);
expect(getCardValue("K♦")).toEqual(10);
});

test(`throws for invalid cards`, () => {
expect(() => {
getCardValue("invalid");
}).toThrow(`Expected a number followed by a suit, but got "invalid"`);
});
test(`throws for invalid rank`, () => {
expect(() => {
getCardValue("1♥");
}).toThrow(`Expected a valid Rank and suit instead got "1♥"`);
});
test(`throws for invalid suit`, () => {
expect(() => {
getCardValue("AS");
}).toThrow(`Expected a valid Rank and suit instead got "AS"`);
});
test(`throws for invalid input`, () => {
expect(() => {
getCardValue("100");
}).toThrow(`Expected a valid Rank and suit instead got "100"`);
});
test(`throws for invalid suit`, () => {
expect(() => {
getCardValue("15♥");
}).toThrow(`Expected a valid Rank and suit instead got "15♥"`);
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
Expand All @@ -15,4 +48,3 @@ test(`Should return 11 when given an ace card`, () => {
// 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

Loading