Skip to content

London | 26-ITP-May | Edina Kurdi | Sprint 3 | Implement and rewrite tests#1468

Open
edinakurdi wants to merge 6 commits into
CodeYourFuture:mainfrom
edinakurdi:coursework/sprint-3-implement-and-rewrite
Open

London | 26-ITP-May | Edina Kurdi | Sprint 3 | Implement and rewrite tests#1468
edinakurdi wants to merge 6 commits into
CodeYourFuture:mainfrom
edinakurdi:coursework/sprint-3-implement-and-rewrite

Conversation

@edinakurdi

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Implemented and tested angles, proper fraction and cards functions, also tested using jest

Questions

  • With the card implementation, I tried making it cleaner, but nested if-statements are not the best for clean code. Is that correct? Would there be a more structured way of dealing with this? I think I was on the right track with creating the suits array inside the function, but then it got a bit messy. Are there any techniques that would help me gear towards a better solution here?

  • Also, when trying to write tests, how many of the same kind is enough? for instance, with the cards, would i need to test for each number value when its a number card, or is it enough to test for 2-3 numbers?

@edinakurdi edinakurdi added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jul 5, 2026
@Luro91 Luro91 added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Jul 10, 2026
Comment on lines +43 to +62
const straight = getAngleType(180);
assertEquals(straight, "Straight angle");

const acute_upper_boundary = getAngleType(89);
assertEquals(acute_upper_boundary, "Acute angle");

const acute_lower_boundary = getAngleType(1);
assertEquals(acute_lower_boundary, "Acute angle");

const invalid_negative = getAngleType(-1);
assertEquals(invalid_negative, "Invalid angle");

const invalid_zero = getAngleType(0);
assertEquals(invalid_zero, "Invalid angle");

const invalid_full = getAngleType(360);
assertEquals(invalid_full, "Invalid angle");

const invalid_big = getAngleType(361);
assertEquals(invalid_big, "Invalid angle");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

NNice touch using the variable names to explain the test case. This makes it easier to understand

Comment on lines +78 to +85
const acute_decimal = getAngleType(89.9);
assertEquals(acute_decimal, "Acute angle");

const obtuse_decimal = getAngleType(179.9);
assertEquals(obtuse_decimal, "Obtuse angle");

const reflex_decimal = getAngleType(180.1);
assertEquals(reflex_decimal, "Reflex angle");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good catch to also test decimal values

Comment on lines +19 to +49
expect(getAngleType(90)).toEqual("Right angle");
});

// Case 3: Obtuse angles
test('should return "Obtuse angle" when (90 < angle < 180', () => {
// Test various obtuse angles, including boundary cases
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(100)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});

// Case 4: Straight angle
test('should return "Straight angle" when (angle = 180)', () => {
// Test straight angle
expect(getAngleType(180)).toEqual("Straight angle");
});

// Case 5: Reflex angles
test('should return "Reflex angle" when (180 < angle < 360', () => {
// Test various reflex angles, including boundary cases
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(300)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});

// Case 6: Invalid angles
test('Should return "Invalid angle" when the input is invalid', () => {
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(361)).toEqual("Invalid angle");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done on testing all the boundaries


function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if (denominator === 0 || numerator === 0) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why can the numerator not be 0?

Comment on lines +26 to +43
if (card[0] === "A" && suits.includes(card[1]) && card.length === 2)
return 11;
if (
(card[0] === "J" || card[0] === "Q" || card[0] === "K") &&
suits.includes(card[1]) &&
card.length === 2
)
return 10;
if (
["2", "3", "4", "5", "6", "7", "8", "9"].includes(card[0]) &&
suits.includes(card[1]) &&
card.length === 2
)
return Number(card[0]);
if (card.slice(0, 2) == "10" && suits.includes(card[2]) && card.length === 3)
return 10;
throw new Error(
'Invalid input: Expected rank followed by a suit symbol. For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦"'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I find the code hard to read. I like the allowed suits definition. Can you do something similar with the numbers. How can you determine suit and rank of a card. (A different way then access by index might be simpler)

Comment on lines +95 to +131
getCardValue("9♠ ");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}

try {
getCardValue("♠9");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}

try {
getCardValue("99♠");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}

try {
getCardValue("9♠♠");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}

try {
getCardValue("9❤️");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work. You found a lot of error cases

@Luro91 Luro91 added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants