Skip to content

Commit e3ae6db

Browse files
committed
Sprint 3 from implement and rewrite - i have done the implement part only.
1 parent b31a586 commit e3ae6db

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@
1616

1717
function getAngleType(angle) {
1818
// TODO: Implement this function
19+
if (angle>0 && angle<90)
20+
{
21+
return "Acute angle";
22+
}
23+
else if (angle==90)
24+
{
25+
return "Right angle";
26+
}
27+
else if (angle>90 && angle<180)
28+
{
29+
return "Obtuse angle";
30+
}
31+
else if (angle==180)
32+
{
33+
return "Straight angle";
34+
}
35+
else if (angle>180 && angle<360)
36+
{
37+
return "Reflex angle";
38+
}
39+
else
40+
{
41+
return "Invalid angle";
42+
}
1943
}
2044

2145
// The line below allows us to load the getAngleType function into tests in other files.
@@ -35,3 +59,30 @@ function assertEquals(actualOutput, targetOutput) {
3559
// Example: Identify Right Angles
3660
const right = getAngleType(90);
3761
assertEquals(right, "Right angle");
62+
63+
const acute = getAngleType(1);
64+
assertEquals(acute,"Acute angle");
65+
66+
const obtuse = getAngleType(90.5);
67+
assertEquals(obtuse,"Obtuse angle");
68+
69+
const straight = getAngleType(180);
70+
assertEquals(straight,"Straight angle");
71+
72+
const reflex = getAngleType(359.9);
73+
assertEquals(reflex,"Reflex angle");
74+
75+
const invalid = getAngleType(380);
76+
assertEquals(invalid,"Invalid angle");
77+
78+
const straight2 = getAngleType(180);
79+
assertEquals(straight2,"Straight angle");
80+
81+
const invalid2 = getAngleType(360);
82+
assertEquals(invalid2,"Invalid angle");
83+
84+
const acute2 = getAngleType(0.1);
85+
assertEquals(acute2,"Acute angle");
86+
87+
const invalid3 = getAngleType(0);
88+
assertEquals(invalid3,"Invalid angle");

Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15+
numerator = Math.abs(numerator);
16+
denominator = Math.abs(denominator);
17+
if (numerator<denominator)
18+
{
19+
return true;
20+
}
21+
else
22+
return false;
1523
}
1624

1725
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +39,10 @@ function assertEquals(actualOutput, targetOutput) {
3139

3240
// Example: 1/2 is a proper fraction
3341
assertEquals(isProperFraction(1, 2), true);
42+
43+
assertEquals(isProperFraction(1,1),false);
44+
assertEquals(isProperFraction(40234,98543),true);
45+
assertEquals(isProperFraction(2,1),false);
46+
assertEquals(isProperFraction(-10,-1),false);
47+
assertEquals(isProperFraction(-1,-10),true);
48+
assertEquals(isProperFraction(1.5,1),false);

Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@
2323

2424
function getCardValue(card) {
2525
// TODO: Implement this function
26+
const value = card.slice(0, -1).toUpperCase();
27+
const validSuits = "♠,♥,♦,♣".split(",");
28+
const suit = card.slice(-1);
29+
30+
31+
if(!validSuits.includes(suit)) {
32+
throw new Error("Invalid card");
33+
}
34+
35+
const faceCardValues = {'A': 11, 'J': 10, 'Q': 10, 'K': 10};
36+
37+
if (faceCardValues[value] !== undefined) {
38+
return faceCardValues[value];
39+
}
40+
41+
const numvalue = Number(value);
42+
if (numvalue >= 2 && numvalue <= 10) {
43+
return numvalue;
44+
}
2645
}
2746

2847
// The line below allows us to load the getCardValue function into tests in other files.
@@ -41,6 +60,14 @@ function assertEquals(actualOutput, targetOutput) {
4160
// Examples:
4261
assertEquals(getCardValue("9♠"), 9);
4362

63+
assertEquals(getCardValue("A♥"),11);
64+
assertEquals(getCardValue("10♠"),10);
65+
66+
67+
assertEquals(getCardValue("2♠"), 2);
68+
assertEquals(getCardValue("K♠"), 10);
69+
assertEquals(getCardValue("q♦"), 10);
70+
assertEquals(getCardValue("J♣"), 10);
4471
// Handling invalid cards
4572
try {
4673
getCardValue("invalid");

0 commit comments

Comments
 (0)