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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,28 @@

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";
}
else {
return "Invalid angle";
}
}


// The line below allows us to load the getAngleType function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getAngleType;
Expand All @@ -35,3 +55,18 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");
let reflex = getAngleType(280);
assertEquals(reflex, "Reflex angle");
const straight = getAngleType(180);
assertEquals(straight, "Straight angle");
let invalid = getAngleType(360);
assertEquals(invalid,"Invalid angle");
invalid = getAngleType(-1);
assertEquals(invalid, "Invalid angle");
invalid = getAngleType(0);
assertEquals(invalid, "Invalid angle");
let obtuse = getAngleType(160);
assertEquals(obtuse, "Obtuse angle");
let acute = getAngleType(10);
assertEquals(acute, "Acute angle");

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (numerator < denominator){
return true;
}
else{
return false;
}
}

// console.log(isProperFraction(10,22))
// The line below allows us to load the isProperFraction function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = isProperFraction;
Expand All @@ -31,3 +37,7 @@ function assertEquals(actualOutput, targetOutput) {

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(10,20), true);
assertEquals(isProperFraction(80, 10), false);
assertEquals(isProperFraction(8, 16), true);
assertEquals(isProperFraction(10, 2), false);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@

function getCardValue(card) {
// TODO: Implement this function
if (typeof card !== "string" || card.length < 2) {
throw new Error("Invalid card format");
}
const rank = card.slice(0, -1);
const suit = card.slice(-1);

const validSuits = ["♠", "♥", "♦", "♣"];
if (!validSuits.includes(suit)) {
throw new Error("Invalid suit");
}
if (rank === "A") {
return 11;
}
if (["J", "Q", "K"].includes(rank)) {
return 10;
}
const numericValue = parseInt(rank, 10);
if (
!isNaN(numericValue) &&
numericValue >= 2 &&
numericValue <= 10 &&
String(numericValue) === rank
) {
return numericValue;
}
throw new Error("Invalid rank");
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand Down Expand Up @@ -52,3 +78,18 @@ try {
}

// What other invalid card cases can you think of?
assertEquals(getCardValue("9♠"), 9);
assertEquals(getCardValue("2♥"), 2);
assertEquals(getCardValue("10♥"), 10);
assertEquals(getCardValue("A♣"), 11);
assertEquals(getCardValue("J♦"), 10);
assertEquals(getCardValue("Q♠"), 10);
assertEquals(getCardValue("K♣"), 10);

assertThrows("invalid");
assertThrows("A");
assertThrows("♠");
assertThrows("1♥");
assertThrows("Z♠");
assertThrows("10");
assertThrows("A♥♠");
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,35 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
expect(getAngleType(89)).toEqual("Acute angle");
});


// Case 2: Right angle
test(`should return "Right angle" when angle is exactly 90`, () => {
expect(getAngleType(90)).toEqual("Right angle");
});

// Case 3: Obtuse angles
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");
});

// Case 4: Straight angle
test(`should return "Straight angle" when angle is exactly 180`, () => {
expect(getAngleType(180)).toEqual("Straight angle");
});

// Case 5: Reflex angles
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");
});

// Case 6: Invalid angles
test(`should return "Invalid angle" for boundaries and out-of-bounds numbers`, () => {
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(-10)).toEqual("Invalid angle");
expect(getAngleType(361)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,31 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

// Case 1: Standard Positive Numbers
test("should handle standard positive fractions correctly", () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(5, 3)).toEqual(false);
});

// Case 2: Equal Numbers (Boundary)
test("should return false when numerator and denominator are equal", () => {
expect(isProperFraction(5, 5)).toEqual(false); // Equals 1 whole (Improper)
});

// Case 3: Numerator is Zero
test("should return true when numerator is zero and denominator is positive", () => {
expect(isProperFraction(0, 5)).toEqual(true);
});

// Case 4: Negative Numbers
test("should handle negative integers according to mathematical comparison rules", () => {
expect(isProperFraction(-5, -2)).toEqual(true);
expect(isProperFraction(-1, -4)).toEqual(false);
});

// Case 5: Mixed Positive and Negative Numbers
test("should return true when only the numerator is negative", () => {
expect(isProperFraction(-1, 2)).toEqual(true);
expect(isProperFraction(1, -2)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@ test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});

// Case 2: Number Cards (2-10)
test("Should return the matching numeric value for number cards (2-10)", () => {
expect(getCardValue("2♥")).toEqual(2);
expect(getCardValue("5♦")).toEqual(5);
expect(getCardValue("10♣")).toEqual(10);
});

// Case 3: Face Cards (J, Q, K)
test("Should return 10 when given face cards (J, Q, K)", () => {
expect(getCardValue("J♣")).toEqual(10);
expect(getCardValue("Q♦")).toEqual(10);
expect(getCardValue("K♠")).toEqual(10);
});

// Case 4: Invalid Cards

test("Should throw an error when given invalid card inputs", () => {
expect(() => getCardValue("invalid")).toThrow();
expect(() => getCardValue("A")).toThrow();
expect(() => getCardValue("♠")).toThrow();
expect(() => getCardValue("11♥")).toThrow();
expect(() => getCardValue("1♥")).toThrow();
expect(() => getCardValue("Z♦")).toThrow();
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
Expand Down
Loading