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

LONDON | Pooriya Ketabi | Module-Structuring-and-Testing-Data | Sprint 3 #230

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 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,22 @@
// 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 && 180 > angle) {
return "Obtuse angle";
} else if (angle === 180) {
return "Straight angle";
} else if (angle > 180 && 360 > angle) {
return "Reflex angle";
} else {
return "Invalid Input"
}
}

console.log(getAngleType(361));
20 changes: 20 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,23 @@
// 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 rank = card.slice(0, -1);
const parseIntRank = parseInt(rank);
Comment on lines +34 to +35
Copy link
Member

Choose a reason for hiding this comment

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

It's useful to differentiate variable names when you have two things which have the same (but for some reason different, e.g. a different type type) data in them.

I probably wouldn't use parseIntRank as a variable name - parse is a verb, and verbs suggest doing (i.e. function names).

What do you think of each of these variable name pairs?

rankString and rankNumber

rankAsString and rankAsNumber

stringRank and numericRank

rankString and rank

if (parseIntRank >= 2 && parseIntRank <= 10) {
return parseIntRank;
}
switch (rank) {
case "J":
case "Q":
case "K":
return 10;
case "A":
return 11;
default:
throw new Error("Invalid card rank");
}
}

module.exports = getCardValue;
20 changes: 20 additions & 0 deletions Sprint-3/implement/get-card-value.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const getCardValue = require("./get-card-value");
test("should return the correct value for number cards (2-10)", () => {
expect(getCardValue("2♠")).toBe(2);
expect(getCardValue("9♥")).toBe(9);
expect(getCardValue("10♦")).toBe(10);
});

test("should return 10 for face cards (J, Q, K)", () => {
expect(getCardValue("J♠")).toBe(10);
expect(getCardValue("Q♣")).toBe(10);
expect(getCardValue("K♦")).toBe(10);
});

test("should return 11 for an Ace (A)", () => {
expect(getCardValue("A♠")).toBe(11);
});

test("should throw an error for an invalid card rank", () => {
expect(() => getCardValue("Z♠")).toThrow("Invalid card rank");
});
43 changes: 43 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,46 @@
// 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 (denominator === 0) {
throw new Error("Denominator cannot be zero");
}
return Math.abs(numerator) < Math.abs(denominator);
}

// ---------------------------------------- Tests: ----------------------------------------
// -------- Proper Fraction --------
console.assert(
isProperFraction(2, 3),
"Test failed: 2/3 should be a proper fraction"
);

// -------- Improper Fraction --------
console.assert(
!isProperFraction(5, 2),
"Test failed: 5/2 should not be a proper fraction"
);

// -------- Zero Denominator --------
try {
isProperFraction(3, 0);
console.error("Test failed: Denominator is zero, but no error was thrown");
} catch (e) {
console.assert(
e.message === "Denominator cannot be zero",
"Test failed: Error message is incorrect"
);
}

// -------- Negative Fraction --------
console.assert(
isProperFraction(-4, 7),
"Test failed: -4/7 should be a proper fraction"
);

// -------- Equal Numerator and Denominator --------
console.assert(
!isProperFraction(3, 3),
"Test failed: 3/3 should not be a proper fraction"
);
13 changes: 13 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,16 @@
// 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 true;
} else {
return false;
}
}

module.exports = isValidTriangle;
28 changes: 28 additions & 0 deletions Sprint-3/implement/is-valid-triangle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const isValidTriangle = require("./is-valid-triangle");

test("should return true for a valid triangle", () => {
expect(isValidTriangle(3, 4, 5)).toBe(true);
expect(isValidTriangle(5, 5, 5)).toBe(true);
expect(isValidTriangle(8, 10, 6)).toBe(true);
});

test("should return true for sides 2, 2, 3", () => {
expect(isValidTriangle(2, 2, 3)).toBe(true);
});

test("should return false (violates inequality)", () => {
expect(isValidTriangle(1, 2, 3)).toBe(false);
});

test("should return false as one side length is 0", () => {
expect(isValidTriangle(0, 5, 7)).toBe(false);
});

test("should return false as one side has negative length", () => {
expect(isValidTriangle(3, -4, 5)).toBe(false);
});

test("should return false (violates inequality)", () => {
expect(isValidTriangle(5, 1, 1)).toBe(false);
expect(isValidTriangle(1, 1, 2)).toBe(false);
});
Loading