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,8 +16,34 @@

function getAngleType(angle) {
// TODO: Implement this function
// first converting conditions into variables
const acuteAngle = (angle > 0 && angle < 90);
const rightAngle = (angle === 90);
const obtuseAngle = (angle > 90 && angle < 180);
const straightAngle = (angle === 180);
const reflexAngle = (angle > 180 && angle < 360);
const zeroAngle = (angle === 0);


if (rightAngle) {
// checking for conditions
return "Right angle";
} else if (zeroAngle) {
return "Invalid angle";
}else if (obtuseAngle) {
return "Obtuse angle";
} else if (straightAngle) {
return "Straight angle";
} else if (reflexAngle) {
return "Reflex angle";
} else if (acuteAngle) {
return "Acute angle";
} else if (angle === zeroAngle || angle != acuteAngle || angle != rightAngle || angle != obtuseAngle || angle != straightAngle || angle != reflexAngle) {
return "Invalid angle";
}
}


// 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 @@ -35,3 +61,24 @@ 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(120);
assertEquals(obtuse, "Obtuse angle");

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

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

const invalidAngle1 = getAngleType(360);
assertEquals(invalidAngle1, "Invalid angle");

const invalidAngle2 = getAngleType(0);
assertEquals(invalidAngle2, "Invalid angle");

const invalidAngle3 = getAngleType(-1);
assertEquals(invalidAngle3, "Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (Math.abs(numerator / denominator) < 1) {
return true;// if numerator is smaller than denominator - return true
} else {
return false;//return false if numerator if bigger that denominator
}
}


// The line below allows us to load the isProperFraction function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = isProperFraction;
Expand All @@ -31,3 +36,12 @@ function assertEquals(actualOutput, targetOutput) {

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

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

// Example: 4/2 is not a proper fraction
assertEquals(isProperFraction(4, 2), false);

// Example: 4/4 is not a proper fraction
assertEquals(isProperFraction(4, 4), false);
131 changes: 130 additions & 1 deletion Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,41 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
const suit = ["♠", "♥", "♦", "♣"]; // array with suits
const rank = [
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"A",
"K",
"Q",
"J",
]; // array with ranks
const tenPointsFaceCards = ["K", "Q", "J"]; //cards with value of 10 points

const rank1 = card.slice(0, -1); //takes the firs part of card
const suit1 = card.slice(-1); //takes "suit" secnd part of card
const isCardValid = suit.includes(suit1) && rank.includes(rank1); //conditions where card is considered valid

//conditional statement to check validity of the card
if (!isCardValid) {
throw new Error("Invalid card format");
}

//conditional statements to check what value to return depending on the card value
if (rank1 === "A") {
return 11;
} else if (tenPointsFaceCards.includes(rank1)) {
return 10;
} else {
return Number(rank1);
}
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -39,8 +73,23 @@ 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("K♠"), 10);

assertEquals(getCardValue("Q♠"), 10);

assertEquals(getCardValue("J♠"), 10);

assertEquals(getCardValue("10♣"), 10);

//assertEquals(getCardValue("11♣"), "Invalid card format"); i find that
// this test will not work, because my function is throwing error before the program
// reaches the assertEquals function.

// Handling invalid cards
try {
getCardValue("invalid");
Expand All @@ -52,3 +101,83 @@ try {
}

// What other invalid card cases can you think of?
try {
getCardValue("11♣"); // testing with "11♣" the error will be thrown because "11" is not a valid rank

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

try {
getCardValue("A"); // testing with "A" the error will be thrown because there is no suit

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

try {
getCardValue("10"); // testing with "10" the error will be thrown because there is no suit

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

try {
getCardValue("1♣"); // testing with "1♣" the error will be thrown because "1" is not a valid rank

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

try {
getCardValue("A5"); // testing with "A5" the error will be thrown because "5" is not a valid suit

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

try {
getCardValue("♣6"); // testing with "♣6" the error will be thrown because "6" is not a valid suit and "♣" is not a valid rank

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

try {
getCardValue("@@"); // testing with "@@" the error will be thrown because "@" is not a valid rank or suit

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

try {
getCardValue("-6♣"); // testing with "-6♣" (negative number) the error will be thrown because "-" is not a valid rank

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

try {
getCardValue(""); // testing with "" the error will be thrown because "" is not a valid card

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,43 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
expect(getAngleType(89.9)).toEqual("Acute angle");
});

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

// Case 3: Obtuse angles
test(`should return "Obtuse angle" when (90 > angle > 180)`, () => {
//test various obtuse cases, including border cases
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(120)).toEqual("Obtuse angle");
expect(getAngleType(179.9)).toEqual("Obtuse angle");
});
// Case 4: Straight angle
test(`should return "Straight angle" when (angle ==== 180)`, () => {
//test for straight angle at 180 degrees
expect(getAngleType(180)).toEqual("Straight angle");
});

// Case 5: Reflex angles
test(`should return "Reflex angle" when (180 > angle > 360)`, () => {
//test for various reflex angle between 181 and 359 degrees
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(210)).toEqual("Reflex angle");
expect(getAngleType(359.9)).toEqual("Reflex angle");
});
// Case 6: Invalid angles
test(`should return "Invalid angle" when (angle >= 0 || angle >= 360 || angle === isNan())`, () => {
//tests for various invalid angles
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(-10)).toEqual("Invalid angle");
expect(getAngleType(380)).toEqual("Invalid angle");
expect(getAngleType(NaN)).toEqual("Invalid angle");
});


Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,62 @@ 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
// Special case: denominator is zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

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

// numerator and denominator are both zero
test(`should return false when numerator and denominator are both zero`, () => {
expect(isProperFraction(0, 0)).toEqual(false);
});

// negative numerator and positive denominator
test(`should return true when numerator is negative and denominator is positive`, () => {
expect(isProperFraction(-1, 2)).toEqual(true);
});

// positive numerator, negative denominator
test(` should return false when numerator is positive and denominator is negative`, () => {
expect(isProperFraction(1, -2)).toEqual(true);
})

//negative numerator and denominator where numerator is smaller than denominator
test(`should return true when numerator is negative and denominator is negative and numerator is smaller than denominator`, () => {
expect(isProperFraction(-1, -2)).toEqual(true);
});

//negative numerator and denominator where numerator is bigger than denominator
test(`should return false when numerator is negative and denominator is negative and numerator is bigger than denominator`, () => {
expect(isProperFraction(-2, -1)).toEqual(false);
});

//positive numerator and denominator where numerator is smaller
test(`should return true when numerator is smaller`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

// positive numerator and denominator, numerator is larger
test(`should return false when numerator is larger`, () => {
expect(isProperFraction(4, 2)).toEqual(false);
});

// equal numerator and denominator
test(`should return false when numerator and denominator are equal`, () => {
expect(isProperFraction(4, 4)).toEqual(false);
});

// numerator and denominator are both floating point numbers, numerator is smaller
test(`should return true when numerator and denominator are both floating point numbers and numerator is smaller`, () => {
expect(isProperFraction(1.5, 2.5)).toEqual(true);
});

// numerator and denominator are both floating point numbers, numerator is larger
test(`should return false when numerator and denominator are both floating point numbers and numerator is larger`, () => {
expect(isProperFraction(2.5, 1.5)).toEqual(false);
});
Loading
Loading