Skip to content

Commit 4327606

Browse files
committed
Address PR review: expand edge and invalid test cases
1 parent f801388 commit 4327606

5 files changed

Lines changed: 77 additions & 1 deletion

File tree

‎implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,15 @@ test("corrctly get angle type", function(){
2626
assert.equal(getAngleType(400), "Invalid angle");
2727
});
2828

29+
test("corrctly get angle type", function(){
30+
assert.equal(getAngleType(0), "Invalid angle");
31+
});
32+
33+
test("corrctly get angle type", function(){
34+
assert.equal(getAngleType(360), "Invalid angle");
35+
});
36+
37+
test("corrctly get angle type", function(){
38+
assert.equal(getAngleType(-70), "Invalid angle");
39+
});
2940

‎implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ test("Basic proper fraction", () => {
3030
assert.equal(isProperFraction(-1, 2), true);
3131
});
3232

33+
test("Basic proper fraction", () => {
34+
assert.equal(isProperFraction(1, -2), true);
35+
});
3336

37+
test("Basic proper fraction", () => {
38+
assert.equal(isProperFraction(-1, -2), true);
39+
});
3440

3541

3642

‎implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,38 @@ test("Missing suit throws", () => {
3737

3838

3939
// TODO: What other invalid card cases can you think of?
40+
41+
test("Empty string throws", () => {
42+
assert.throws(
43+
() => getCardValue(""),
44+
/Expected a number followed by a suit/
45+
);
46+
});
47+
48+
test("Suit only throws", () => {
49+
assert.throws(
50+
() => getCardValue("♠"),
51+
/Expected a number followed by a suit/
52+
);
53+
});
54+
55+
test("Invalid rank throws", () => {
56+
assert.throws(
57+
() => getCardValue("1♠"),
58+
/Expected a number followed by a suit/
59+
);
60+
});
61+
62+
test("Invalid suit throws", () => {
63+
assert.throws(
64+
() => getCardValue("9X"),
65+
/Expected a number followed by a suit/
66+
);
67+
});
68+
69+
test("Rank with no suit character throws", () => {
70+
assert.throws(
71+
() => getCardValue("10"),
72+
/Expected a number followed by a suit/
73+
);
74+
});

‎implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ test(`should return true for proper fractions`, () => {
1111
expect(isProperFraction(1, 2)).toEqual(true);
1212
expect(isProperFraction(0, 5)).toEqual(true);
1313
expect(isProperFraction(-1, 2)).toEqual(true);
14+
expect(isProperFraction(1, -2)).toEqual(true);
15+
expect(isProperFraction(-1, -2)).toEqual(true);
1416
});
1517

1618
test(`should return false for improper fractions`, () => {

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ test(`Should return 11 when given an ace card`, () => {
1818

1919
test(`Should return numeric value for number cards`, () => {
2020
expect(getCardValue("2♥")).toEqual(2);
21+
expect(getCardValue("3♠")).toEqual(3);
22+
expect(getCardValue("4♣")).toEqual(4);
23+
expect(getCardValue("5♥")).toEqual(5);
24+
expect(getCardValue("6♦")).toEqual(6);
25+
expect(getCardValue("7♠")).toEqual(7);
26+
expect(getCardValue("8♣")).toEqual(8);
2127
expect(getCardValue("9♠")).toEqual(9);
2228
expect(getCardValue("10♦")).toEqual(10);
2329
});
@@ -28,11 +34,27 @@ test(`Should return 10 for face cards`, () => {
2834
expect(getCardValue("K♥")).toEqual(10);
2935
});
3036

31-
test(`Should throw for invalid cards`, () => {
37+
// Invalid cards
38+
test(`should throw for invalid cards`, () => {
3239
expect(() => getCardValue("invalid")).toThrow(
3340
/Expected a number followed by a suit, but got "invalid"/
3441
);
3542
expect(() => getCardValue("A")).toThrow(
3643
/Expected a number followed by a suit/
3744
);
45+
expect(() => getCardValue("")).toThrow(
46+
/Expected a number followed by a suit/
47+
);
48+
expect(() => getCardValue("♠")).toThrow(
49+
/Expected a number followed by a suit/
50+
);
51+
expect(() => getCardValue("1♠")).toThrow(
52+
/Expected a number followed by a suit/
53+
);
54+
expect(() => getCardValue("9X")).toThrow(
55+
/Expected a number followed by a suit/
56+
);
57+
expect(() => getCardValue("10")).toThrow(
58+
/Expected a number followed by a suit/
59+
);
3860
});

0 commit comments

Comments
 (0)