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

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

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

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

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

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

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
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 @@ -31,3 +36,7 @@ function assertEquals(actualOutput, targetOutput) {

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

assertEquals(isProperFraction(1, 2), "true");
assertEquals(isProperFraction(2, 2), "false");
assertEquals(isProperFraction(7, 4), "false");
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@

function getCardValue(card) {
// TODO: Implement this function
rankCard = card.slice(0, 1);
if (rankCard === "A") {
return 11;
} else if (rankCard === "J" || rankCard === "Q" || rankCard === "K") {
return 10;
} else if (+rankCard >= 2 && +rankCard <= 10) {
return +rankCard;
} else {
return rankCard.toThrow();
}
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -47,6 +57,6 @@ try {

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

// What other invalid card cases can you think of?
// What other invalid card cases can you think of? "13♠"
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,31 @@ 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(145)).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 acute angles, including boundary cases
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(245)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test(`should return "Invalid angle" when (angle > 360)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(90)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});


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

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

// Special case: zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(10, 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 2–10 for their respective card values", () => {
const cards = ["2", "3", "4", "5", "6", "7", "8", "9", "10"];
cards.forEach(card => {
expect(getCardValue(card)).toEqual(Number(card));
});
});

// Face Cards (J, Q, K)
test("Should return 2–10 for their respective card values", () => {
const cards = ["J", "Q", "K"];
cards.forEach(card => {
expect(getCardValue(card)).toEqual(10);
});
});

// Invalid Cards

test("Should return invalid for their respective card values", () => {
const cards = ["L", "M", "N"];
cards.forEach(card => {
expect(getCardValue(card)).toEqual(Number("Invalid"));

});
});



// 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