-
-
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
CYF-ITP-South Africa | Natalie Patel | Module-Structuring-and-Testing-Data | Sprint 3 #229
base: main
Are you sure you want to change the base?
Changes from 25 commits
539b04e
35898f3
4cd6e85
970d3a3
8bc9668
ecdc094
10a66ec
a2d867e
9cf5a0e
ff0b518
024d1dc
2f88c6a
a117de1
353f076
28ef0a5
780fd32
8b6570e
df48596
e516fc4
5ece594
29b658e
e79bc0a
84c7f64
a4e9a9d
72665a7
5de85c4
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,62 @@ | ||
/* Testing criteria | ||
If the input is 90, the output should be "Right angle" | ||
If the input is less than 90, the output should be "Acute angle" | ||
If the input is more than 90, the output should be "Obtuse angle" | ||
If the input is 180, the output should be "Straight angle" | ||
If the input is more than 180 but less than 360, the output should be "Reflex angle" | ||
If the input is any value outside of these parameters, the output should be "Please enter a valid angle" | ||
*/ | ||
|
||
const {getAngleType} = require ('../../implement/get-angle-type'); | ||
describe("getAngleType function", () => { | ||
//Typical cases | ||
test("should return 'Right angle' when 90 degrees", () => { | ||
expect(getAngleType(90)).toBe("Right angle"); | ||
}); | ||
|
||
test("should return 'Acute angle' when less than 90 degrees", () => { | ||
expect(getAngleType(60)).toBe("Acute angle"); | ||
}); | ||
|
||
test("should return 'Obtuse angle' when more than 90 degrees", () => { | ||
expect(getAngleType(130)).toBe("Obtuse angle"); | ||
}); | ||
|
||
test("should return 'Straight angle' when 180 degrees", () => { | ||
expect(getAngleType(180)).toBe("Straight angle"); | ||
}); | ||
|
||
test("should return 'Reflex angle' when more than 180 but less than 360 degrees", () => { | ||
expect(getAngleType(240)).toBe("Reflex angle"); | ||
}); | ||
|
||
|
||
//Edge cases | ||
test("should return 'Acute angle' when less than 90 degrees", () => { | ||
expect(getAngleType(76)).toBe("Acute angle"); | ||
}); | ||
|
||
test("should return 'Obtuse angle' when more than 90 degrees", () => { | ||
expect(getAngleType(169)).toBe("Obtuse angle"); | ||
}); | ||
|
||
test("should return 'Reflex angle' when more than 180 but less than 360 degrees", () => { | ||
expect(getAngleType(321)).toBe("Reflex angle"); | ||
}); | ||
|
||
|
||
//Invalid cases | ||
test("should return 'Please enter a valid angle' when negative degrees", () => { | ||
expect(getAngleType(-45)).toBe("Please enter a valid angle"); | ||
}); | ||
|
||
test("should return 'Please enter a valid angle' when equal to or greater than 360 degrees", () => { | ||
expect(getAngleType(360)).toBe("Please enter a valid angle"); | ||
}); | ||
|
||
test("should return 'Please enter a valid angle' for inputs that are not numbers", () => { | ||
expect(getAngleType("string")).toBe("Please enter a valid angle"); | ||
expect(getAngleType(null)).toBe("Please enter a valid angle"); | ||
expect(getAngleType(undefined)).toBe("Please enter a valid angle"); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Testing criteria - returning a numerical value for card inputs of different types | ||
The card input will consist of a letter (JKQA), a number (2-10) and an emoji to represent suit (♠♥♦♣) | ||
If the input is not a string, an error must be thrown. | ||
When this card string is entered, it must return a numeric value.Cards with inputs between "2-9" should return numeric equivalent. | ||
The cards "10 J Q K" should return the value of 10. | ||
The card with input "A" should return a default value of 11. | ||
When no suit emoji has been entered, it must return "Please enter a card suit emoji" | ||
All other inputs should throw error "Invalid card rank" | ||
♠♥♦♣ | ||
*/ | ||
|
||
const {getCardValue} = require ('../../implement/get-card-value'); | ||
describe("getCardValue function", () => { | ||
//Invalid cases | ||
|
||
test("should throw error when input is not a string, a recognised card number or face card", () => { | ||
expect(() =>getCardValue(23456789)).toThrow("Invalid card rank or card suit"); | ||
expect(() =>getCardValue("11♠")).toThrow("Invalid card rank or card suit"); //must be numbers 2-10 | ||
expect(() =>getCardValue("-2♦")).toThrow("Invalid card rank or card suit"); //must be positive number | ||
expect(() =>getCardValue("P♥")).toThrow("Invalid card rank or card suit"); //must be valid face card | ||
expect(() =>getCardValue("J💔")).toThrow("Invalid card rank or card suit"); //must be valid emoji suit | ||
expect(() =>getCardValue(null)).toThrow("Invalid card rank or card suit"); //must have an entry | ||
expect(() =>getCardValue(undefined)).toThrow("Invalid card rank or card suit"); //must be a defined entry | ||
|
||
}); | ||
|
||
//Error case for when no suit emoji is entered | ||
test("should return 'Invalid card rank or card suit' when there are less than 2 characters", () => { | ||
expect(() =>getCardValue("4")).toThrow("Invalid card rank or card suit"); | ||
}); | ||
|
||
|
||
//Typical cases | ||
test("should return numerical '5' when string 5 and emoji suit is input", () => { | ||
expect(getCardValue("5♣")).toBe(5); | ||
}); | ||
|
||
test("should return '10' when card input is 10, J, Q, K", () => { | ||
expect(getCardValue("J♠")).toBe(10); | ||
expect(getCardValue("10♦")).toBe(10); | ||
expect(getCardValue("Q♥")).toBe(10); | ||
expect(getCardValue("K♣")).toBe(10); | ||
expect(getCardValue("10♠")).toBe(10); | ||
}); | ||
|
||
test("should return '11' when card input is A", () => { | ||
expect(getCardValue("A♥")).toBe(11); | ||
}) | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* Testing criteria | ||
The results should either be true or false to indicate a valid triangle. | ||
If any of the sides = 0 or a value is negative, it must return "false" | ||
If the sum of any two sides is <= the 3rd side, it must return "false" | ||
If the sum of any two sides is greater than the 3rd side, it must return "true" | ||
If string characters and not numbers are input, it must throw an error "Please enter numeric triangle side values" | ||
*/ | ||
|
||
|
||
const {isValidTriangle} = require ('../../implement/is-valid-triangle'); | ||
describe("isValidTriangle function", () => { | ||
|
||
//Error cases | ||
test ("should throw an error 'Please enter numeric triangle side values' when inputs are NaN", () => { | ||
expect(() =>isValidTriangle("triangle")).toThrow("Please enter numeric triangle side values"); | ||
expect(() =>isValidTriangle(null)).toThrow("Please enter numeric triangle side values"); //must have entries | ||
expect(() =>isValidTriangle(undefined)).toThrow("Please enter numeric triangle side values"); //must be defined entries | ||
}); | ||
|
||
//Invalid cases | ||
test ("should return 'false' when values are equal to zero or negative", () => { | ||
expect(isValidTriangle(0, -4, 3)).toBe(false); | ||
expect(isValidTriangle(0, 0, 0)).toBe(false); | ||
}) | ||
|
||
//There is no need to write a test to check for the sum of 2 sides being larger than the 3rd if negative and zero numbers have been handled. | ||
|
||
//Valid cases | ||
test ("should return 'true' when the sum of 2 sides is >= 3rd side", () => { | ||
expect(isValidTriangle(3, 4, 5)).toBe(true); | ||
}) | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Testing criteria | ||
An inputted string character must rotate by 3 and output the corresponding alphabet position. | ||
An inputted number must remain the same. | ||
An inputted uppercase letter must output a rotated uppercase letter. | ||
An inputted lowercase letter must output a rotated lowercase letter. | ||
All inputted letters at the end of the alphabet must wrap around to the beginning. | ||
*/ | ||
|
||
const {rotateCharacter} = require ('../../implement/rotate-char'); | ||
describe("rotateCharacter function", () => { | ||
|
||
//Invalid cases | ||
test("Please enter a number or character", () => { | ||
expect(() =>rotateCharacter(null)).toThrow("Please enter a number or character"); //must have an entry | ||
expect(() =>rotateCharacter(undefined)).toThrow("Please enter a number or character"); //must be an entry | ||
}) | ||
|
||
//Typical cases | ||
test("should return lowercase 'b' + rotation when string b and rotation is input", () => { | ||
expect(rotateCharacter("a", 3)).toBe("d"); | ||
expect(rotateCharacter("c", 4)).toBe("g"); | ||
expect(rotateCharacter("D", 2)).toBe("F"); | ||
expect(rotateCharacter("6", 2)).toBe(6); | ||
expect(rotateCharacter("y", 3)).toBe("b"); | ||
expect(rotateCharacter("Y", 3)).toBe("B"); | ||
}); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* Testing criteria - to determine that the input is a proper fraction, true or false | ||
The input will consist of 2 numbers, numerator and denominator: | ||
If the denominator is 0, it should throw an error: "Denominator cannot be zero" | ||
If the numerator is 0, it should throw an error: "Numerator cannot be zero" | ||
If either the numerator or denominator is a negative number, it must be converted to absolute values. | ||
If the numerator is smaller than the denominator, it is a proper fraction: true | ||
If the numerator is larger than the denominator it is not a proper fraction: false | ||
If the numerator is equal to the denominator, it is not a proper fraction: false | ||
If any other inputs are entered, it should return: "Please enter a valid numerator and/or denominator" | ||
*/ | ||
|
||
const {isProperFraction} = require ('../implement/is-proper-fraction'); | ||
describe("isProperFraction function", () => { | ||
//Invalid cases | ||
|
||
test("should throw error when numerator or denominator is 0", () => { | ||
expect(() => isProperFraction(0, 5)).toThrow("The numerator and/or denominator cannot be zero"); | ||
}); | ||
|
||
test("should throw error when numerator or denominator is 0", () => { | ||
expect(() => isProperFraction(5, 0)).toThrow("The numerator and/or denominator cannot be zero"); | ||
}); | ||
|
||
test("should throw error when numerator or denominator is 0", () => { | ||
expect(() => isProperFraction(0, 0)).toThrow("The numerator and/or denominator cannot be zero"); | ||
}); | ||
|
||
test("should return 'Please enter a valid numerator and/or denominator' for inputs that are not numbers", () => { | ||
expect(isProperFraction("string")).toBe("Please enter a valid numerator and/or denominator"); | ||
expect(isProperFraction(null)).toBe("Please enter a valid numerator and/or denominator"); | ||
expect(isProperFraction(undefined)).toBe("Please enter a valid numerator and/or denominator"); | ||
}); | ||
//Typical cases | ||
test("should return 'True' when numerator is smaller than denominator", () => { | ||
expect(isProperFraction(2, 5)).toBe("True"); | ||
}); | ||
|
||
test("should return 'False' when numerator is larger than denominator", () => { | ||
expect(isProperFraction(5, 2)).toBe("False"); | ||
}); | ||
|
||
test("should return 'False' when numerator is equal to the denominator", () => { | ||
expect(isProperFraction(2, 2)).toBe("False"); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,53 @@ | |
// 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." | ||
|
||
function getCardValue(card) { | ||
|
||
//The string input must consist of 2 characters if the emoji suit is to be included | ||
if (typeof card !="string" || card.length < 2) { | ||
throw new Error("Invalid card rank or card suit"); | ||
} | ||
|
||
//The input has to be separated into the rank and suit emoji so that they can be handled separately | ||
let rank = card.slice(0, -1); //If there are 2 characters in the string, this slices just the first character | ||
let suit = card.slice(-1); //This isolates the suit emoji | ||
|
||
//Define valid suits and face cards | ||
let validSuits = ["♠", "♥", "♦", "♣"]; | ||
let validFaceCards = ["J", "Q", "K", "A"]; | ||
|
||
//Instructing the only suit emojis that are valid. When the condition is true (the suit input is NOT in the valid array) it throws an error. | ||
|
||
if (!validSuits.includes(suit)) { | ||
throw new Error("Invalid card rank or card suit"); | ||
} | ||
|
||
//Handling when card inputs are 2-9 | ||
if (rank >= "2" && rank <= "9") { | ||
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. TodoCan you also check if |
||
return parseInt(rank, 10); //parseInt parses a string and returns the first integer, 10 indicates decimal radix for numbers 0-9 | ||
} | ||
|
||
//Handling when card input is 10 | ||
if (rank === "10") { | ||
return 10; | ||
} | ||
|
||
//Handling face cards worth 10 and the Ace worth 11 | ||
if (validFaceCards.includes(rank)) { | ||
if (rank === "A") { | ||
return 11; | ||
} | ||
return 10; //When not the A but the other face cards J, Q, K | ||
} | ||
|
||
//If none of the valid rank parameters are matched, throw an error | ||
{ | ||
throw new Error("Invalid card rank or card suit"); | ||
} | ||
} | ||
|
||
module.exports = {getCardValue}; | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,30 @@ | |
// 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) { | ||
//Check if numerator OR denominator is 0, throw an error | ||
if (numerator === 0 || denominator === 0) { | ||
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. 0 can be considered a fraction. So numerator should be allowed to be 0. |
||
throw new Error("The numerator and/or denominator cannot be zero"); | ||
} | ||
|
||
//Ensure that numerator and denominator are absolute values | ||
|
||
let num = Math.abs(numerator); | ||
let den = Math.abs(denominator); | ||
|
||
if (num < den) { | ||
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. TodoShould return the Boolean value |
||
} | ||
else if (num > den) { | ||
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. Assuming |
||
return "False" | ||
} | ||
else if (num === den) { | ||
return "False" | ||
} | ||
//When the numerator and denominator are not numbers | ||
else { | ||
return "Please enter a valid numerator and/or denominator"; | ||
} | ||
Comment on lines
+56
to
+59
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. If you want to check for invalid types, you should do the checking at the beginning of the function so that subsequent code in the function won't have to deal with invalid values. |
||
} | ||
module.exports = {isProperFraction}; |
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.
If
angle
is not any of the valid value, then it must be invalid. So anelse
would be suffice.