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";
}
Comment on lines +15 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you lookup if -1/-2, 1/-2, -1/2, -1/0 are considered proper fractions, and then update
your implementation and tests accordingly?

}

// 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();
}
}
Comment on lines 24 to 36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The function is expected to also validate if the last character is a valid suit character.

  • In JavaScript, strings that represent valid numeric literals in the language can be safely converted to equivalent numbers. For examples, "0x02", "2.1", or "0002".
    Does your function return the value you expected from each of the following function calls?

getCardValue("0x02♠");
getCardValue("2.1♠");
getCardValue("0002♠");


// 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");
});
Comment on lines +41 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The condition about invalid angle is not quite correct.

  • Can your function pass this test?

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);
});
Comment on lines +14 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description of the tests do not match the tests being carried out.


// 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"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A valid card should also have a valid suit character.
For example, "2♥". "2" should be considered an invalid card.

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"));

});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Test descriptions do not match the tests being carried out.

  • The function is expected to throw an error when the given card is invalid.

    • Suggestion: Lookup how to throw error in JS, and follow the links line 44 to find out how to check if a function can throw an errors as expected in Jest.




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