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 @@ -15,9 +15,30 @@
// execute the code to ensure all tests pass.

function getAngleType(angle) {
// TODO: Implement this function
if (angle > 360)
angleType = "Invalid"
else if (angle > 180){
angleType = "Reflex angle"
}
else if (angle == 180){
angleType = "Straight angle"
}
else if (angle > 90){
angleType = "Obtuse angle"
}
else if ( angle == 90){
angleType = "Right angle"
}
else {
angleType = "Acute angle"
}

return angleType
}

console.log(getAngleType(320));


// The line below allows us to load the getAngleType function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getAngleType;
Expand All @@ -30,7 +51,7 @@ function assertEquals(actualOutput, targetOutput) {
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

assertEquals(getAngleType(320), "Acute angle");
// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles
const right = getAngleType(90);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
// execute the code to ensure all tests pass.

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

// 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(5, 6), true);
assertEquals(isProperFraction(1, 100), true);
assertEquals(isProperFraction(3, 2), false);
assertEquals(isProperFraction(9, 9), false);
assertEquals(isProperFraction(100, 2), false);
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,44 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
const cardSuit = card.slice(card.length - 1);
const cardRank = card.slice(0, card.length - 1);
let cardValue;
if (
["♠", "♥", "♦", "♣"].includes(cardSuit) &&
["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"].includes(
cardRank
)
) {
if (cardRank == "1") {
throw "invalid";
}

switch (cardRank) {
case "A":
return 11;
case "K":
case "Q":
case "J":
return 10;
//case "1": throw RangeError("invalid")
default:
return parseInt(cardRank);
}
} else {
throw "invalid";
}
}

// The line below allows us to load the getCardValue function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getCardValue;

// Helper functions to make our assertions easier to read.
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
// function assertEquals(actualOutput, targetOutput) {
// console.assert(
// actualOutput === targetOutput,
// `Expected ${actualOutput} to equal ${targetOutput}`

// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
assertEquals(getCardValue("9♠"), 9);

// Handling invalid cards
try {
getCardValue("invalid");

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

// What other invalid card cases can you think of?
//invalid card cases can you think of?
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,31 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
expect(getAngleType(89)).toEqual("Acute angle");
});

// Case 2: Right angle
//Case 2: Right angle
test(`should return "Right angle" when (angle === 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(127)).toEqual("Obtuse angle")
expect(getAngleType(179)).toEqual("Obtuse angle")
});

// Case 4: Straight angle
test(`Should return "Straight angle" when ( angle === 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(360>)`,()=>{
expect(getAngleType(361)).toEqual("Invalid")
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,19 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
// Special case: numerator is zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
expect(isProperFraction(0,0)).toEqual(false)
});

// Where the numerator is > than the denominator
test(`should return false when the (numerator > denominator)`,()=>{
expect(isProperFraction(4,2)).toEqual(false)
expect(isProperFraction(100,6)).toEqual(false)
expect(isProperFraction(5,-10)).toEqual(false)
});

// Where the fraction is correct
test(`Should return a true when the (numerator < denominator)`,()=>{
expect(isProperFraction(1,2)).toEqual(true)
expect(isProperFraction(6,8)).toEqual(true)
expect(isProperFraction(-1,2)).toEqual(true)
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,36 @@ const getCardValue = require("../implement/3-get-card-value");
// Case 1: Ace (A)
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
expect(getCardValue("A♣")).toEqual(11);
expect(getCardValue("A♥")).toEqual(11);
expect(getCardValue("A♦")).toEqual(11);
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("7♠")).toEqual(7);
expect(getCardValue("9♣")).toEqual(9);
expect(getCardValue("3♥")).toEqual(3);
expect(getCardValue("5♦")).toEqual(5);
});
// Face Cards (J, Q, K)
// Invalid Cards
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("K♣")).toEqual(10);
expect(getCardValue("Q♥")).toEqual(10);
expect(getCardValue("K♦")).toEqual(10);
});
//Invalid Cards
test("throws on invalid card", () => {
expect(() => {
getCardValue("JJ"); }).toThrow("invalid");
expect(() => {
getCardValue("1♠"); }).toThrow("invalid");
expect(() => {
getCardValue("A1"); }).toThrow("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

Loading