Skip to content
Closed
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
8 changes: 4 additions & 4 deletions Sprint-3/1-implement-and-rewrite-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ to choose test values that thoroughly test a function.

## 1 Implement solutions

In the `implement` directory you've got a number of functions you'll need to implement.

Here is a recommended order:

1. `1-get-angle-type.js`In the `implement` directory you've got a number of functions you'll need to implement.
For each function, you also have a number of different cases you'll need to check for your function.

Write your assertions and build up your program case by case. Don't rush to a solution. The point of these assignments is to learn how to write assertions and build up a program step by step.

Here is a recommended order:

1. `1-get-angle-type.js`
2. `2-is-proper-fraction.js`
3. `3-get-card-value.js`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,30 @@
// execute the code to ensure all tests pass.

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 @@ -33,5 +56,24 @@ function assertEquals(actualOutput, targetOutput) {

// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles
const right = getAngleType(90);
let invalid = getAngleType(0);
assertEquals(invalid, "Invalid angle");
let acute = getAngleType(1);
assertEquals(acute, "Acute angle");
acute = getAngleType(89);
assertEquals(acute, "Acute angle");
let right= getAngleType(90);
assertEquals(right, "Right angle");
let obtuse = getAngleType(91);
assertEquals(obtuse, "Obtuse angle");
obtuse = getAngleType(179);
assertEquals(obtuse, "Obtuse angle");
const straight = getAngleType(180);
assertEquals(straight, "Straight angle");
let reflex = getAngleType(181);
assertEquals(reflex, "Reflex angle");
reflex = getAngleType(359);
assertEquals(reflex, "Reflex angle");
invalid = getAngleType(400);
assertEquals(invalid, "Invalid angle");

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@
// execute the code to ensure all tests pass.

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

}
else
{
return false;
}
}

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

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(5, 4), false);
assertEquals(isProperFraction(3, 3), false);
assertEquals(isProperFraction(0, 5), true);
assertEquals(isProperFraction(1, 0), false);
assertEquals(isProperFraction(-3, 2), true);
assertEquals(isProperFraction(2, -5), false);
assertEquals(isProperFraction(-2, -3), false);
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,37 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
if(typeof card !== "string" || card.length<2)
{
throw new Error("Invalid card");
}
const suit = card.slice(-1);
const rank = card.slice(0, -1);

const validSuits = ["♠", "♥", "♦", "♣"];
const validRanks = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"];

if(!validSuits.includes(suit) || !validRanks.includes(rank))
{
throw new Error("Invalid card");
}
else if (rank == "A")
{
return 11;
}
else if (["J","Q","K"].includes(rank))
{
return 10
}
else {
return Number(rank);
}
}

// 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;
module.exports = getCardValue;

// Helper functions to make our assertions easier to read.
function assertEquals(actualOutput, targetOutput) {
console.assert(
Expand All @@ -40,13 +64,40 @@ 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("10♥"), 10);

// Handling invalid cards
try {
getCardValue("invalid");
getCardValue("11♠");
console.error("Error was not thrown for invalid card");
} catch (e) {}
try {
getCardValue("A?");
console.error("Error was not thrown for invalid card");
} catch (e) {}
try {
getCardValue("A");

// This line will not be reached if an error is thrown as expected

console.error("Error was not thrown for invalid card");
} catch (e) {}
try {
getCardValue("10");


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

// What other invalid card cases can you think of?
//try {
//getCardValue("AA");
//console.error("Error was not thrown for invalid card");
//} catch (e) {}
//try {
//getCardValue("1♠");


//console.error("Error was not thrown for invalid card");
//} catch (e) {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,28 @@ const getAngleType = require("../implement/1-get-angle-type");
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(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});
test(`should return "Right angle" when (angle = 90)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(90)).toEqual("Right angle");
});
test(`should return"Obtuse angle" when (90 < angle< 180)`, ()=>{
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});
test(`should return "Straight angle" when ( angle = 180)`,()=>{
expect(getAngleType(180)).toEqual("Straight angle");
});
test(`should return "Reflex angle" when (180 < angle <360)`, ()=>{
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");

});
test(`should return "invalid angle when angles outside the valid range`, ()=>{
expect(getAngleType(0)).toEqual("Invalid angle")
})

// Case 2: Right angle
// Case 3: Obtuse angles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,24 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});
test(`Should return true when numerator is zero`, ()=>{
expect(isProperFraction(0, 5)).toEqual(true);
});
test(`should return true when denominator is greater than numerator`, () =>{
expect(isProperFraction(1, 2)).toEqual(true);
});
test(`should return false when numerator is greater than denominator`, ()=> {
expect(isProperFraction(5, 4)).toEqual(false);
});
test(`should return false when numerator is equals to denominator`, ()=>{
expect(isProperFraction(3, 3)).toEqual(false);
});
test(`should return true when denominator is greater than negative numerator`, ()=>{
expect(isProperFraction(-3, 2)).toEqual(true);
});
test(`should return false when numerator is greater than denominator`, ()=> {
expect(isProperFraction(2, -5)).toEqual(false);
});
test(`should return false when negative numerator is greater than negative denominator`, ()=> {
expect(isProperFraction(-2, -3)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,27 @@ const getCardValue = require("../implement/3-get-card-value");
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});

test(`should return 9 when given a 9♠ card`,()=>{
expect(getCardValue("9♠")).toEqual(9);
});
test (`should return 10 when given a face card K♦`, ()=>{
expect(getCardValue("K♦")).toEqual(10);
});
test(`should return 10 when given a 10`, ()=>{
expect(getCardValue("10♥")).toEqual(10);
});
test(`should throw error for invalid Ranks`, ()=>{
expect(()=> getCardValue("11♠")).toThrow();
});
test(`should throw error for invalid Suits`, ()=>{
expect(()=> getCardValue("A?")).toThrow();
});
test(`should throw error for missing Suits`,()=>{
expect(()=> getCardValue("A")).toThrow();
});
test(`should throw error for non String input`, ()=>{
expect(()=> getCardValue("10")).toThrow();
});
// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
Expand Down
13 changes: 0 additions & 13 deletions Sprint-3/2-practice-tdd/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions Sprint-3/2-practice-tdd/count.js

This file was deleted.

24 changes: 0 additions & 24 deletions Sprint-3/2-practice-tdd/count.test.js

This file was deleted.

5 changes: 0 additions & 5 deletions Sprint-3/2-practice-tdd/get-ordinal-number.js

This file was deleted.

20 changes: 0 additions & 20 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js

This file was deleted.

5 changes: 0 additions & 5 deletions Sprint-3/2-practice-tdd/repeat-str.js

This file was deleted.

32 changes: 0 additions & 32 deletions Sprint-3/2-practice-tdd/repeat-str.test.js

This file was deleted.

9 changes: 0 additions & 9 deletions Sprint-3/3-dead-code/README.md

This file was deleted.

Loading
Loading