Skip to content
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

North West | Zabihollah Namazi | Module-Structuring-and-Testing-Data | Sprint 3 #123

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
22 changes: 22 additions & 0 deletions Sprint-3/implement/get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,25 @@
// Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"


function getAngleType(angle){
if (angle == 90){
return "Right angle"
}
else if(angle < 90){
return "Acute angle"
}
else if(angle > 90 && angle < 180){
return "Obtuse angle"
}
else if(angle == 180){
return "Straight angle"
}
else if(angle > 180 && angle < 360){
return "Relax angle"
}

}

console.log(getAngleType(250));
28 changes: 28 additions & 0 deletions Sprint-3/implement/get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
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♣️"));


//
24 changes: 24 additions & 0 deletions Sprint-3/implement/is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
console.assert(
currentOutput == targetOutput,
`currentOutput ${currentOutput} is not equal to targetOutput ${targetOutput}`
);
17 changes: 17 additions & 0 deletions Sprint-3/implement/is-valid-triangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
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");
29 changes: 29 additions & 0 deletions Sprint-3/implement/rotate-char.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

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"

Expand Down
38 changes: 38 additions & 0 deletions Sprint-3/revise/implement/card-validator.js
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));

22 changes: 22 additions & 0 deletions Sprint-3/revise/implement/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,25 @@
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.

function countChar(str, char){
let str_list = [];
for(let i = 0;i < str.length; i++){
str_list.push(str[i]);
}
console.log(str_list);
let sum = 0;
for(let j=0; j < str_list.length; j++){
if(char == str_list[j]){
sum++
}
}
if(sum > 0){
return sum
}
else{
return 0
}
}

console.log(countChar("asldajaa", "z"));
13 changes: 13 additions & 0 deletions Sprint-3/revise/implement/is-prime.test.js
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));
23 changes: 23 additions & 0 deletions Sprint-3/revise/implement/password-validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,26 @@ To be valid, a password must:

You must breakdown this problem in order to solve it. Find one test case first and get that working
*/
function passValidation(newPassword, previousPasswords){
if (newPassword.length < 5){
return false;
}
let hasUpperCase = /[A-Z]/.test(newPassword);
let hasLowerCase = /[a-z]/.test(newPassword);
let hasNumber = /[0-9]/.test(newPassword);
let hasNonAlpha = /["!""#""$""%"".""*""&"]/.test(newPassword);

if(!hasUpperCase || !hasLowerCase || !hasNumber || !hasNonAlpha){
return false;
}
if(previousPasswords.includes(newPassword)){
return false;
}
return true
}


let PASSWORDS = ["Liver12345!", "London12345?", "Sheff12345!?"];
console.log(passValidation("Liver12345.", PASSWORDS));

console.assert(passValidation("England54321", PASSWORDS), "test failed. write a valid password");
27 changes: 27 additions & 0 deletions Sprint-3/revise/implement/repeat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,30 @@
// Given a target string str and a negative integer count,
// When the repeat function is called with these inputs,
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.


function repeat(str, count){
let text = "";
if(count > 1 && count < 10){
for(let i = 1; i <= count; i++){
text += str;
}
return text;
}
if(count == 1){
return str;
}
if(count == 0){
return text;
}
if(count < 0){
throw new Error("The count must not be a negative number!");
}


}

console.log(repeat("hello", 3));

// I set acondition that count should not be greater than 9
console.assert(repeat("hello", 11), "test failed, in valid count number");
5 changes: 5 additions & 0 deletions Sprint-3/revise/investigate/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ console.log(find("code your future", "z"));
// Pay particular attention to the following:

// a) How the index variable updates during the call to find
// index updates: Starts at 0 and goes up by 1 each time, checking each character in the string.
// b) What is the if statement used to check
// if statement: Checks if the current character matches the one we’re looking for. If it does, it returns the position.
// c) Why is index++ being used?
// index++: Moves to the next character so we don’t get stuck on the same one.
// d) What is the condition index < str.length used for?
// index < str.length: Makes sure we stop when we reach the end of the string.