-
-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WM4 | Fatima Safana | Module-Structuring-and-Testing-Data | WEEK6 #235
base: main
Are you sure you want to change the base?
Changes from 10 commits
486d3d4
9b87c50
f2deeaf
72ddd33
859ab24
8895465
0de99a5
7135b39
83adeca
511097e
af80044
891a000
6c83ddf
efc544d
e3d3cab
2246997
114fc6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,23 @@ | |
// Given a card with an invalid rank (neither a number nor a recognized face card), | ||
// When the function is called with such a card, | ||
// Then it should throw an error indicating "Invalid card rank." | ||
|
||
module.exports = getCardValue | ||
|
||
function getCardValue(card) { | ||
const singleDigitRank = Number(card.substring(0,1)); | ||
// const doubleDigitRank = Number(card.substring(0,2)); | ||
|
||
if (card.startsWith("10")){ | ||
return 10; | ||
} else if (singleDigitRank >= 2 && singleDigitRank <=9){ | ||
return singleDigitRank; | ||
} else if (card.startsWith("J") || card.startsWith("Q") || card.startsWith("K")){ | ||
return 10; | ||
} else if (card.startsWith("A")){ | ||
return 11 | ||
} else return "Invalid Cards"; | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you expect from the following function calls?
|
||
console.log(getCardValue("J♠")); | ||
console.log(getCardValue("Z♠")); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const getAngleType = require('./get-angle-type.js'); | ||
const isProperFraction = require('./is-proper-fraction.js'); | ||
const isValidTriangle = require('./is-valid-triangle.js'); | ||
const getCardValue = require('./get-card-value.js'); | ||
|
||
|
||
|
||
test('Given an angle in degrees, return the type of angle', () => { | ||
Comment on lines
+1
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better to use separate |
||
expect(getAngleType(90)).toBe("Right angle"); | ||
expect(getAngleType(45)).toBe("Acute angle"); | ||
expect(getAngleType(160)).toBe("Obtuse angle"); | ||
expect(getAngleType(180)).toBe("Straight angle"); | ||
expect(getAngleType(300)).toBe("Reflex angle"); | ||
}); | ||
Comment on lines
+8
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also test invalid cases. |
||
|
||
test('Given numerator and denominator, return the type of fraction', () => { | ||
expect(isProperFraction(2, 3)).toBe(true); | ||
expect(isProperFraction(5, 3)).toBe(false); | ||
expect(isProperFraction(2, 0)).toBe("error"); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not test also cases where numerator and/or denominator are negative values? |
||
|
||
|
||
test('Given length of sides validate the its a triangle', () => { | ||
expect(isValidTriangle(3, 3, 3)).toBe(true); | ||
expect(isValidTriangle(0, 3, 3)).toBe(false); | ||
expect(isValidTriangle(3, 1, 1)).toBe(false); | ||
}); | ||
|
||
test('Given the card input getCardValue returns correct number for valid ranks ', () => { | ||
expect(getCardValue("5♥")).toBe(5); | ||
expect(getCardValue("K♥")).toBe(10); | ||
expect(getCardValue("A♥")).toBe(11); | ||
expect(getCardValue("z♥")).toBe("Invalid Cards"); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,16 @@ | |
// target output: false | ||
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. | ||
// These acceptance criteria cover a range of scenarios to ensure that the isProperFraction function handles both proper and improper fractions correctly and handles potential errors such as a zero denominator. | ||
|
||
module.exports = isProperFraction | ||
|
||
function isProperFraction(numerator, denominator){ | ||
if (denominator === numerator){ | ||
return false | ||
} else if (denominator === 0 ) { | ||
return "error" | ||
} else if (denominator < numerator) { | ||
return false | ||
} else (denominator > numerator); | ||
return true | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In mathematics, -4/7 == 4/-7, and -4/-7 == 4/7. Hint: If you compute the absolute value of both parameters inside the function first, the code can become much simpler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec does not give an exact specification of acute angle.
By definition, an acute angle cannot be less than or equal to 0.