generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 195
Glasgow | Mansoor Munawar | Structuring and Testing Data | Sprint 3 #662
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
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cf4537d
created getAngleTpe and assertion function
MansoorM11 7835f78
created isProperfraction function and added tests for it
MansoorM11 d157d6a
implemented getCard function and created test for it
MansoorM11 17c240e
added jest to main directory and createted test with jest for angle t…
MansoorM11 9aab60a
added code for getAngly function to identify straight angle and creat…
MansoorM11 833720c
created test to identify straight angle and reflex angle using jest
MansoorM11 790e134
created test using jest for is proper fractions
MansoorM11 f0a954a
fixed some bugs in the code and fixed variable names for easier reada…
MansoorM11 2456dd3
created test for card value function using jest
MansoorM11 ab4d3f3
created function for countChar and created test for it using jest
MansoorM11 a73c5dd
created formula for getOrdinalNumber function
MansoorM11 c72f1cb
created test for getOrdinal number function using Jest
MansoorM11 668ca1f
created a repeat function in JavaScript
MansoorM11 45fecfe
added two more test for repeat function using Jest
MansoorM11 b1775b2
added functionality for repeat function that takes into account negat…
MansoorM11 dc1663b
added a test for repeat function which checks for negative values
MansoorM11 2f3e10c
fixed a typo within a test
MansoorM11 5f9ef73
refactor my if-statement for better readability
MansoorM11 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
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 |
---|---|---|
@@ -1,18 +1,14 @@ | ||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
// replace with your completed function from key-implement | ||
|
||
else if (angle < 90) return "Acute angle"; | ||
else if (angle > 90 && angle < 180) return "Obtuse angle"; | ||
else if (angle > 180 && angle < 360) return "Reflex angle"; | ||
else if (angle === 180) return "Straight angle"; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// Don't get bogged down in this detail | ||
// Jest uses CommonJS module syntax by default as it's quite old | ||
// We will upgrade our approach to ES6 modules in the next course module, so for now | ||
// We will upgrade our approach to ES6 modules in the next course module, so for now | ||
// we have just written the CommonJS module.exports syntax for you | ||
module.exports = getAngleType; | ||
module.exports = getAngleType; |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
if (Math.abs(numerator) < Math.abs(denominator)) return true; | ||
else return false; | ||
} | ||
|
||
module.exports = isProperFraction; | ||
module.exports = isProperFraction; |
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
// replace with your code from key-implement | ||
let rank = card.slice(0, -1); | ||
|
||
if (rank === "A") return 11; | ||
else if (rank === "K" || rank === "Q" || rank === "J" || rank === "10") | ||
return 10; | ||
else if (Number(rank) >= 2 && Number(rank) <= 9) return Number(rank); | ||
else return "Invalid card rank."; | ||
} | ||
module.exports = getCardValue; | ||
module.exports = getCardValue; |
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 |
---|---|---|
@@ -1,11 +1,35 @@ | ||
const getCardValue = require("./3-get-card-value"); | ||
|
||
test("should return 11 for Ace of Spades", () => { | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
|
||
// Case 2: Handle Number Cards (2-10): | ||
test("should return 10 for 10 of Hearts", () => { | ||
const tenOfHearts = getCardValue("10♥"); | ||
expect(tenOfHearts).toEqual(10); | ||
}); | ||
test("should return 5 for 10 of Spades", () => { | ||
const fiveOfHearts = getCardValue("5♠"); | ||
expect(fiveOfHearts).toEqual(5); | ||
}); | ||
// Case 3: Handle Face Cards (J, Q, K): | ||
test("should return 10 for Kings of Spades", () => { | ||
const tenOfHearts = getCardValue("K♠"); | ||
expect(tenOfHearts).toEqual(10); | ||
}); | ||
test("should return 10 for Queen of Hearts", () => { | ||
const queenOfHearts = getCardValue("Q♥"); | ||
expect(queenOfHearts).toEqual(10); | ||
}); | ||
// Case 4: Handle Ace (A): | ||
test("should return 11 for Ace of Hearts", () => { | ||
const AceOfHearts = getCardValue("A♥"); | ||
expect(AceOfHearts).toEqual(11); | ||
}); | ||
// Case 5: Handle Invalid Cards: | ||
test("should return Invalid Card for letters", () => { | ||
const AceOfHearts = getCardValue("SS"); | ||
expect(AceOfHearts).toEqual("Invalid card rank."); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
let occurance = 0; | ||
for (const letter of stringOfCharacters) { | ||
if (findCharacter === letter) { | ||
occurance++; | ||
} | ||
} | ||
return occurance; | ||
} | ||
|
||
module.exports = countChar; | ||
module.exports = countChar; |
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
13 changes: 11 additions & 2 deletions
13
Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
let lastTwoNumber = num % 100; | ||
if (lastTwoNumber === 11 || lastTwoNumber === 12 || lastTwoNumber === 13) | ||
return `${num}th`; | ||
let lastDigit = num % 10; | ||
if (lastDigit === 1) return `${num}st`; | ||
else if (lastDigit === 2) return `${num}nd`; | ||
else if (lastDigit === 3) return `${num}rd`; | ||
else return `${num}th`; | ||
} | ||
|
||
module.exports = getOrdinalNumber; | ||
console.log(getOrdinalNumber(100)); | ||
|
||
module.exports = getOrdinalNumber; |
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
function repeat() { | ||
return "hellohellohello"; | ||
function repeat(str, count) { | ||
if (count < 0) { | ||
return "Negative numbers are not accepted"; | ||
} | ||
return str.repeat(count); | ||
} | ||
|
||
module.exports = repeat; | ||
console.log(repeat("hello", -100)); | ||
console.log(repeat("hell0", 0)); | ||
module.exports = repeat; |
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.
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.
Can you see any way you could combine these 3 return false conditions into one line?