@@ -14,7 +14,35 @@ test(`Should return 11 when given an ace card`, () => {
1414// Face Cards (J, Q, K)
1515// Invalid Cards
1616
17+ // Case 2: Number Cards (2-10)
18+ test ( `Should return correct value for single digit number card` , ( ) => {
19+ expect ( getCardValue ( "9♠" ) ) . toEqual ( 9 ) ;
20+ expect ( getCardValue ( "5♦" ) ) . toEqual ( 5 ) ;
21+ expect ( getCardValue ( "10♣" ) ) . toEqual ( 10 ) ;
22+ } ) ;
23+
24+ // Case 3: Face cards (J, Q, K)
25+ test ( `Should return 10 for face cards (J, Q, K)` , ( ) => {
26+ expect ( getCardValue ( "J♥" ) ) . toEqual ( 10 ) ;
27+ expect ( getCardValue ( "Q♦" ) ) . toEqual ( 10 ) ;
28+ expect ( getCardValue ( "K♣" ) ) . toEqual ( 10 ) ;
29+ } ) ;
30+
31+ // Case 4: Invalid Cards
32+ test ( `Should throw error for invalid cards` , ( ) => {
33+ expect ( ( ) => getCardValue ( "invalid" ) ) . toThrow ( ) ;
34+ // too short
35+ expect ( ( ) => getCardValue ( "A" ) ) . toThrow ( ) ;
36+ // invalid rank
37+ expect ( ( ) => getCardValue ( "X♠" ) ) . toThrow ( ) ;
38+ // invalid suit
39+ expect ( ( ) => getCardValue ( "Kx" ) ) . toThrow ( ) ;
40+ // missing suit
41+ expect ( ( ) => getCardValue ( "10" ) ) . toThrow ( ) ;
42+ // empty string
43+ expect ( ( ) => getCardValue ( "" ) ) . toThrow ( ) ;
44+ } ) ;
45+
1746// To learn how to test whether a function throws an error as expected in Jest,
1847// please refer to the Jest documentation:
1948// https://jestjs.io/docs/expect#tothrowerror
20-
0 commit comments