Skip to content

LON | Amirhossein Aminian | Module-structuring-and-testing-data | sprint3 #142

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

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a9422f3
get-angle
AmirhosseinAminian Nov 10, 2024
fcbc6ce
get-card-value
AmirhosseinAminian Nov 11, 2024
c4029b3
fraction
AmirhosseinAminian Nov 12, 2024
73fb2ad
valid-triangle
AmirhosseinAminian Nov 12, 2024
5f53537
rotate-chart
AmirhosseinAminian Nov 13, 2024
22b26ab
credit_card_number
AmirhosseinAminian Nov 13, 2024
d0f894d
count_char
AmirhosseinAminian Nov 14, 2024
a04f883
ordinal_number-test
AmirhosseinAminian Nov 14, 2024
37c799f
Fixing feedback
AmirhosseinAminian Nov 14, 2024
3a19cbb
is_prime
AmirhosseinAminian Nov 14, 2024
9617648
feedback
AmirhosseinAminian Nov 14, 2024
048a134
password_validation
AmirhosseinAminian Nov 14, 2024
7f4fdbe
repeat_test
AmirhosseinAminian Nov 14, 2024
0696a5a
find.js
AmirhosseinAminian Nov 14, 2024
bf0c3b5
find.js
AmirhosseinAminian Nov 14, 2024
bb8e1c8
Merge branch 'main' into amiraminia/sprint3
SallyMcGrath Nov 21, 2024
2ce2bba
java to javascript
AmirhosseinAminian Nov 21, 2024
004e0ec
Merge branch 'amiraminia/sprint3' of https://github.com/Amir200524/Mo…
AmirhosseinAminian Nov 21, 2024
6d213de
java to javascript
AmirhosseinAminian Nov 21, 2024
b402751
java to javascript
AmirhosseinAminian Nov 21, 2024
e964339
converting to JavaScript
AmirhosseinAminian Nov 21, 2024
c970c82
more test case
AmirhosseinAminian Nov 21, 2024
fd5fd05
jest test
AmirhosseinAminian Nov 23, 2024
e480c7d
deleted example file
AmirhosseinAminian Nov 23, 2024
9423d02
generating test.js
AmirhosseinAminian Nov 23, 2024
b5dd0e1
fixing feedback
AmirhosseinAminian Nov 23, 2024
2160580
fixing password.test
AmirhosseinAminian Nov 23, 2024
6fbaaa4
generating count.test
AmirhosseinAminian Nov 23, 2024
e8ae613
generating get-ordinalnumber.test
AmirhosseinAminian Nov 23, 2024
e54439f
generating password-validator.test
AmirhosseinAminian Nov 23, 2024
e112659
generating repeat.test
AmirhosseinAminian Nov 23, 2024
9507417
fixing code
AmirhosseinAminian Nov 23, 2024
acf58fb
fixing repeat.test & repeat.js
AmirhosseinAminian Nov 23, 2024
67e8477
test of number of digits is exactly 16
AmirhosseinAminian Nov 30, 2024
b71f5a4
generate ifs for special case and skip even numbers
AmirhosseinAminian Nov 30, 2024
c88ad5f
export previousPasswords
AmirhosseinAminian Nov 30, 2024
b547b6c
Handles the special case & Eliminates even numbers
AmirhosseinAminian Nov 30, 2024
4018a61
Shift Normalization
AmirhosseinAminian Nov 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions Sprint-3/implement/get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// Implement a function getAngleType
class AngleType {
static 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 "Reflex angle";
} else {
return "Invalid angle";
}
}
}

// Acceptance criteria:
// Test cases
console.log(AngleType.getAngleType(45)); // Output: Acute angle
console.log(AngleType.getAngleType(90)); // Output: Right angle
console.log(AngleType.getAngleType(120)); // Output: Obtuse angle
console.log(AngleType.getAngleType(180)); // Output: Straight angle
console.log(AngleType.getAngleType(270)); // Output: Reflex angle
console.log(AngleType.getAngleType(360)); // Output: Invalid angle
console.log(AngleType.getAngleType(420)); //Invalid angle

// Given an angle in degrees,
// When the function getAngleType is called with this angle,
// Then it should:

// Identify Right Angles:
// When the angle is exactly 90 degrees,
// Then the function should return "Right angle"

// Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"

// Identify Obtuse Angles:
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"

// Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"

// Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
84 changes: 54 additions & 30 deletions Sprint-3/implement/get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck
function getCardValue(card) {
const rank = card.slice(0, -1);

switch (rank) {
case "A":
return 11;
case "K":
case "Q":
case "J":
case "10":
return 10;
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
return parseInt(rank);
default:
throw new Error("Invalid card rank");
}
}

// Test cases for different scenarios
try {
console.assert(getCardValue("A♠") === 11, "Ace should be worth 11 points");
console.assert(getCardValue("K♣") === 10, "King should be worth 10 points");
console.assert(getCardValue("Q♦") === 10, "Queen should be worth 10 points");
console.assert(getCardValue("J♥") === 10, "Jack should be worth 10 points");
console.assert(getCardValue("10♠") === 10, "10 should be worth 10 points");
console.assert(getCardValue("9♣") === 9, "9 should be worth 9 points");
console.assert(getCardValue("5♦") === 5, "5 should be worth 5 points");

// Testing invalid card rank
try {
getCardValue("1♠");
console.assert(false, "Expected Error for invalid rank '1'");
} catch (e) {
console.assert(e.message === "Invalid card rank", "Exception message should be 'Invalid card rank'");
}

try {
getCardValue("Z♦");
console.assert(false, "Expected Error for invalid rank 'Z'");
} catch (e) {
console.assert(e.message === "Invalid card rank", "Exception message should be 'Invalid card rank'");
}

console.log("All tests passed!");
} catch (e) {
console.error("Test failed:", e.message);
}

// You will need to implement a function getCardValue

// You need to write assertions for your function to check it works in different cases

// Acceptance criteria:

// 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

// 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).

// 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.

// 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.

// 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."
53 changes: 23 additions & 30 deletions Sprint-3/implement/is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
// You wil need to implement a function isProperFraction
// You need to write assertions for your function to check it works in different cases
function isProperFraction(numerator, denominator) {
if (denominator === 0) {
throw new Error("Denominator cannot be zero");
}
return Math.abs(numerator) < Math.abs(denominator);
}

// Terms:
// Fractions: https://www.bbc.co.uk/bitesize/topics/zt9n6g8/articles/zjxpp4j
// Written here like this: 1/2 == Numerator/Denominator
// Test cases
try {
console.assert(isProperFraction(2, 3) === true, "Test failed: 2/3 should be a proper fraction");
console.assert(isProperFraction(5, 2) === false, "Test failed: 5/2 should be an improper fraction");

// Acceptance criteria:
// Test for denominator of 0
try {
isProperFraction(3, 0);
console.assert(false, "Test failed: Denominator of 0 should throw an error");
} catch (e) {
console.assert(e.message === "Denominator cannot be zero", "Test failed: Incorrect error message for zero denominator");
}

// Proper Fraction check:
// Input: numerator = 2, denominator = 3
// target output: true
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
console.assert(isProperFraction(-4, 7) === true, "Test failed: -4/7 should be a proper fraction");
console.assert(isProperFraction(3, 3) === false, "Test failed: 3/3 should not be a proper fraction");

// Improper Fraction check:
// Input: numerator = 5, denominator = 2
// target output: false
// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false.

// Zero Denominator check:
// Input: numerator = 3, denominator = 0
// No target output: Error (Denominator cannot be zero)
// Explanation: The function should throw an error when the denominator is zero, as it's not a valid fraction.

// Negative Fraction check:
// Input: numerator = -4, denominator = 7
// target output: true
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.

// Equal Numerator and Denominator check:
// Input: numerator = 3, denominator = 3
// 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.
console.log("All tests passed!");
} catch (e) {
console.error("Test failed:", e.message);
}
50 changes: 18 additions & 32 deletions Sprint-3/implement/is-valid-triangle.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
// Implement a function isValidTriangle
// Terms
// the Triangle Inequality says: the sum of any two sides is always greater than the third side.
// practical examples:
// Side a = 3
// Side b = 3
// Side c = 3
function isValidTriangle(a, b, c) {
if (a <= 0 || b <= 0 || c <= 0) {
return false;
}

// This is a valid triangle, because a plus b = 6 and 6 is greater than 3
// Another way to write this is a + b > c
// It's also true that b + c > a
// It's also true that a + c > b
return (a + b > c) && (a + c > b) && (b + c > a);
}

// In our function isValidTriangle which takes as parameters the lengths of three sides, we need to invalidate any triangle where the sum of any two sides is less than or equal to the length of the third side.
// and we need to validate any triangle where the sum of any two sides is greater than the length of the third side.
// Test cases
try {
console.assert(isValidTriangle(3, 3, 3) === true, "Test failed: 3, 3, 3 should be a valid triangle");
console.assert(isValidTriangle(1, 2, 3) === false, "Test failed: 1, 2, 3 should be an invalid triangle");
console.assert(isValidTriangle(0, 5, 7) === false, "Test failed: 0, 5, 7 should be an invalid triangle");
console.assert(isValidTriangle(-3, 4, 5) === false, "Test failed: -3, 4, 5 should be an invalid triangle");
console.assert(isValidTriangle(3, 4, 5) === true, "Test failed: 3, 4, 5 should be a valid triangle");
console.assert(isValidTriangle(7, 10, 5) === true, "Test failed: 7, 10, 5 should be a valid triangle");

// Acceptance criteria:

// scenario: invalid triangle
// Given the side lengths a, b, and c,
// When the sum of any two side lengths is less than or equal to the length of the third side (i.e., a + b <= c, a + c <= b, b + c <= a),
// Then it should return false because these conditions violate the Triangle Inequality, which states that the sum of the lengths of any two sides of a triangle must be greater than the length of the third side.

// scenario: invalid triangle
// Check for Valid Input:
// Given the sides a, b, and c,
// When any of the sides are less than or equal to zero,
// Then it should return false because a triangle cannot have zero or negative side lengths.

// scenario: valid triangle
// Given valid side lengths where the sum of any two sides is greater than the third side,
// When the function is called with these values as input,
// 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.
console.log("All tests passed!");
} catch (e) {
console.error("Test failed:", e.message);
}
63 changes: 24 additions & 39 deletions Sprint-3/implement/rotate-char.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,28 @@
// The rotateCharacter function takes a character and a shift value as input.
// If the character is a letter (either uppercase or lowercase),
// it rotates the character by the specified shift value within the alphabet,
// considering wrapping around if necessary. Non-letter characters are returned unchanged.
function rotateCharacter(char, shift) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you modify your implementation if shift is allowed to be a negative number to represent a rotation in the opposite direction?

// Normalize the shift value to the range [0, 25]
shift = ((shift % 26) + 26) % 26;

// This function is commonly used for text encryption and decryption,
// where shifting characters by a certain value can obscure their meaning or reveal hidden messages.
if (char >= 'a' && char <= 'z') {
let newCharCode = ((char.charCodeAt(0) - 'a'.charCodeAt(0) + shift) % 26) + 'a'.charCodeAt(0);
return String.fromCharCode(newCharCode);
}

if (char >= 'A' && char <= 'Z') {
let newCharCode = ((char.charCodeAt(0) - 'A'.charCodeAt(0) + shift) % 26) + 'A'.charCodeAt(0);
return String.fromCharCode(newCharCode);
}

// Acceptance criteria:
return char; // Return the character unchanged if it is not a letter
}

// Given a character and a shift value,
// When the function rotateCharacter is called with these inputs,
// Then it should:
// Test cases for large and negative shifts
console.log(rotateCharacter("a", 3)); // Output: "d"
console.log(rotateCharacter("z", 1)); // Output: "a" (wraps around)
console.log(rotateCharacter("a", 26)); // Output: "a" (full rotation)
console.log(rotateCharacter("a", 52)); // Output: "a" (multiple full rotations)
console.log(rotateCharacter("a", -1)); // Output: "z" (negative shift)
console.log(rotateCharacter("z", -26)); // Output: "z" (full negative rotation)
console.log(rotateCharacter("Y", 28)); // Output: "A" (handles large positive shift)
console.log(rotateCharacter("B", -29)); // Output: "Y" (handles large negative shift)
console.log(rotateCharacter("7", 5)); // Output: "7" (unchanged, not a letter)

// Scenario: Rotate Lowercase Letters:
// 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.
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"

// Scenario: Leave Non-Letter Characters Unchanged:
// Given a character that is not a letter (neither uppercase nor lowercase) and any positive or negative shift value,
// When the function is called with these inputs,
// Then it should return the character unchanged.
// This specification outlines the behavior of the rotateCharacter function for different input scenarios, including valid and invalid characters, and defines the expected output or action for each case.
console.log(rotateCharacter("7", 5)); // Output: "7" (unchanged, not a letter)

// Scenario: Shifting a Character with Wraparound
// Given a character char within the lowercase alphabet range (e.g., 'z') or the uppercase alphabet range (e.g., 'Z'),
// And a positive integer shift that causes the character to wrap around the alphabet when rotated (e.g., a shift of 3 for 'z' or 'Z'),
// When the rotateCharacter function is called with char and shift as inputs,
// Then it should correctly rotate the character by shift positions within the alphabet while handling the wraparound,
// And the function should return the rotated character as a string (e.g., 'z' rotated by 3 should become 'c', 'Z' rotated by 3 should become 'C').
console.log(rotateCharacter("z", 1)); // Output: "a" (preserves case, but wraps around)
console.log(rotateCharacter("Y", 2)); // Output: "A" (preserves case, but wraps around)
8 changes: 4 additions & 4 deletions Sprint-3/revise/implement/card-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ Here are the rules for a valid number:

For example, the following credit card numbers are valid:

```markdown
markdown
9999777788880000
6666666666661666
```


And the following credit card numbers are invalid:

```markdown
markdown
a92332119c011112 (invalid characters)
4444444444444444 (only one type of number)
1111111111111110 (sum less than 16)
6666666666666661 (odd final number)
```


These are the requirements your project needs to fulfill:

Expand Down
12 changes: 12 additions & 0 deletions Sprint-3/revise/implement/count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function countChar(str, char) {
let count = 0;
for (let i = 0; i < str.length; i++) {
if (str[i] === char) {
count++;
}
}
return count;
}

module.exports = countChar; // This exports the function for use in other files

Loading