Skip to content

Commit 13d526c

Browse files
Alex JamshidiAlex Jamshidi
authored andcommitted
formatted with prettier
1 parent 474cd2e commit 13d526c

6 files changed

Lines changed: 72 additions & 43 deletions

File tree

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@
1515
// execute the code to ensure all tests pass.
1616

1717
function getAngleType(angle) {
18-
if (angle > 0 && angle < 90) {return "Acute angle";}
19-
if (angle == 90) {return "Right angle";}
20-
if (angle > 90 && angle < 180) {return "Obtuse angle";}
21-
if (angle == 180) {return "Straight angle";}
22-
if (angle > 180 && angle < 360) {return "Reflex angle";}
23-
else return "Invalid angle"
18+
if (angle > 0 && angle < 90) {
19+
return "Acute angle";
20+
}
21+
if (angle == 90) {
22+
return "Right angle";
23+
}
24+
if (angle > 90 && angle < 180) {
25+
return "Obtuse angle";
26+
}
27+
if (angle == 180) {
28+
return "Straight angle";
29+
}
30+
if (angle > 180 && angle < 360) {
31+
return "Reflex angle";
32+
} else return "Invalid angle";
2433
}
2534

2635
// The line below allows us to load the getAngleType function into tests in other files.
@@ -58,4 +67,3 @@ assertEquals(getAngleType(180), "Straight angle");
5867

5968
assertEquals(getAngleType(181), "Reflex angle");
6069
assertEquals(getAngleType(359), "Reflex angle");
61-

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// execute the code to ensure all tests pass.
1212

1313
function isProperFraction(numerator, denominator) {
14-
return Math.abs(numerator) < Math.abs(denominator)
14+
return Math.abs(numerator) < Math.abs(denominator);
1515
}
1616

1717
// The line below allows us to load the isProperFraction function into tests in other files.

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,23 @@
2323

2424
function getCardValue(card) {
2525
const suits = ["♠", "♥", "♦", "♣"];
26-
if (!suits.includes(card.slice(-1))) {throw new Error("Invalid card");}
27-
26+
if (!suits.includes(card.slice(-1))) {
27+
throw new Error("Invalid card");
28+
}
29+
2830
const value = card.slice(0, -1);
29-
if (value == 10) {return 10;}
30-
if (value >= 2 && value <= 9) {return Number(value);}
31-
if (value == "J" || value == "Q" || value == "K") {return 10;}
32-
if (value == "A") {return 11;}
33-
else throw new Error("Invalid card");
31+
if (value == 10) {
32+
return 10;
33+
}
34+
if (value >= 2 && value <= 9) {
35+
return Number(value);
36+
}
37+
if (value == "J" || value == "Q" || value == "K") {
38+
return 10;
39+
}
40+
if (value == "A") {
41+
return 11;
42+
} else throw new Error("Invalid card");
3443
}
3544

3645
// The line below allows us to load the getCardValue function into tests in other files.
@@ -70,4 +79,4 @@ try {
7079
// cards without suits
7180
// numbers above 10
7281
// negative numbers
73-
// letters outside J K Q and A
82+
// letters outside J K Q and A

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
1616
// Case 2: Right angle
1717
test(`should return "Right angle" when angle == 90)`, () => {
1818
// Test right angle
19-
expect(getAngleType(90)).toEqual("Right angle");
19+
expect(getAngleType(90)).toEqual("Right angle");
2020
});
2121

2222
// Case 3: Obtuse angles
@@ -30,7 +30,7 @@ test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
3030
// Case 4: Straight angle
3131
test(`should return "Straight angle" when angle == 180)`, () => {
3232
// Test straight angle
33-
expect(getAngleType(180)).toEqual("Straight angle");
33+
expect(getAngleType(180)).toEqual("Straight angle");
3434
});
3535

3636
// Case 5: Reflex angles
@@ -49,4 +49,4 @@ test(`should return "Invalid Angle" when invalid`, () => {
4949
expect(getAngleType(360)).toEqual("Invalid angle");
5050
expect(getAngleType(10000)).toEqual("Invalid angle");
5151
expect(getAngleType("Im not an angle")).toEqual("Invalid angle");
52-
});
52+
});

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,52 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
44

55
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
66

7-
test('should return true when the numerator is less than the denominator (1 and 2)', () => {
7+
test("should return true when the numerator is less than the denominator (1 and 2)", () => {
88
expect(isProperFraction(1, 2)).toEqual(true);
99
});
1010

11-
test('should return true when the numerator is less than the denominator using decimals (0.1 and 2)', () => {
11+
test("should return true when the numerator is less than the denominator using decimals (0.1 and 2)", () => {
1212
expect(isProperFraction(0.1, 2)).toEqual(true);
1313
});
1414

15-
test('should return true when the numerator is less than the denominator and numerator is negative (-1 and 2)', () => {
15+
test("should return true when the numerator is less than the denominator and numerator is negative (-1 and 2)", () => {
1616
expect(isProperFraction(-1, 2)).toEqual(true);
1717
});
1818

19-
test('should return true when the numerator is less than the denominator and denominator is negative (1 and -2)', () => {
20-
expect(isProperFraction(1, -2)).toEqual(true);
19+
test("should return true when the numerator is less than the denominator and denominator is negative (1 and -2)", () => {
20+
expect(isProperFraction(1, -2)).toEqual(true);
2121
});
2222

23-
test('should return true for large numbers when numerator is less than denominator (1,000,000 and 2,000,000)', () => {
23+
test("should return true for large numbers when numerator is less than denominator (1,000,000 and 2,000,000)", () => {
2424
expect(isProperFraction(1000000, 2000000)).toEqual(true);
2525
});
2626

27-
28-
test('should return false when the numerator is greater than the denominator (2 and 1)', () => {
27+
test("should return false when the numerator is greater than the denominator (2 and 1)", () => {
2928
expect(isProperFraction(2, 1)).toEqual(false);
3029
});
3130

32-
test('should return false when the numerator is larger than the denominator with decimals (2 and 0.1)', () => {
31+
test("should return false when the numerator is larger than the denominator with decimals (2 and 0.1)", () => {
3332
expect(isProperFraction(2, 0.1)).toEqual(false);
3433
});
3534

36-
test('should return false when the numerator is larger than the denominator (2 and -1)', () => {
35+
test("should return false when the numerator is larger than the denominator (2 and -1)", () => {
3736
expect(isProperFraction(2, -1)).toEqual(false);
3837
});
3938

40-
test('should return false when the numerator is larger than the denominator (-2 and 1)', () => {
39+
test("should return false when the numerator is larger than the denominator (-2 and 1)", () => {
4140
expect(isProperFraction(-2, 1)).toEqual(false);
4241
});
4342

44-
test('should return false for large numbers when the numerator is larger than the denominator (2,000,000 and 1,000,000)', () => {
43+
test("should return false for large numbers when the numerator is larger than the denominator (2,000,000 and 1,000,000)", () => {
4544
expect(isProperFraction(2000000, 1000000)).toEqual(false);
4645
});
4746

4847
// Special case: denominator is zero
49-
test('should return false when denominator is zero', () => {
48+
test("should return false when denominator is zero", () => {
5049
expect(isProperFraction(1, 0)).toEqual(false);
5150
});
5251

5352
// Special case: numerator is string
54-
test('should return false when denominator is zero', () => {
53+
test("should return false when denominator is zero", () => {
5554
expect(isProperFraction("hello", 0)).toEqual(false);
56-
});
55+
});

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,47 @@ test(`Should return 10 when given a King "K♦" card`, () => {
3737

3838
// Invalid Cards
3939
test(`Should return error when given a string`, () => {
40-
expect(() => { getCardValue("invalid");}).toThrow("Invalid card");
40+
expect(() => {
41+
getCardValue("invalid");
42+
}).toThrow("Invalid card");
4143
});
4244

4345
test(`Should return error when given a wrong letter`, () => {
44-
expect(() => { getCardValue("L♦");}).toThrow("Invalid card");
46+
expect(() => {
47+
getCardValue("L♦");
48+
}).toThrow("Invalid card");
4549
});
4650

4751
test(`Should return error when given a wrong letter`, () => {
48-
expect(() => { getCardValue("L♦");}).toThrow("Invalid card");
52+
expect(() => {
53+
getCardValue("L♦");
54+
}).toThrow("Invalid card");
4955
});
5056

5157
test(`Should return error when given a wrong number`, () => {
52-
expect(() => { getCardValue("11♦");}).toThrow("Invalid card");
58+
expect(() => {
59+
getCardValue("11♦");
60+
}).toThrow("Invalid card");
5361
});
5462

5563
test(`Should return error when given a wrong order`, () => {
56-
expect(() => { getCardValue("♦2");}).toThrow("Invalid card");
64+
expect(() => {
65+
getCardValue("♦2");
66+
}).toThrow("Invalid card");
5767
});
5868

5969
test(`Should return error when given no suit`, () => {
60-
expect(() => { getCardValue("3");}).toThrow("Invalid card");
70+
expect(() => {
71+
getCardValue("3");
72+
}).toThrow("Invalid card");
6173
});
6274

6375
test(`Should return error when given only suit`, () => {
64-
expect(() => { getCardValue("♦");}).toThrow("Invalid card");
76+
expect(() => {
77+
getCardValue("♦");
78+
}).toThrow("Invalid card");
6579
});
6680

67-
6881
// To learn how to test whether a function throws an error as expected in Jest,
6982
// please refer to the Jest documentation:
70-
// https://jestjs.io/docs/expect#tothrowerror
83+
// https://jestjs.io/docs/expect#tothrowerror

0 commit comments

Comments
 (0)