-
-
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
Changes from 16 commits
cf4537d
7835f78
d157d6a
17c240e
9aab60a
833720c
790e134
f0a954a
2456dd3
ab4d3f3
a73c5dd
c72f1cb
668ca1f
45fecfe
b1775b2
dc1663b
2f3e10c
5f9ef73
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 |
---|---|---|
|
@@ -8,7 +8,13 @@ | |
// write one test at a time, and make it pass, build your solution up methodically | ||
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers | ||
function getCardValue(card) { | ||
if (rank === "A") return 11; | ||
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."; | ||
} | ||
|
||
// You need to write assertions for your function to check it works in different cases | ||
|
@@ -25,27 +31,33 @@ function assertEquals(actualOutput, targetOutput) { | |
// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A), | ||
// When the function getCardValue is called with this card string as input, | ||
// Then it should return the numerical card value | ||
const aceofSpades = getCardValue("A♠"); | ||
assertEquals(aceofSpades, 11); | ||
const aceOfSpades = getCardValue("A♠"); | ||
assertEquals(aceOfSpades, 11); | ||
|
||
// Handle Number Cards (2-10): | ||
// Given a card with a rank between "2" and "9", | ||
// When the function is called with such a card, | ||
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). | ||
const fiveofHearts = getCardValue("5♥"); | ||
const fiveOfHearts = getCardValue("5♥"); | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
|
||
assertEquals(fiveOfHearts, 5); | ||
// Handle Face Cards (J, Q, K): | ||
// Given a card with a rank of "10," "J," "Q," or "K", | ||
// When the function is called with such a card, | ||
// Then it should return the value 10, as these cards are worth 10 points each in blackjack. | ||
|
||
const kingOfHearts = getCardValue("K♥"); | ||
assertEquals(kingOfHearts, 10); | ||
const tenOfHearts = getCardValue("10♥"); | ||
assertEquals(tenOfHearts, 10); | ||
// Handle Ace (A): | ||
// Given a card with a rank of "A", | ||
// When the function is called with an Ace, | ||
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. | ||
|
||
const aceOfHearts = getCardValue("A♥"); | ||
assertEquals(aceOfSpades, 11); | ||
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 think you may have made a typo here that invalidates this test. Which variables are you trying to test for on this line? 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. Thanks for the feedback. I've now made the requested changes. |
||
// Handle Invalid Cards: | ||
// 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." | ||
const invalidCard = getCardValue("S"); | ||
assertEquals(invalidCard, "Invalid card rank."); |
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
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 if (numerator === denominator) return false; | ||
else if (numerator > denominator) return false; | ||
else return false; | ||
} | ||
|
||
module.exports = isProperFraction; | ||
module.exports = isProperFraction; |
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; |
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."); | ||
}); |
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; |
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; |
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; |
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?