@@ -7,6 +7,59 @@ test(`Should return 11 when given an ace card`, () => {
77 expect ( getCardValue ( "A♠" ) ) . toEqual ( 11 ) ;
88} ) ;
99
10+ // Case 2: Face cards (J, Q, K)
11+ test ( `Should return 10 when given a face card` , ( ) => {
12+ expect ( getCardValue ( "J♣" ) ) . toEqual ( 10 ) ;
13+ expect ( getCardValue ( "Q♦" ) ) . toEqual ( 10 ) ;
14+ expect ( getCardValue ( "K♥" ) ) . toEqual ( 10 ) ;
15+ } ) ;
16+
17+ // Case 3: Number cards (2-10)
18+ test ( `Should return the correct value for number cards` , ( ) => {
19+ expect ( getCardValue ( "2♠" ) ) . toEqual ( 2 ) ;
20+ expect ( getCardValue ( "3♣" ) ) . toEqual ( 3 ) ;
21+ expect ( getCardValue ( "4♦" ) ) . toEqual ( 4 ) ;
22+ expect ( getCardValue ( "5♥" ) ) . toEqual ( 5 ) ;
23+ expect ( getCardValue ( "6♠" ) ) . toEqual ( 6 ) ;
24+ expect ( getCardValue ( "7♣" ) ) . toEqual ( 7 ) ;
25+ expect ( getCardValue ( "8♦" ) ) . toEqual ( 8 ) ;
26+ expect ( getCardValue ( "9♥" ) ) . toEqual ( 9 ) ;
27+ expect ( getCardValue ( "10♠" ) ) . toEqual ( 10 ) ;
28+ } ) ;
29+
30+ // Case 4: Invalid ranks
31+ test ( `Should throw an error when given an invalid card` , ( ) => {
32+ expect ( ( ) => getCardValue ( "11♠" ) ) . toThrow ( Error ) ;
33+ expect ( ( ) => getCardValue ( "1♣" ) ) . toThrow ( Error ) ;
34+ expect ( ( ) => getCardValue ( "H♠" ) ) . toThrow ( Error ) ;
35+ } ) ;
36+
37+ // Case 5: Invalid suits
38+ test ( `Should throw an error when given an invalid suit` , ( ) => {
39+ expect ( ( ) => getCardValue ( "A♤" ) ) . toThrow ( Error ) ;
40+ expect ( ( ) => getCardValue ( "10X" ) ) . toThrow ( Error ) ;
41+ expect ( ( ) => getCardValue ( "KZ" ) ) . toThrow ( Error ) ;
42+ } ) ;
43+
44+ // Case 6: Invalid input types
45+ test ( `Should throw an error when given a non-string input` , ( ) => {
46+ expect ( ( ) => getCardValue ( 10 ) ) . toThrow ( Error ) ;
47+ expect ( ( ) => getCardValue ( null ) ) . toThrow ( Error ) ;
48+ expect ( ( ) => getCardValue ( undefined ) ) . toThrow ( Error ) ;
49+ expect ( ( ) => getCardValue ( { } ) ) . toThrow ( Error ) ;
50+ expect ( ( ) => getCardValue ( [ ] ) ) . toThrow ( Error ) ;
51+ } ) ;
52+
53+ // Case 7: Edge cases
54+ test ( `Should throw an error for edge cases` , ( ) => {
55+ expect ( ( ) => getCardValue ( "" ) ) . toThrow ( Error ) ;
56+ expect ( ( ) => getCardValue ( "A" ) ) . toThrow ( Error ) ;
57+ expect ( ( ) => getCardValue ( "♠" ) ) . toThrow ( Error ) ;
58+ expect ( ( ) => getCardValue ( "A♠♣" ) ) . toThrow ( Error ) ;
59+ expect ( ( ) => getCardValue ( "10♠♣" ) ) . toThrow ( Error ) ;
60+ } ) ;
61+
62+
1063// Suggestion: Group the remaining test data into these categories:
1164// Number Cards (2-10)
1265// Face Cards (J, Q, K)
0 commit comments