Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@

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 @@ -35,3 +59,30 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");

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

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

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

const reflex = getAngleType(359.9);
assertEquals(reflex,"Reflex angle");

const invalid = getAngleType(380);
assertEquals(invalid,"Invalid angle");

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

const invalid2 = getAngleType(360);
assertEquals(invalid2,"Invalid angle");

const acute2 = getAngleType(0.1);
assertEquals(acute2,"Acute angle");

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

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

// The line below allows us to load the isProperFraction function into tests in other files.
Expand All @@ -29,5 +37,12 @@ function assertEquals(actualOutput, targetOutput) {
// TODO: Write tests to cover all cases.
// What combinations of numerators and denominators should you test?

// Example: 1/2 is a proper fraction
// Example: 1/2 is a proper fraction.
assertEquals(isProperFraction(1, 2), true);

assertEquals(isProperFraction(1,1),false);
assertEquals(isProperFraction(40234,98543),true);
assertEquals(isProperFraction(2,1),false);
assertEquals(isProperFraction(-10,-1),false);
assertEquals(isProperFraction(-1,-10),true);
assertEquals(isProperFraction(1.5,1),false);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@

function getCardValue(card) {
// TODO: Implement this function
const value = card.slice(0, -1).toUpperCase();
const validSuits = "♠,♥,♦,♣".split(",");
const suit = card.slice(-1);


if(!validSuits.includes(suit)) {
throw new Error("Invalid card");
}

const faceCardValues = {'A': 11, 'J': 10, 'Q': 10, 'K': 10};

if(faceCardValues[value] === undefined && (Number(value) < 2 || Number(value) > 10)) {
throw new Error("Invalid card");
}

if (faceCardValues[value] !== undefined) {
return faceCardValues[value];
}

const numvalue = Number(value);
if (numvalue >= 2 && numvalue <= 10) {
return numvalue;
}
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -41,6 +64,14 @@ function assertEquals(actualOutput, targetOutput) {
// Examples:
assertEquals(getCardValue("9♠"), 9);

assertEquals(getCardValue("A♥"),11);
assertEquals(getCardValue("10♠"),10);


assertEquals(getCardValue("2♠"), 2);
assertEquals(getCardValue("K♠"), 10);
assertEquals(getCardValue("q♦"), 10);
assertEquals(getCardValue("J♣"), 10);
// Handling invalid cards
try {
getCardValue("invalid");
Expand Down
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 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(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" 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 reflex angles, including boundary cases
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" when (angle < 0 || angle > 360)`, () => {
// Test various invalid angles
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(361)).toEqual("Invalid angle");
expect(getAngleType(0)).toEqual("Invalid angle");
});

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,24 @@
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.
test(`should return True when denominator is positive and less than numerator`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(-1, 2)).toEqual(true );
expect(isProperFraction(1, 10)).toEqual(true);
});

test(`should return false when denominator is less than numerator`, () => {
expect(isProperFraction(22, 20)).toEqual(false);
expect(isProperFraction(11, 10)).toEqual(false);
});

test(`should return false when denominator and numerator are equal`, () => {
expect(isProperFraction(1, 1)).toEqual(false);
expect(isProperFraction(-1, -1)).toEqual(false);
});

// Special case: numerator is zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
expect(isProperFraction(-1, 0)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,34 @@ test(`Should return 11 when given an ace card`, () => {

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
test(`Should return 10 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);
expect(getCardValue("10♣")).toEqual(10);
});
// Face Cards (J, Q, K)
// Invalid Cards
test(`Should return 10 when given a number card`, () => {
expect(getCardValue("K♠")).toEqual(10);
expect(getCardValue("q♦")).toEqual(10);
expect(getCardValue("J♣")).toEqual(10);
});

// Invalid Cards
test(`Should return Invalid Cards when given invalid inputs`, () => {
expect(() => getCardValue("")).toThrow();
expect(() => getCardValue("11")).toThrow();
expect(() => getCardValue("♠10")).toThrow();
expect(() => getCardValue("invalid")).toThrow();
expect(() => getCardValue("♠1")).toThrow();
expect(() => getCardValue("ab")).toThrow();

});
// 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
Expand Down
Loading