-
-
Notifications
You must be signed in to change notification settings - Fork 195
WESTMIDLANDS| ITP-MAY 2025| ROJA ALAGURAJAN| Module Structuring and Testing Data|Sprint-3 #670
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -1,56 +1,44 @@ | ||
// Implement a function getAngleType | ||
// Build up your function case by case, writing tests as you go | ||
// The first test and case is written for you. The next case has a test, but no code. | ||
// Execute this script in your terminal | ||
// node 1-get-angle-type.js | ||
// The assertion error will tell you what the expected output is | ||
// Write the code to pass the test | ||
// Then, write the next test! :) Go through this process until all the cases are implemented | ||
|
||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
// read to the end, complete line 36, then pass your test here | ||
} | ||
if(angle<90) return "Acute angle"; | ||
if(angle>90 && angle<180) return "Obtuse angle"; | ||
if(angle === 180) return "Straight angle" | ||
if (angle>180 && angle <360) return "Reflex angle" | ||
|
||
// we're going to use this helper function to make our assertions easier to read | ||
// if the actual output matches the target output, the test will pass | ||
function assertEquals(actualOutput, targetOutput) { | ||
console.assert( | ||
actualOutput === targetOutput, | ||
`Expected ${actualOutput} to equal ${targetOutput}` | ||
); | ||
// read to the end, complete line 36, then pass your test here | ||
} | ||
|
||
|
||
// Acceptance criteria: | ||
|
||
// Given an angle in degrees, | ||
// When the function getAngleType is called with this angle, | ||
// Then it should: | ||
|
||
// Case 1: Identify Right Angles: | ||
// When the angle is exactly 90 degrees, | ||
// Then the function should return "Right angle" | ||
const right = getAngleType(90); | ||
assertEquals(right, "Right angle"); | ||
|
||
// Case 2: Identify Acute Angles: | ||
// When the angle is less than 90 degrees, | ||
// Then the function should return "Acute angle" | ||
const acute = getAngleType(45); | ||
assertEquals(acute, "Acute angle"); | ||
|
||
// Case 3: Identify Obtuse Angles: | ||
// When the angle is greater than 90 degrees and less than 180 degrees, | ||
// Then the function should return "Obtuse angle" | ||
const obtuse = getAngleType(120); | ||
assertEquals(obtuse, "Obtuse angle"); | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
|
||
// Case 4: Identify Straight Angles: | ||
// When the angle is exactly 180 degrees, | ||
// Then the function should return "Straight angle" | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
|
||
const straightangle = getAngleType(180) | ||
assertEquals(straightangle, "Straight angle") | ||
// Case 5: Identify Reflex Angles: | ||
// When the angle is greater than 180 degrees and less than 360 degrees, | ||
// Then the function should return "Reflex angle" | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
const reflexangle = getAngleType(250) | ||
assertEquals(reflexangle, "Reflex angle") |
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 (denominator === 0) throw new Error("Denominator cannot be zero"); | ||
return Math.abs(numerator) < Math.abs(denominator); | ||
} | ||
|
||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
const rankChar = card.slice(0, -1) | ||
|
||
if (rankChar === "A") return 11; //If rank is 'A' (Ace), return 11 points | ||
if (["K", "Q", "J"].includes(rankChar)) return 10; //// If rank is 'K', 'Q', or 'J' (King, Queen, Jack), return 10 points | ||
|
||
const validRanks = ["2", "3", "4", "5", "6", "7", "8", "9", "10"]; | ||
if (validRanks.includes(rankChar)) return Number(rankChar); // Define all valid numeric ranks as strings | ||
|
||
throw new Error("Invalid card rank.");//If none of the above conditions match, the card rank is invalid, so throw an error | ||
} | ||
module.exports = getCardValue; | ||
|
||
|
||
module.exports = getCardValue; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
const getCardValue = require("./3-get-card-value"); | ||
|
||
test("should return 11 for Ace of Spades", () => { | ||
test("should return 11 for Ace of Spades", () => { | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
|
||
|
||
|
||
test("should return rank for Number Cards", () => { | ||
const fiveofHearts = getCardValue("5♥"); | ||
expect(fiveofHearts).toEqual(5); | ||
}); | ||
Comment on lines
+10
to
+13
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. "2♥" and "10♥" -- the boundary values usually worth testing. The same principle applies to the test that deals with the face cards. |
||
|
||
test("should return 10 for Face Cards", () => { | ||
const facecards = getCardValue("Q♥"); | ||
expect(facecards).toEqual(10); | ||
}); | ||
|
||
test("should return 11 for AceCard", () => { | ||
const AceCard = getCardValue("A♥"); | ||
expect(AceCard).toEqual(11); | ||
}); | ||
Comment on lines
+20
to
+23
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. This test is similar to the test at lines 3-7. (This comment was from the previous review). |
||
|
||
test('throws error for invalid card', () => { | ||
expect(() => getCardValue("ST")).toThrow("Invalid card rank."); | ||
expect(() => getCardValue("0x02♠")).toThrow("Invalid card rank."); | ||
expect(() => getCardValue("5.1♠")).toThrow("Invalid card rank."); | ||
expect(() => getCardValue(" 5 ♠")).toThrow("Invalid card rank."); | ||
}); | ||
// Case 2: Handle Number Cards (2-10): | ||
// Case 3: Handle Face Cards (J, Q, K): | ||
// Case 4: Handle Ace (A): | ||
// Case 5: Handle Invalid Cards: | ||
// Case 5: Handle Invalid Cards: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
if (!stringOfCharacters.includes(findCharacter)) | ||
return 0; | ||
else { | ||
let count = 0; | ||
for (let char of stringOfCharacters) { | ||
if (char === findCharacter) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
} | ||
|
||
module.exports = countChar; |
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.
Any reason to keep this code? Code submitted to a PR is like the final work. As such, it is best practices to keep the code in the PR as clean as possible, including removal of unused code.