-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
West Midlands | Alireza Seifi Shalamzari | Module-Structuring-and-Testing-Data | Week 3 #231
base: main
Are you sure you want to change the base?
Changes from all commits
b089720
89e68e6
70e370f
89e8ce2
1a80784
10fe203
986f549
c15e74f
274d23d
3f06364
874674b
46d9d7f
5f08647
b918d45
5d65a76
c3e8cb9
8bb658a
c986982
031f86f
543e9be
315c043
c37f61c
e7ec383
baedcfc
15ebf6e
a6d5d9e
f1b8d0d
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// get-angle-type.test.js | ||
const getAngleType = require('./get-angle-type'); | ||
|
||
describe('getAngleType', () => { | ||
test('should return "Right angle" for 90 degrees', () => { | ||
expect(getAngleType(90)).toBe("Right angle"); | ||
}); | ||
|
||
test('should return "Acute angle" for angles less than 90 degrees', () => { | ||
expect(getAngleType(45)).toBe("Acute angle"); | ||
expect(getAngleType(0)).toBe("Acute angle"); | ||
}); | ||
|
||
test('should return "Obtuse angle" for angles greater than 90 and less than 180 degrees', () => { | ||
expect(getAngleType(135)).toBe("Obtuse angle"); | ||
}); | ||
|
||
test('should return "Straight angle" for 180 degrees', () => { | ||
expect(getAngleType(180)).toBe("Straight angle"); | ||
}); | ||
|
||
test('should return "Reflex angle" for angles greater than 180 and less than 360 degrees', () => { | ||
expect(getAngleType(225)).toBe("Reflex angle"); | ||
expect(getAngleType(359)).toBe("Reflex angle"); | ||
}); | ||
|
||
test('should return "Invalid angle" for angles less than 0 or greater than or equal to 360', () => { | ||
expect(getAngleType(-45)).toBe("Invalid angle"); | ||
expect(getAngleType(360)).toBe("Invalid angle"); | ||
expect(getAngleType(400)).toBe("Invalid angle"); | ||
}); | ||
|
||
test('should return "Invalid angle" for non-numeric inputs', () => { | ||
expect(getAngleType("45")).toBe("Invalid angle"); | ||
expect(getAngleType(null)).toBe("Invalid angle"); | ||
expect(getAngleType(undefined)).toBe("Invalid angle"); | ||
expect(getAngleType(true)).toBe("Invalid angle"); | ||
expect(getAngleType(false)).toBe("Invalid angle"); | ||
expect(getAngleType(NaN)).toBe("Invalid angle"); | ||
expect(getAngleType(Infinity)).toBe("Invalid angle"); | ||
expect(getAngleType(-Infinity)).toBe("Invalid angle"); | ||
expect(getAngleType("hello")).toBe("Invalid angle"); | ||
expect(getAngleType([1, 2, 3])).toBe("Invalid angle"); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,24 @@ | |
// 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. | ||
function isProperFraction(numerator, denominator) { | ||
// Get the absolute values of numerator and denominator | ||
const absNumerator = Math.abs(numerator); | ||
const absDenominator = Math.abs(denominator); | ||
|
||
// Check if the denominator is zero and throw an error if it is | ||
if (absDenominator === 0) { | ||
throw new Error("Denominator cannot be zero"); | ||
} | ||
|
||
// Check if the absolute value of the numerator is less than the absolute value of the denominator | ||
return absNumerator < absDenominator; | ||
} | ||
|
||
//Testing the function | ||
console.log(isProperFraction(2, 3)); //should return True | ||
console.log(isProperFraction(5, 2)); //should return False | ||
console.log(isProperFraction(-4, 7)); //should 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 commentThe reason will be displayed to describe this comment to others. Learn more. I added a part which first make absolute numbers then check them |
||
console.log(isProperFraction(3, 3)); //should return False | ||
console.log(isProperFraction(3, 0)); //should throw an error | ||
|
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.
Todo
This check is not solid enough.
You can test your function by calling
getCardValue("23♠")
orgetCardValue("899♠")
to see what they return.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.
I did work on this and I found a solution!
I added a set of valid ranks so only the valid ones can return an actual value