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,6 +16,24 @@

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.
Expand All @@ -32,6 +50,48 @@ function assertEquals(actualOutput, targetOutput) {
}

// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");

// Right angle
const rightAngle = getAngleType(90);
assertEquals(rightAngle, "Right angle");

// Acute angles
const acuteAngle = getAngleType(75);
assertEquals(acuteAngle, "Acute angle");

const acuteAngleBoundary = getAngleType(89);
assertEquals(acuteAngleBoundary, "Acute angle");

// Obtuse angles
const obtuseAngle = getAngleType(120);
assertEquals(obtuseAngle, "Obtuse angle");

const obtuseAngleBoundaryStart = getAngleType(91);
assertEquals(obtuseAngleBoundaryStart, "Obtuse angle");

const obtuseAngleBoundaryEnd = getAngleType(179);
assertEquals(obtuseAngleBoundaryEnd, "Obtuse angle");

// Straight angle
const straightAngle = getAngleType(180);
assertEquals(straightAngle, "Straight angle");

// Reflex angles
const reflexAngle = getAngleType(270);
assertEquals(reflexAngle, "Reflex angle");

const reflexAngleBoundary = getAngleType(359);
assertEquals(reflexAngleBoundary, "Reflex angle");

// Invalid angles
const invalidAngleAboveRange = getAngleType(370);
assertEquals(invalidAngleAboveRange, "Invalid angle");

const invalidAngleBelowRange = getAngleType(-10);
assertEquals(invalidAngleBelowRange, "Invalid angle");

const invalidAngleZero = getAngleType(0);
assertEquals(invalidAngleZero, "Invalid angle");

const invalidAngleUpperBoundary = getAngleType(360);
assertEquals(invalidAngleUpperBoundary, "Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@

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

// The line below allows us to load the isProperFraction function into tests in other files.
Expand All @@ -25,9 +34,22 @@ function assertEquals(actualOutput, targetOutput) {
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

// TODO: Write tests to cover all cases.
// What combinations of numerators and denominators should you test?

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(5, 5), false);
assertEquals(isProperFraction(2, 4), true);
assertEquals(isProperFraction(0, 9), true);
assertEquals(isProperFraction(6, 3), false);
assertEquals(isProperFraction(10,4), false);
assertEquals(isProperFraction(7, 0), false);
assertEquals(isProperFraction(15, 30), true);
assertEquals(isProperFraction(-7, 30), true);
assertEquals(isProperFraction(-9, 10), true);
assertEquals(isProperFraction(-5, -5), false);
assertEquals(isProperFraction(-1, 0), false);
assertEquals(isProperFraction(-1, -5), true);
assertEquals(isProperFraction(-1, -5), true);
assertEquals(isProperFraction(1, -5), true);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@

function getCardValue(card) {
// TODO: Implement this function
if(card=="A♠" || card=="A♥" || card=="A♦" || card == "A♣"){
return 11;
}
if(card=="J♠" || card=="J♥" || card=="J♦" || card == "J♣" ){
return 10;
}
if(card=="Q♠" || card=="Q♥" || card=="Q♦" || card == "Q♣" ){
return 10;
}
if(card=="K♠" || card=="K♥" || card=="K♦" || card == "K♣" ){
return 10;
}
const rank = Number(card.slice(0,-1));
const suit = card.slice(-1);
if(rank >= 2 && rank <=10 && ["♠","♥", "♦", "♣"].includes(suit)){
return rank;
}
Comment on lines +38 to +42

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In JavaScript, strings that represent valid numeric literals in the language can be safely converted to equivalent numbers. For examples, "0x02", "2.1", or "0002".

Does your function return the value you expected from each of the following function calls?

getCardValue("0x02♠");
getCardValue("2.1♠");
getCardValue("0002♠");

throw new Error("Invalid card");

}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -40,6 +59,12 @@ function assertEquals(actualOutput, targetOutput) {
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
assertEquals(getCardValue("9♠"), 9);
assertEquals(getCardValue("K♥"), 10);
assertEquals(getCardValue("J♣"), 10);
assertEquals(getCardValue("A♦"), 11);
assertEquals(getCardValue("Q♦"), 10);
assertEquals(getCardValue("10♠"), 10);
assertEquals(getCardValue("4♠"), 4);

// Handling invalid cards
try {
Expand All @@ -50,5 +75,36 @@ try {
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}

// What other invalid card cases can you think of?
try {
getCardValue("11♠");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}
try {
getCardValue("0");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}
try {
getCardValue("-8♦");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}
try {
getCardValue("a♣");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,41 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
expect(getAngleType(75)).toEqual("Acute angle");
});

// Case 2: Right angle
// Case 3: Obtuse angles
test(`should return "Right angle" when (angle==90)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(90)).toEqual("Right angle");
});

// Case 3: Obtuse angles
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(120)).toEqual("Obtuse angle");
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
expect(getAngleType(145)).toEqual("Obtuse angle");
});

// Case 4: Straight angle
test(`should return "Straight angle" when (angle==180)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(180)).toEqual("Straight angle");
});
// Case 5: Reflex angles
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
expect(getAngleType(181)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test("should return 'Invalid angle' for invalid angles", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It may not be clear what values are consider "invalid angles".
Can you revise the test description to make it more informative?

// Test various acute angles, including boundary cases
expect(getAngleType(-10)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(370)).toEqual("Invalid angle");
expect(getAngleType(0)).toEqual("Invalid angle");
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Based on the test descriptions, it is unclear what value these function calls should return:

 // It fits three of the test descriptions and they are giving contradicting info
isProperFraction(0, 0); 

// No info about negative numbers
isProperFraction(-1, 2);
isProperFraction(1, -2); 
isProperFraction(-1, -2); 

isProperFraction(-2, 1);
isProperFraction(2, -1); 
isProperFraction(-2, -1); 

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,52 @@ const isProperFraction = require("../implement/2-is-proper-fraction");

// 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`, () => {
// Denominator is zero
test("should return false when denominator is zero", () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

// Proper fractions
test("should return true when numerator is less than denominator", () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(2, 4)).toEqual(true);
expect(isProperFraction(15, 30)).toEqual(true);
});

// Numerator is zero
test("should return true when numerator is zero", () => {
expect(isProperFraction(0, 9)).toEqual(true);
});

// Equal numerator and denominator
test("should return false when numerator is equal to denominator", () => {
expect(isProperFraction(5, 5)).toEqual(false);
});

// Numerator is greater than denominator
test("should return false when numerator is greater than denominator", () => {
expect(isProperFraction(6, 3)).toEqual(false);
expect(isProperFraction(10, 4)).toEqual(false);
});

// Negative numerator
test("should return true when numerator is negative and forms a proper fraction", () => {
expect(isProperFraction(-1, 5)).toEqual(true);
expect(isProperFraction(-9, 10)).toEqual(true);
});

// Negative denominator
test("should return true when denominator is negative and forms a proper fraction", () => {
expect(isProperFraction(1, -5)).toEqual(true);
});

// Both numerator and denominator are negative
test("should handle both numerator and denominator being negative", () => {
expect(isProperFraction(-1, -5)).toEqual(true);
expect(isProperFraction(-5, -5)).toEqual(false);
});

// Negative numerator with zero denominator
test("should return false when denominator is zero with a negative numerator", () => {
expect(isProperFraction(-1, 0)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,25 @@ test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
// Invalid Cards
// Case 2: Face cards (J, Q, K)
test("should return 10 for face cards", () => {
expect(getCardValue("J♣")).toEqual(10);
expect(getCardValue("Q♦")).toEqual(10);
expect(getCardValue("K♥")).toEqual(10);
});

// 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
// Case 3: Number cards (2-10)
test("should return the numeric value for number cards", () => {
expect(getCardValue("4♠")).toEqual(4);
expect(getCardValue("9♠")).toEqual(9);
expect(getCardValue("10♠")).toEqual(10);
});

// Case 4: Invalid cards
test("should throw an error for invalid cards", () => {
expect(() => getCardValue("invalid")).toThrow();
expect(() => getCardValue("11♠")).toThrow();
expect(() => getCardValue("0")).toThrow();
expect(() => getCardValue("-8♦")).toThrow();
expect(() => getCardValue("a♣")).toThrow();
});