Skip to content

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for sharing your tests! You’ve set up a solid foundation covering the main angle categories.

Are there any boundary values or edge cases (such as 0°, 360°, or negative numbers) that might be worth including to ensure the function handles all possible inputs precisely?

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,29 @@ 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(60);
assert.equal(acute, "Acute angle");
});
test("Classifies obtuse angles", () => {
const obtuse = getAngleType(120);
assert.equal(obtuse, "Obtuse angle");
});
test("Classifies straight angles", () => {
const straight = getAngleType(180);
assert.equal(straight, "Straight angle");
});
test("Classifies reflex angles", () => {
const reflex = getAngleType(350);
assert.equal(reflex, "Reflex angle");
});
test("Classifies invalid angles", () => {
const invalid = getAngleType(370);
assert.equal(invalid, "Invalid angle");
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Solid tests! Have you noticed a couple of minor typos in the descriptions, and might negative numbers be worth covering?

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

test("decimal numerator should return flase", () => {

assert.equal(isProperFraction(0.5, 2), false);
});


test("zero numerator", () => {
assert.equal(isProperFraction(0, 5), true);
});

test("numerator bigger then denumnator", () => {
assert.equal(isProperFraction(20, 15), false);
});
test("zero denumator", () => {
assert.equal(isProperFraction(100, 0), false);
});

test("equal numrator and denumerator ", () => {
assert.equal(isProperFraction(3, 3), 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.

Great test coverage for valid cards and invalid formats! How might the function handle lowercase inputs or missing values?

Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,35 @@ test("Arbitrary non-card string", () => {
});

// TODO: What other invalid card cases can you think of?
test("Ace returns 11", () => {
assert.equal(getCardValue("A♠"), 11);
});

test("Number card returns its numeric value", () => {
assert.equal(getCardValue("2♥"), 2);
assert.equal(getCardValue("7♦"), 7);
assert.equal(getCardValue("10♣"), 10);
});

test("Face cards return 10", () => {
assert.equal(getCardValue("J♣"), 10);
assert.equal(getCardValue("Q♦"), 10);
assert.equal(getCardValue("K♥"), 10);
});

test("Invalid rank throws an error", () => {
assert.throws(() => getCardValue("11♠"), Error);
assert.throws(() => getCardValue("X♥"), Error);
});

test("Invalid suit throws an error", () => {
assert.throws(() => getCardValue("A★"), Error);
});

test("Invalid format throws an error", () => {
assert.throws(() => getCardValue("A"), Error);
assert.throws(() => getCardValue("♠A"), Error);
assert.throws(() => getCardValue(" A♠"), Error);
assert.throws(() => getCardValue("A♠♠"), Error);
});

20 changes: 19 additions & 1 deletion implement-and-rewrite-tests/implement/1-get-angle-type.js

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Solid implementation! What happens if a negative number is passed into the function?

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Implement a function getAngleType

//
// Don't forget to write tests in implement-tests-with-node-test.
//
Expand All @@ -17,5 +18,22 @@
// execute the code to ensure all tests pass.

export function getAngleType(angle) {
// TODO: Implement this function
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";
}
return "Invalid angle";


}
13 changes: 12 additions & 1 deletion implement-and-rewrite-tests/implement/2-is-proper-fraction.js

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Solid implementation! How does the function handle negative numbers, and should they be considered proper fractions in this context?

Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,16 @@
// execute the code to ensure all tests pass.

export function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (Number.isNaN(numerator) || Number.isNaN(denominator)|| denominator===0) {
return false;
}
if (!Number.isInteger(numerator) || !Number.isInteger(denominator)) {
return false;
}
if (numerator >= denominator ) {
return false;
}
return true;


}
20 changes: 18 additions & 2 deletions implement-and-rewrite-tests/implement/3-get-card-value.js

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean regex logic! Notice where the function's closing brace is placed—is all of that implementation code currently inside the function body?

Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,21 @@
// execute the code to ensure all tests pass.

export function getCardValue(card) {
// TODO: Implement this function
}
const match = /^(A|[2-9]|10|J|Q|K)([♠♥♦♣])$/.exec(card);

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

const rank = match[1];

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

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

return Number(rank);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great coverage of the angle types! Have you checked the syntax of the first test block—is anything missing at the end before the next test starts?

Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
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");



test("Classifies right angles", () => {
expect(getAngleType(90)).toBe("Right angle");
});

test("Classifies acute angles", () => {
expect(getAngleType(60)).toBe("Acute angle");
});

test("Classifies obtuse angles", () => {
expect(getAngleType(120)).toBe("Obtuse angle");
});

// Case 2: Right angle
// Case 3: Obtuse angles
// Case 4: Straight angle
// Case 5: Reflex angles
// Case 6: Invalid angles
test("Classifies straight angles", () => {
expect(getAngleType(180)).toBe("Straight angle");
});

test("Classifies reflex angles", () => {
expect(getAngleType(350)).toBe("Reflex angle");
});

test("Classifies invalid angles", () => {
expect(getAngleType(370)).toBe("Invalid angle");
});


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice test coverage! Have you noticed the duplicated test blocks throughout the file

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,50 @@ 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 zero", () => {
expect(isProperFraction(1, 0)).toBe(false);
});
test("decimal numerator should return false", () => {
expect(isProperFraction(0.5, 2)).toBe(false);
});

test("zero numerator", () => {
expect(isProperFraction(0, 5)).toBe(true);
});

test("numerator bigger than denominator", () => {
expect(isProperFraction(20, 15)).toBe(false);
});

test("zero denominator", () => {
expect(isProperFraction(100, 0)).toBe(false);
});

test("equal numerator and denominator", () => {
expect(isProperFraction(3, 3)).toBe(false);
});

test("should return false when denominator is zero", () => {
expect(isProperFraction(1, 0)).toBe(false);
});

test("decimal numerator should return false", () => {
expect(isProperFraction(0.5, 2)).toBe(false);
});

test("zero numerator", () => {
expect(isProperFraction(0, 5)).toBe(true);
});

test("numerator bigger than denominator", () => {
expect(isProperFraction(20, 15)).toBe(false);
});

test("zero denominator should fail", () => {
expect(isProperFraction(100, 0)).toBe(false);
});

test("negative numerator should pass", () => {
expect(isProperFraction(-75, 100)).toBe(true);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comprehensive and thorough test suite covering numbers, face cards, and multiple error formats! Have you considered whether testing the Ace card is also needed in this block?

Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,34 @@ test(`Should return 11 when given an ace card`, () => {
// please refer to the Jest documentation:
// https://jestjs.io/docs/expect#tothrowerror

test("Number card returns its numeric value", () => {
expect(getCardValue("2♥")).toEqual(2);
expect(getCardValue("7♦")).toEqual(7);
expect(getCardValue("10♣")).toEqual(10);
});

test("Face cards return 10", () => {
expect(getCardValue("J♣")).toEqual(10);
expect(getCardValue("Q♦")).toEqual(10);
expect(getCardValue("K♥")).toEqual(10);
});

test("Invalid rank throws an error", () => {
expect(() => getCardValue("11♠")).toThrow(Error);
expect(() => getCardValue("X♥")).toThrow(Error);
});

test("Invalid suit throws an error", () => {
expect(() => getCardValue("A★")).toThrow(Error);
});

test("Invalid format throws an error", () => {
expect(() => getCardValue("A")).toThrow(Error);
expect(() => getCardValue("♠A")).toThrow(Error);
expect(() => getCardValue(" A♠")).toThrow(Error);
expect(() => getCardValue("A♠♠")).toThrow(Error);
});

test("Arbitrary non-card string", () => {
expect(() => getCardValue("invalid")).toThrow();
});
Loading