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 @@ -15,7 +15,19 @@
// execute the code to ensure all tests pass.

function getAngleType(angle) {
// TODO: Implement this function
if (angle < 0 || angle > 360){
return "Invalid";
}else if (angle > 0 && angle < 90){
return "Acute angle";
}else if (angle === 90){
return "Right angle";
}else if (angle < 180){
return "Obtuse angle";
}else if (angle === 180){
return "Straight line";
}else if (angle > 180 && angle < 360){
return "Reflex angle";
}
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -35,3 +47,18 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");

const acute = getAngleType(15);
assertEquals(acute, "Acute angle");

const obtuse= getAngleType(115);
assertEquals(obtuse, "Obtuse angle");

const straight = getAngleType(180);
assertEquals(straight, "Straight line");

const reflexAngle = getAngleType(215);
assertEquals(reflexAngle, "Reflex angle");

const invalid = getAngleType(380);
assertEquals(invalid, "Invalid");
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// execute the code to ensure all tests pass.

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

// The line below allows us to load the isProperFraction function into tests in other files.
Expand All @@ -31,3 +31,8 @@ function assertEquals(actualOutput, targetOutput) {

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(2, 3), true);
assertEquals(isProperFraction(499, 500), true);
assertEquals(isProperFraction(5, 2), false);
assertEquals(isProperFraction(5, 5), false);
assertEquals(isProperFraction(1, 0), false);
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,32 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
const number = card.slice(0, -1);
const suit = card.slice(-1);
if (suit == "♠" || suit == "♥" || suit == "♦" || suit == "♣"){
switch (number) {
case "A":
return 11;
case "J":
case "Q":
case "K":
return 10;
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
return Number(number);
default:
throw new Error("Number is not valid");

}
}else{
throw new Error("Suit is not valid");
}
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -39,11 +64,28 @@ function assertEquals(actualOutput, targetOutput) {

// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
assertEquals(getCardValue("9♠"), 9);
assertEquals(getCardValue("A♠"), 11);
assertEquals(getCardValue("A♥"), 11);
assertEquals(getCardValue("J♦"), 10);
assertEquals(getCardValue("Q♦"), 10);
assertEquals(getCardValue("K♦"), 10);
assertEquals(getCardValue("2♣"), 2);
assertEquals(getCardValue("3♣"), 3);
assertEquals(getCardValue("4♦"), 4);
assertEquals(getCardValue("5♦"), 5);
assertEquals(getCardValue("6♦"), 6);
assertEquals(getCardValue("7♦"), 7);
assertEquals(getCardValue("8♣"), 8);
assertEquals(getCardValue("9♣"), 9);

// Handling invalid cards
try {
getCardValue("invalid");
getCardValue("92");
getCardValue("♦");
getCardValue("A");
getCardValue("*");
getCardValue("");
getCardValue(2);

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
Expand All @@ -52,3 +94,4 @@ try {
}

// What other invalid card cases can you think of?
// I tried different invalid card in the errror catch code above
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,37 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// Case 2: Right angle
test(`should return "Right angle" when (angle = 90)`, () => {
// Test right angles, only one case
expect(getAngleType(90)).toEqual("Right angle");
});

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

// Case 4: Straight angle
test(`should return "Straight angle angle" when (angle = 180)`, () => {
// Test right angles, only one case
expect(getAngleType(180)).toEqual("Straight line");
});

// Case 5: Reflex angles
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
// Test various reflex angles, including boundary cases
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(225)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});

// Case 6: Invalid angles
test(`should return "Invalid" when ( angle < 0 or angle > 360 )`, () => {
// Test various invalid angle, including boundary cases
expect(getAngleType(-1)).toEqual("Invalid");
expect(getAngleType(361)).toEqual("Invalid");
expect(getAngleType(550)).toEqual("Invalid");
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,21 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

// Proper fraction cases
test(`should return true when numerator is smaller then denominator`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(65, 67)).toEqual(true);
expect(isProperFraction(1, 1000)).toEqual(true);
expect(isProperFraction(999, 1000)).toEqual(true);
expect(isProperFraction(0, 6)).toEqual(true);
});

// Improper fraction cases
test(`should return false when numerator is bigger then denominator`, () => {
expect(isProperFraction(3, 2)).toEqual(false);
expect(isProperFraction(65, 60)).toEqual(false);
expect(isProperFraction(1000, 1)).toEqual(false);
expect(isProperFraction(2999, 1000)).toEqual(false);
expect(isProperFraction(11, 10)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,58 @@ const getCardValue = require("../implement/3-get-card-value");
// Case 1: Ace (A)
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
expect(getCardValue("A♦")).toEqual(11);
expect(getCardValue("A♠")).toEqual(11);
});

// Case 2: Face cards Jack, Queen, King (J,Q,K)
test(`Should return 10 when given a face card`, () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("J♦")).toEqual(10);
expect(getCardValue("Q♣")).toEqual(10);
expect(getCardValue("K♥")).toEqual(10);
});

// Case 3: Number cards 2-10 (2,3,4,5,6,7,8,9)
test(`Should return the card value when given a number card`, () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("3♦")).toEqual(3);
expect(getCardValue("4♣")).toEqual(4);
expect(getCardValue("5♥")).toEqual(5);
expect(getCardValue("6♠")).toEqual(6);
expect(getCardValue("7♦")).toEqual(7);
expect(getCardValue("8♣")).toEqual(8);
expect(getCardValue("9♥")).toEqual(9);
});

// Case 4: Invalid card
// test(`Should return invalid as the case is not valid`, () => {
// expect(getCardValue("invalid")).toEqual("invalid");
// expect(getCardValue("♦")).toEqual("invalid");
// expect(getCardValue("4")).toEqual("invalid");
// expect(getCardValue("")).toEqual("invalid");
// expect(getCardValue("m")).toEqual("invalid");
// expect(getCardValue("300")).toEqual("invalid");
// });
test("throw an error as the case is not valid but in right format", () => {
expect(() => {
getCardValue("92");
}).toThrow();
expect(() => {
getCardValue("♦");
}).toThrow();
expect(() => {
getCardValue("A");
}).toThrow();
expect(() => {
getCardValue("*");
}).toThrow();
expect(() => {
getCardValue("");
}).toThrow();
expect(() => {
getCardValue(2);
}).toThrow();
});

// Suggestion: Group the remaining test data into these categories:
Expand Down
Loading