Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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

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,40 @@ 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");
});
test("Classifies invalid angles", () => {
const invalid = getAngleType(-10);
assert.equal(invalid, "Invalid angle");
});
test("Classifies Zero angle", () => {
const zero = getAngleType(0);
assert.equal(zero, "Zero angle");
});

test("Classifies Complete angle", () => {
const complete = getAngleType(360);
assert.equal(complete, "Complete 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,44 @@ 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 should retrun true", () => {
assert.equal(isProperFraction(0, 5), true);
});

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

test("equal numerator and denumerator should return false", () => {
assert.equal(isProperFraction(3, 3), false);
});

test("negative numerator smaller then a positive denumerator should return true ", () => {
assert.equal(isProperFraction(-5, 16), true);
});

test("positive numerator and negative denumerator should return false", () => {
assert.equal(isProperFraction(5, -16), false);
});

test("negative numerator smaller then a negative denumerator should return false", () => {
assert.equal(isProperFraction(-50 , -16), false);
});
test("negative numerator bigger then a negative denumerator should return true", () => {
assert.equal(isProperFraction(-16, -50), 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.

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 @@ -5,12 +5,46 @@ import { getCardValue } from "../implement/3-get-card-value.js";

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

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

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

test("Arbitrary non-card string", () => {
assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error");
expect(() => getCardValue("invalid")).toThrow(
'Expected a number followed by a suit, but got "invalid"'
);
});

test("Ace returns 11", () => {
expect(getCardValue("A♠")).toEqual(11);
});

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

// TODO: What other invalid card cases can you think of?
test("Invalid format throws an error", () => {
expect(() => getCardValue("A★")).toThrow(Error);
expect(() => getCardValue("11♠")).toThrow(Error);
expect(() => getCardValue("X♥")).toThrow(Error);
expect(() => getCardValue("A")).toThrow(Error);
expect(() => getCardValue("♠A")).toThrow(Error);
expect(() => getCardValue(" A♠")).toThrow(Error);
expect(() => getCardValue("A♠♠")).toThrow(Error);
expect(() => getCardValue(undefined)).toThrow(Error);
expect(() => getCardValue(null)).toThrow(Error);
expect(() => getCardValue("")).toThrow(Error);
expect(() => getCardValue("a♠")).toThrow(Error);
expect(() => getCardValue("k♥")).toThrow(Error);
expect(() => getCardValue("q♦")).toThrow(Error);
});
28 changes: 27 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,30 @@
// execute the code to ensure all tests pass.

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


}
18 changes: 17 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,21 @@
// 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;
}
if (numerator < 0 && denominator < 0) {
if (Math.abs(numerator) > Math.abs(denominator)) return false;
}
return true;
}
18 changes: 17 additions & 1 deletion 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,41 @@ 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 should return true", () => {
expect(isProperFraction(0, 5)).toBe(true);
});

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

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

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

test("negative numeratore smaller then a positive denumerator should return true", () => {
expect(isProperFraction(-5, 16)).toBe(true);
});

test("positive numeratior and negative denumerator should return false", () => {
expect(isProperFraction(5, -16)).toBe(false);
});

test("negative numerator smaller than a negative denominator should return false", () => {
expect(isProperFraction(20, 15)).toBe(false);
});

test("negative numerator bigger than a negative denominator should return false", () => {
expect(isProperFraction(-16, -50)).toBe(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.

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