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 @@ -35,3 +53,13 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");
const acute = getAngleType (45);
assertEquals(acute, "Acute angle");
const obtuse = getAngleType (110);
assertEquals(obtuse, "Obtuse angle");
const straight = getAngleType (180);
assertEquals(straight, "Straight angle");
const reflex = getAngleType (270);
assertEquals(reflex, "Reflex angle");
const invalid = getAngleType (400);
assertEquals(invalid, "Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

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

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

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(2,1),false);
assertEquals(isProperFraction(1,1),false);
assertEquals(isProperFraction(0,1),false);
assertEquals(isProperFraction(1,-2),false);
assertEquals(isProperFraction(-1,2),false);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,44 @@

function getCardValue(card) {
// TODO: Implement this function
if (card === "A♠" || card === "A♥" || card === "A♦" || card === "A♣") {
return 11;
}
else if (card === "J♠" || card === "J♥" || card === "J♦" || card === "J♣" ||
card === "Q♠" || card === "Q♥" || card === "Q♦" || card === "Q♣" ||
card === "K♠" || card === "K♥" || card === "K♦" || card === "K♣") {
return 10;
}
else if (card === "2♠" || card === "2♥" || card === "2♦" || card === "2♣") {
return 2;
}
else if (card === "3♠" || card === "3♥" || card === "3♦" || card === "3♣") {
return 3;
}
else if (card === "4♠" || card === "4♥" || card === "4♦" || card === "4♣") {
return 4;
}
else if (card === "5♠" || card === "5♥" || card === "5♦" || card === "5♣") {
return 5;
}
else if (card === "6♠" || card === "6♥" || card === "6♦" || card === "6♣") {
return 6;
}
else if (card === "7♠" || card === "7♥" || card === "7♦" || card === "7♣") {
return 7;
}
else if (card === "8♠" || card === "8♥" || card === "8♦" || card === "8♣") {
return 8;
}
else if (card === "9♠" || card === "9♥" || card === "9♦" || card === "9♣") {
return 9;
}
else if (card === "10♠" || card === "10♥" || card === "10♦" || card === "10♣") {
return 10;
}
else {
throw new Error("Invalid card");
}
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -40,6 +78,9 @@ 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("J♦"), 10);
assertEquals(getCardValue("10♣"), 10);

// Handling invalid cards
try {
Expand All @@ -50,3 +91,7 @@ try {
} catch (e) {}

// What other invalid card cases can you think of?
try {
getCardValue("1♠");
console.error("Error was not thrown for invalid card");}
catch (e) {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,30 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// 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(120)).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" when angle is outside the valid range`, () => {
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(400)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,27 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});
test('should return false when numerator is zero', () => {
expect(isProperFraction(0, 1)).toEqual(false);
});
test('should return false when both numerator and denominator are zero', () => {
expect(isProperFraction(0, 0)).toEqual(false);
});
test('should return false when numerator is negative', () => {
expect(isProperFraction(-1, 2)).toEqual(false);
});
test('should return false when denominator is negative', () => {
expect(isProperFraction(1, -2)).toEqual(false);
});
test('should return false when both numerator and denominator are negative', () => {
expect(isProperFraction(-1, -2)).toEqual(false);
});
test('should return true if numerator is less than denominator and both are positive', () => {
expect(isProperFraction(1, 2)).toEqual(true);
});
test('should return false if numerator is greater than denominator and both are positive', () => {
expect(isProperFraction(2, 1)).toEqual(false);
});
test('should return false if numerator is equal to denominator and both are positive', () => {
expect(isProperFraction(1, 1)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ const getCardValue = require("../implement/3-get-card-value");
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});
test(`Should return 10 when given a face card`, () => {
expect(getCardValue("J♦")).toEqual(10);
expect(getCardValue("Q♥")).toEqual(10);
expect(getCardValue("K♣")).toEqual(10);
});
test(`Should return the numeric 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);
expect(getCardValue("10♠")).toEqual(10);
});
test ('Should return invalid card error when given invalid cards', () => {
expect(() => getCardValue("1♠")).toThrow();
expect(() => getCardValue("11♥")).toThrow();
});


// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
Expand Down