Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e4e4db0
write code for the angle conditions checking
vmoratti Jul 6, 2026
cd130fb
add tests for 45 and 120
vmoratti Jul 6, 2026
cfd5e9e
add tests for 180 and 270
vmoratti Jul 6, 2026
c3e2ecf
add 360, 0, -1, tests
vmoratti Jul 9, 2026
a68ed34
write code and tests
vmoratti Jul 9, 2026
f07846c
write code to check conditions
vmoratti Jul 9, 2026
191b890
rewrite main function
vmoratti Jul 10, 2026
9c498b6
add tests for all cases
vmoratti Jul 10, 2026
7e7fe32
add empty string test
vmoratti Jul 10, 2026
d6568e7
write test for the right and obtuse angle
vmoratti Jul 12, 2026
d23d3a6
add straight angle, and reflex angle tests
vmoratti Jul 12, 2026
75b5e83
add invalid test cases
vmoratti Jul 12, 2026
0fdd272
add floating point test cases
vmoratti Jul 12, 2026
c278f25
add test for zero numerator
vmoratti Jul 12, 2026
3448413
add negative tests
vmoratti Jul 12, 2026
1433508
add ablolute methode to function
vmoratti Jul 13, 2026
e81fc42
add tests
vmoratti Jul 13, 2026
08cc18c
add negative numbers tests
vmoratti Jul 13, 2026
366cb56
add positive tests
vmoratti Jul 13, 2026
2ef1a20
add final tests
vmoratti Jul 13, 2026
55113f3
add tests for number 2 and 10
vmoratti Jul 13, 2026
0527fe3
add tests for J, Q, K
vmoratti Jul 13, 2026
7e5f326
add invalid card tests
vmoratti Jul 14, 2026
cdef481
add more number tests
vmoratti Jul 14, 2026
376602f
write countChar() function
vmoratti Jul 16, 2026
c17d0e6
write no occurrences test
vmoratti Jul 16, 2026
6f7cc83
write a complete function to check for endings
vmoratti Jul 16, 2026
d5357cd
correct function
vmoratti Jul 16, 2026
88ecb07
add tests for numbers ending on 2, and on 3
vmoratti Jul 16, 2026
b19e7d6
add tests
vmoratti Jul 16, 2026
cd93a70
write function
vmoratti Jul 16, 2026
7715334
change conditions in the function
vmoratti Jul 16, 2026
3ec2172
add tests for 1 and 0 zero
vmoratti Jul 16, 2026
3301bc3
write test with negative number
vmoratti Jul 17, 2026
cc6f9a3
remove dead code
vmoratti Jul 17, 2026
a36afa4
Implement getAngleType function placeholder
vmoratti Jul 17, 2026
9bfe6a9
Implement isProperFraction function
vmoratti Jul 17, 2026
41fbd9c
Add placeholder for getCardValue function
vmoratti Jul 17, 2026
4e8d8cc
Update test for acute angle boundary condition
vmoratti Jul 17, 2026
c951858
Update tests for isProperFraction function
vmoratti Jul 17, 2026
dacdb0f
add comment in the right place
vmoratti Jul 17, 2026
338d2f0
delete line 7
vmoratti Jul 17, 2026
e3db167
add line after line 10
vmoratti Jul 17, 2026
11e3132
Clean up comments in card value test
vmoratti Jul 17, 2026
52c9e2e
Add implementation instructions for repeatStr
vmoratti Jul 17, 2026
7994451
add blank line 16
vmoratti Jul 17, 2026
7bf6788
Comment out return statement for '1st' in function
vmoratti Jul 17, 2026
a8bbcc6
Update comment to clarify implementation requirements
vmoratti Jul 17, 2026
bf23461
Update comment to clarify implementation requirements
vmoratti Jul 17, 2026
1a86e1f
Clarify repeatStr function implementation requirements
vmoratti Jul 17, 2026
54d7a27
Add comments to countChar function
vmoratti Jul 17, 2026
33e8423
Update comment to clarify implementation requirements
vmoratti Jul 17, 2026
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,7 +15,32 @@
// execute the code to ensure all tests pass.

function getAngleType(angle) {
// TODO: Implement this function
// 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.
Expand All @@ -35,3 +60,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 @@ -12,8 +12,14 @@

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 +37,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);
130 changes: 130 additions & 0 deletions 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 @@ -23,6 +23,41 @@

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 +74,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 +102,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 @@ -14,7 +14,40 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// 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 @@ -5,6 +5,63 @@ 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
test(`should return true when numerator is zero `, () => {
expect(isProperFraction(0, 2)).toEqual(true);
});

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



// 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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,49 @@ test(`Should return 11 when given an ace card`, () => {
// Face Cards (J, Q, K)
// Invalid Cards

// Case 2: Number cards (2-9)
// 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
test(`Should return corresponding number 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);
});

// Case 3: Number cards (10)
test(`Should return 10 when given a 10 card`, () => {
expect(getCardValue("10♠")).toEqual(10);
});

// Case 4: Face cards (J, Q, K)
test(`Should return 10 when given a J card`, () => {
expect(getCardValue("J♠")).toEqual(10);
});

// Case 5: Face cards (J, Q, K)
test(`Should return 10 when given a Q card`, () => {
expect(getCardValue("Q♠")).toEqual(10);
});

// Case 6: Face cards (J, Q, K)
test(`Should return 10 when given a K card`, () => {
expect(getCardValue("K♠")).toEqual(10);
});

// Invalid cases
test(`should throw an error with message "Invalid card format" when given invalid card`, () => {
expect(() => getCardValue("1♠")).toThrow("Invalid card format");
expect(() => getCardValue("11♥")).toThrow("Invalid card format");
expect(() => getCardValue("A1")).toThrow("Invalid card format");
expect(() => getCardValue("1A")).toThrow("Invalid card format");
expect(() => getCardValue("♣10")).toThrow("Invalid card format");
expect(() => getCardValue("$$")).toThrow("Invalid card format");
expect(() => getCardValue("-5♣")).toThrow("Invalid card format");
});

Loading
Loading