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,19 @@

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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
return numerator > 0 && numerator < denominator; // expression to compare proper fraction
}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,41 @@

function getCardValue(card) {
// TODO: Implement this function
if (card <= 1 && card >= 10 || typeof card !== "string") {
// Here the type of values are checked whether they are string.
return card + " Invalid card";
}

const validRanks = [ // An array of ranks are created here
"A",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
];
const validSuits = ["♠", "♥", "♦", "♣"]; // An array of suits are created here.
const suit = card.slice(-1);
const rank = card.slice(0, -1);

if (!validRanks.includes(rank) || !validSuits.includes(suit)) { //Here the values that are stored in rank and suit are checked whether they are valid are inside the validRank and validSuits arrays.
return card + " Invalid card";
}

if (rank === "A") { // Here the code is testing wether the rank is an Ace.
return 11;
} else if (rank === "J" || rank === "Q" || rank === "K") { // Here the ranks are checked if they are J, Q or K and it returns 10
return 10;
} else { // Lastly any rank between 2 and 10 get checked and the same number of value returned.
return Number(rank);
}
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,38 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

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

// Case 3: Obtuse angles
test(`should return "Obtuse angle" when (angle > 90 && angle < 180)`, () => {
// Test various Obtuse angles, including boundary cases
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 === 180)`, () => {
// Test Obtuse angles.
expect(getAngleType(180)).toEqual("Straight angle");
});

// Case 5: Reflex angles
test(`should return "Reflex angle" when (angle > 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 that are less that are negative number, 0 and numbers that are above 360 degrees.
expect(getAngleType(-9)).toEqual("Invalid angle");
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(450)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,74 @@ 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`, () => {
// Special case 1: numerator is zero
test(`should return false when numerator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

// Special case 2: denominator zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(0, 1)).toEqual(false);
});

// Special case 3: both zero
test(`should return false when both are zero`, () => {
expect(isProperFraction(0, 0)).toEqual(false);
});

// Special case 4: numerator is a negative number
test(`should return false when numerator is negative`, () => {
expect(isProperFraction(-3, 4)).toEqual(false);
});

// Special case 5: denominator is a negative number
test(`should return false when denominator is negative`, () => {
expect(isProperFraction(3, -4)).toEqual(false);
});

// Special case 6: numerator -3 and denominator -4
test(`should return false when numerator -3 and denominator -4`, () => {
expect(isProperFraction(-3, -4)).toEqual(false);
});

// Special case 7: negative equal values
test(`should return false when both negative equal values`, () => {
expect(isProperFraction(-6, -6)).toEqual(false);
});

// Special case 8: equal values
test(`should return false when both are equal`, () => {
expect(isProperFraction(5, 5)).toEqual(false);
});

// Special case 9: numerator is a negative number
test(`should return false when numerator is negative`, () => {
expect(isProperFraction(-3, 4)).toEqual(false);
});

// Non special cases

// Case ase 10: numerator 1 denominator 2
test(`should return false when numerator 1 denominator 2`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

// Case ase 11: numerator 3 denominator 4
test(`should return false when numerator 3 denominator 4`, () => {
expect(isProperFraction(3, 4)).toEqual(true);
});

// Case ase 12: numerator 5 denominator 8
test(`should return false when numerator 5 denominator 8`, () => {
expect(isProperFraction(5, 8)).toEqual(true);
});

// Case ase 13: numerator 7 denominator 4
test(`should return false when 7 denominator 4`, () => {
expect(isProperFraction(7, 4)).toEqual(false);
});

// Case ase 14: numerator 9 denominator 5
test(`should return false when numerator 9 denominator 5`, () => {
expect(isProperFraction(9, 5)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@ test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});

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

// Case 3: Number Cards (2-10)
test(`Should return the card value when given 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);
});

// Case 4: Invalid Cards
test(`Should return invalid cards when given a face card`, () => {
expect(getCardValue("1♦")).toEqual("Invalid card");
expect(getCardValue("10")).toEqual("Invalid card");
expect(getCardValue("AZ")).toEqual("Invalid card");
expect(getCardValue("")).toEqual("Invalid card");
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
Expand All @@ -17,4 +45,3 @@ test(`Should return 11 when given an ace card`, () => {
// 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