-
-
Notifications
You must be signed in to change notification settings - Fork 165
North West | Zabihollah Namazi | Module-Structuring-and-Testing-Data | Sprint 3 #123
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
70aad48
77746f9
7fc4ae2
5946df5
366095e
1c2b2f3
19d79ba
5825d6a
a40495a
fc98a96
56680fb
5cca134
1633f62
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 |
---|---|---|
|
@@ -29,3 +29,31 @@ | |
// 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){ | ||
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. It seems like there's quite a lot to do here. In the assignment there are many tests and criteria defined. Your code should address each criterion systematically. How will you do this? |
||
let num = card[0]; | ||
if(Number(num) >= 2 && Number(num) < 10){ | ||
return `${num}${card[1]}` | ||
} | ||
else if(num == "A"){ | ||
return `11${card[1]}` | ||
} | ||
else if (num == 10 || num == "J" || num == "Q" || num == "K"){ | ||
return `10${card[1]}` | ||
} | ||
|
||
|
||
} | ||
|
||
let currentOutput = getCardValue("5♠"); | ||
let targetOutput = "5♠"; | ||
console.assert( | ||
currentOutput === targetOutput, | ||
`current output: ${currentOutput}, target output: ${targetOutput}` | ||
); | ||
|
||
|
||
console.log(getCardValue("K♣️")); | ||
|
||
|
||
// |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,27 @@ | |
// 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){ | ||
if (numerator < 0){ | ||
numerator = numerator * (-1); | ||
} | ||
if(denominator == 0){ | ||
throw new Error("denominator should not be equal to Zero"); | ||
} | ||
if(numerator < denominator){ | ||
return true | ||
} | ||
else if(numerator >= denominator){ | ||
return false | ||
} | ||
} | ||
|
||
console.log(isProperFraction(3, 5)); | ||
|
||
let currentOutput = isProperFraction(2, 3); | ||
let targetOutput = 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. Here too, I am looking for a sequence of assertions that check the assertions made in the coursework. This is a great thing to take to pair programming sessions and work through systematically with a pair. You can use driver navigator pattern to build up your solution. |
||
console.assert( | ||
currentOutput == targetOutput, | ||
`currentOutput ${currentOutput} is not equal to targetOutput ${targetOutput}` | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,20 @@ | |
// Then it should return true because the input forms a valid triangle. | ||
|
||
// This specification outlines the behavior of the isValidTriangle function for different input scenarios, ensuring it properly checks for invalid side lengths and whether they form a valid triangle according to the Triangle Inequality Theorem. | ||
|
||
function isValidTriangle(a, b, c){ | ||
if(a == 0 || b == 0 || c == 0){ | ||
return false | ||
} | ||
if(a + b <= c || a + c <= b || b + c <= a){ | ||
return false | ||
} | ||
// else if(a + b >= c || a + c >= b || b + c >= a){ | ||
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. Why is this commented out? In general, unless you have a question about it, don't commit commented out code |
||
return true | ||
//} | ||
} | ||
|
||
|
||
console.log(isValidTriangle(1, 1, 1)); | ||
|
||
console.assert(isValidTriangle(23, 45, 97), "its false because sum of the 23 and 45 is greater than 67"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,42 @@ | |
// Given a lowercase letter character and a positive integer shift, | ||
// When the function is called with these inputs, | ||
// Then it should rotate the lowercase letter by shift positions within the lowercase alphabet, wrapping around if necessary, and return the rotated lowercase letter as a string. | ||
let ALPHABET = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "U", "V", "w", "x", "y", "z"]; | ||
let ALPHABET_UPPERCASE = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; | ||
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. 🤔 Instead of using two arrays here, could I use one and operate on each character with a string method? |
||
|
||
function rotateCharacter(char , num){ | ||
|
||
let result = ""; | ||
for(let i = 0; i < ALPHABET.length; i++){ | ||
if(char == ALPHABET[i]){ | ||
if(i+num >=26){ | ||
let a = (i+num) % 26; | ||
return ALPHABET[a]; | ||
} | ||
result = ALPHABET[i + num] | ||
|
||
return result | ||
} | ||
if(char == ALPHABET_UPPERCASE[i]){ | ||
if(i+num >=26){ | ||
let a = (i+num) % 26; | ||
return ALPHABET_UPPERCASE[a]; | ||
} | ||
result = ALPHABET_UPPERCASE[i + num] | ||
|
||
return result | ||
} | ||
} | ||
return char; | ||
} | ||
console.log(rotateCharacter("a", 3)); // Output: "d" | ||
console.log(rotateCharacter("f", 1)); // Output: "g" | ||
|
||
// Scenario: Rotate Uppercase Letters: | ||
// Given an uppercase letter character and a positive integer shift, | ||
// When the function is called with these inputs, | ||
// Then it should rotate the uppercase letter by shift positions within the uppercase alphabet, wrapping around if necessary, and return the rotated uppercase letter as a string. | ||
|
||
console.log(rotateCharacter("A", 3)); // Output: "D" | ||
console.log(rotateCharacter("F", 1)); // Output: "G" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function card_validator(number){ | ||
let num = []; | ||
// we'll get the number and put it in a list | ||
while(number != 0){ | ||
num.push(number % 10); | ||
number = Math.floor(number / 10); | ||
} | ||
num.reverse(); | ||
let freqMap = { | ||
0:0,1:0,2:0,3:0 | ||
}; | ||
let sum = 0; | ||
num.forEach(x => { | ||
freqMap[x]=( (freqMap[x]) ? freqMap[x] : 0) + 1; | ||
sum += x; | ||
}) | ||
console.log(freqMap) | ||
let noneZeros = 0; | ||
Object.keys(freqMap).forEach(x=>{ | ||
if(freqMap[x] > 0){ | ||
noneZeros++; | ||
} | ||
}) | ||
console.log(noneZeros) | ||
if(noneZeros >= 2 && (num[15] % 2) == 0 && sum > 16){ // checking the condintions two diffirent digits, last digit must be even and sum must be greater than 16 | ||
return true; | ||
|
||
} | ||
else{ | ||
return false; | ||
} | ||
// console.log(noneZeros) | ||
} | ||
|
||
console.log(card_validator(1111222233334444)); | ||
console.log(card_validator(4444444444444444)); | ||
console.log(card_validator(1111111111111110)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
// Given a positive integer num, | ||
// When the isPrime function is called with num as input, | ||
// Then it should check if the num is prime | ||
|
||
function isPrime(num){ | ||
if (num <= 1) return false; | ||
else if (num <= 3) return true; | ||
else if(num % 2 == 0 || num % 3 == 0){ | ||
return false; | ||
} | ||
else if (num % 1 == 0 && num % num == 0){ | ||
return true | ||
} | ||
} | ||
|
||
console.log(isPrime(277473)); |
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.
Does this return Reflex angle? What test could you write to check this?