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
@@ -1,5 +1,4 @@
// Implement a function getAngleType
//
// When given an angle in degrees, it should return a string indicating the type of angle:
// - "Acute angle" for angles greater than 0° and less than 90°
// - "Right angle" for exactly 90°
Expand All @@ -15,7 +14,24 @@
// execute the code to ensure all tests pass.

function getAngleType(angle) {
// TODO: Implement this function
if (angle <= 0 || angle >= 360) {
return "Invalid 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 if(angle>0 && angle < 90){
return "Acute angle";
}
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -31,7 +47,9 @@ function assertEquals(actualOutput, targetOutput) {
);
}



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

function isProperFraction(numerator, denominator) {
// TODO: Implement this function

return numerator< denominator ;

}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand All @@ -31,3 +33,8 @@ function assertEquals(actualOutput, targetOutput) {

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


assertEquals(isProperFraction(0, 2), true);
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck

// Implement a function getCardValue, when given a string representing a playing card,
/// Implement a function getCardValue, when given a string representing a playing card,
// should return the numerical value of the card.

// A valid card string will contain a rank followed by the suit.
Expand All @@ -22,9 +20,25 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
}
const rank = card.slice(0, -1);



if (rank === "A"){
return 11 ;
}
else if (rank === "J" || rank === "Q" || rank === "K"){
return 10 ;
};


const value = Number(rank);

if( value>=2 && value <= 10 ){
return value};

throw new Error("invalid card!");
}
// 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;
Expand All @@ -39,7 +53,7 @@ function assertEquals(actualOutput, targetOutput) {

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

// Handling invalid cards
try {
Expand All @@ -50,5 +64,22 @@ try {
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}


try {
getCardValue("null");

console.error("Error was not thrown for null card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉")
}

try {
getCardValue("0");

console.error("Error was not thrown for 0 card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉")
}
// What other invalid card cases can you think of?

42 changes: 42 additions & 0 deletions Sprint-3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "week-4-test-example",
"description": "An example application showing how to write tests using the jest framework",
"scripts": {
"test": "jest"
},
"devDependencies": {
"jest": "^29.5.0"
}
}
































Loading