generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 221
CYF-ITP-South Africa | Rashaad Ebrahim | Module-Structuring-and-Testing-Data | Week 3 #225
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
Closed
Rashaad-Ebrahim
wants to merge
18
commits into
CodeYourFuture:main
from
Rashaad-Ebrahim:sprint-3-exercises
Closed
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0655e6d
implement section complete
Rashaad-Ebrahim 35a010c
Installed Jest, package.json and package-lock.json added.
Rashaad-Ebrahim 45701b5
Jest test implemented for get-angle-type.js, with get-angle-type.test.js
Rashaad-Ebrahim a9860cf
getCardValue function updated to chheck if input is valid string.
Rashaad-Ebrahim f227570
isProperFraction function updated and isProperFraction jest tests cre…
Rashaad-Ebrahim 548c85e
isValidTriangle function updated and tests created.
Rashaad-Ebrahim 4775eb1
rotateCharacter function updated and tests created.
Rashaad-Ebrahim 3557a56
cardValidator function implemented and tests created.
Rashaad-Ebrahim 7c8723e
countChar function implemented and tests created.
Rashaad-Ebrahim f7407c9
getOrdinalNumber function implemented and tests created.
Rashaad-Ebrahim 0fb1ed7
isPrime function implemented and tests created.
Rashaad-Ebrahim c0c428c
validatePassword function created and tests created.
Rashaad-Ebrahim d4ba005
repeat function implemeted and tests created.
Rashaad-Ebrahim d3efba7
investigate>find exercise complete.
Rashaad-Ebrahim ad65cb9
console.logs removed from files after running tests.
Rashaad-Ebrahim bc8f1b9
Code updated a suggested on PR
Rashaad-Ebrahim fb6492b
minor changes from feedback from PR
Rashaad-Ebrahim 698e98c
refactored code.
Rashaad-Ebrahim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const getAngleType = require("./get-angle-type"); | ||
|
||
test('When the angle is less than 90 degrees, the function should return "Acute angle"', () => { | ||
expect(getAngleType(69)).toBe("Acute angle"); | ||
}); | ||
|
||
test('When the angle is exactly 90 degrees, the function should return "Right angle"', () => { | ||
expect(getAngleType(90)).toBe("Right angle"); | ||
}); | ||
|
||
test('When the angle is greater than 90 degrees and less than 180 degrees, the function should return "Obtuse angle"', () => { | ||
expect(getAngleType(169)).toBe("Obtuse angle"); | ||
}); | ||
|
||
test('When the angle is exactly 180 degrees, the function should return "Straight angle"', () => { | ||
expect(getAngleType(180)).toBe("Straight angle"); | ||
}); | ||
|
||
test('When the angle is greater than 180 degrees and less than 360 degrees, the function should return "Reflex angle"', () => { | ||
Rashaad-Ebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
expect(getAngleType(246)).toBe("Reflex angle"); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
const getCardValue = require("./get-card-value"); | ||
|
||
describe("getCardValue tests", () => { | ||
describe("Acceptance criteria", () => { | ||
test("Handle Number Cards (2-10)", () => { | ||
expect(getCardValue("2♠")).toBe(2); | ||
expect(getCardValue("3♣")).toBe(3); | ||
expect(getCardValue("4♥")).toBe(4); | ||
expect(getCardValue("5♦")).toBe(5); | ||
expect(getCardValue("6♠")).toBe(6); | ||
expect(getCardValue("7♣")).toBe(7); | ||
expect(getCardValue("8♥")).toBe(8); | ||
expect(getCardValue("9♦")).toBe(9); | ||
expect(getCardValue("10♠")).toBe(10); | ||
}); | ||
|
||
test("Handle Face Cards (J, Q, K)", () => { | ||
expect(getCardValue("K♣")).toBe(10); | ||
expect(getCardValue("Q♥")).toBe(10); | ||
expect(getCardValue("J♦")).toBe(10); | ||
}); | ||
|
||
test("Handle Ace (A)", () => { | ||
expect(getCardValue("A♠")).toBe(11); | ||
expect(getCardValue("A♣")).toBe(11); | ||
expect(getCardValue("A♥")).toBe(11); | ||
expect(getCardValue("A♦")).toBe(11); | ||
}); | ||
|
||
test("Handle Invalid Cards", () => { | ||
expect(getCardValue("w♣")).toBe("Invalid card rank."); | ||
expect(getCardValue("W♦")).toBe("Invalid card rank."); | ||
expect(getCardValue("0♠")).toBe("Invalid card rank."); | ||
expect(getCardValue("14♥")).toBe("Invalid card rank."); | ||
expect(getCardValue("?♣")).toBe("Invalid card rank."); | ||
expect(getCardValue("♣")).toBe("Invalid card rank."); | ||
expect(getCardValue(" ♦")).toBe("Invalid card rank."); | ||
expect(getCardValue("card♣")).toBe("Invalid card rank."); | ||
}); | ||
}); | ||
|
||
describe("Other tests", () => { | ||
test("Handle lowercase", () => { | ||
expect(getCardValue("a♠")).toBe(11); | ||
expect(getCardValue("k♣")).toBe(10); | ||
expect(getCardValue("q♥")).toBe(10); | ||
expect(getCardValue("j♦")).toBe(10); | ||
}); | ||
|
||
test("Handle expression as argument", () => { | ||
expect(getCardValue("2♣ two of clubs".split(" ")[0])).toBe(2); | ||
}); | ||
}); | ||
|
||
describe("Random data", () => { | ||
test.each([ | ||
["6♣", 6], | ||
["q♦", 10], | ||
["10♠", 10], | ||
["4♣", 4], | ||
])("Valid values: The %s should be %i ", (input, expected) => { | ||
expect(getCardValue(input)).toBe(expected); | ||
}); | ||
|
||
test.each([ | ||
["/3/4♣", "Invalid card rank."], | ||
["@@$$♦", "Invalid card rank."], | ||
["00000♠", "Invalid card rank."], | ||
["", "Invalid card rank."], | ||
["[]{}♣", "Invalid card rank."], | ||
["let♦", "Invalid card rank."], | ||
["const♠", "Invalid card rank."], | ||
["...♣", "Invalid card rank."], | ||
])("Inalid values: The %s should be %s", (input, expected) => { | ||
expect(getCardValue(input)).toBe(expected); | ||
}); | ||
}); | ||
Rashaad-Ebrahim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const isProperFraction = require("./is-proper-fraction"); | ||
|
||
describe("isProperFraction Tests", () => { | ||
test("Proper Fraction Check", () => { | ||
expect(isProperFraction(2, 3)).toBe(true); | ||
}); | ||
|
||
test("Improper Fraction Check", () => { | ||
expect(isProperFraction(5, 2)).toBe(false); | ||
}); | ||
|
||
test("Zero Denominator Check", () => { | ||
expect(() => isProperFraction(3, 0)).toThrow("Denominator cannot be zero"); | ||
}); | ||
|
||
test("Negative Fraction Check", () => { | ||
expect(isProperFraction(-4, 7)).toBe(true); | ||
}); | ||
|
||
test("Equal Numerator and Denominator Check", () => { | ||
expect(isProperFraction(3, 3)).toBe(false); | ||
}); | ||
|
||
// Additional tests | ||
|
||
test("Negative Denominator Check", () => { | ||
expect(isProperFraction(3, -5)).toBe(true); | ||
}); | ||
|
||
test("Negative Fraction Improper Check", () => { | ||
expect(isProperFraction(-13, 5)).toBe(false); | ||
}); | ||
|
||
test("Negative Denominator Improper Check", () => { | ||
expect(isProperFraction(9, -6)).toBe(false); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const isValidTriangle = require("./is-valid-triangle"); | ||
|
||
describe("isValidTriangle Tests", () => { | ||
test("Invalid triangle", () => { | ||
expect(isValidTriangle(6, 9, -1)).toBe(false); | ||
expect(isValidTriangle(2, 4, 0)).toBe(false); | ||
expect(isValidTriangle(-6, -9, -7)).toBe(false); | ||
}); | ||
|
||
test("Valid triangle", () => { | ||
expect(isValidTriangle(6, 9, 7)).toBe(true); | ||
expect(isValidTriangle(3, 3, 3)).toBe(true); | ||
expect(isValidTriangle(1200, 1800, 2700)).toBe(true); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const rotateCharacter = require("./rotate-char"); | ||
|
||
describe("rotateCharacter Tests", () => { | ||
it("Rotate Lowercase Letters", () => { | ||
expect(rotateCharacter("a", 3)).toBe("d"); | ||
expect(rotateCharacter("f", 1)).toBe("g"); | ||
}); | ||
|
||
it("Rotate Uppercase Letters", () => { | ||
expect(rotateCharacter("A", 3)).toBe("D"); | ||
expect(rotateCharacter("F", 1)).toBe("G"); | ||
}); | ||
|
||
it("Leave Non-Letter Characters Unchanged", () => { | ||
expect(rotateCharacter("7", 5)).toBe("7"); | ||
expect(rotateCharacter("?", 5)).toBe("?"); | ||
}); | ||
|
||
it("Shifting a Character with Wraparound", () => { | ||
expect(rotateCharacter("z", 1)).toBe("a"); | ||
expect(rotateCharacter("Y", 2)).toBe("A"); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function cardValidator(ccNumber) { | ||
// Ensure the card number is treated as a string | ||
const ccString = ccNumber.toString(); | ||
|
||
// Helper variables | ||
const ccNumberArray = ccString.split("").map((dig) => Number(dig)); // Array of card number digits. | ||
const digitsRegex = /^\d+$/; // Regex to check only numeric characters | ||
|
||
// Validation checks | ||
const isCorrectLength = ccString.length === 16; // Number must be 16 digits | ||
const hasMultipleDigits = [...new Set(ccNumberArray)].length > 1; // At least two different digits | ||
Rashaad-Ebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
const hasValidChars = digitsRegex.test(ccString); // All characters are numeric | ||
const endsWithEvenDigit = ccNumberArray[ccNumberArray.length - 1] % 2 === 0; // Last digit is even | ||
const isSumGreaterThan16 = ccNumberArray.reduce((a, c) => a + c, 0) > 16; // Sum of digits greater than 16 | ||
|
||
// Return true if all conditions are met, false otherwise | ||
return ( | ||
isCorrectLength && | ||
hasMultipleDigits && | ||
hasValidChars && | ||
endsWithEvenDigit && | ||
isSumGreaterThan16 | ||
); | ||
} | ||
|
||
module.exports = cardValidator; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const cardValidator = require("./card-validator"); | ||
|
||
describe("cardValidator Tests", () => { | ||
describe("Valid Number Tests", () => { | ||
it.each([ | ||
{ | ||
input: 9999777788880000, | ||
expected: true, | ||
description: "Number must be 16 digits", | ||
}, | ||
{ | ||
input: 6666666666661666, | ||
expected: true, | ||
description: "All characters must be numbers", | ||
}, | ||
|
||
{ | ||
input: "8899227766883304", | ||
expected: true, | ||
description: "At least two different digits", | ||
}, | ||
{ | ||
input: "2265566441861652", | ||
expected: true, | ||
description: "Last digit is even", | ||
}, | ||
{ | ||
input: "6264561614768652", | ||
expected: true, | ||
description: "Sum of digits greater than 16", | ||
}, | ||
])("$description", ({ input, expected }) => { | ||
expect(cardValidator(input)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe("Invalid Number Tests", () => { | ||
it.each([ | ||
{ | ||
input: 929673378853830, | ||
expected: false, | ||
description: "Number less than 16 digits", | ||
}, | ||
{ | ||
input: "495276#896141684", | ||
expected: false, | ||
description: "Invalid characters", | ||
}, | ||
|
||
{ | ||
input: 7777777777777777, | ||
expected: false, | ||
description: "Only one number used", | ||
}, | ||
{ | ||
input: "2265566441861651", | ||
expected: false, | ||
description: "Last digit is odd", | ||
}, | ||
{ | ||
input: "1111111111111110", | ||
expected: false, | ||
description: "Sum of digits less than 16", | ||
}, | ||
])("$description", ({ input, expected }) => { | ||
expect(cardValidator(input)).toBe(expected); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function countChar(str, char) { | ||
return str.split("").filter((letter) => letter === char).length; | ||
} | ||
|
||
module.exports = countChar; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.