@@ -6,14 +6,40 @@ const getCardValue = require("../implement/3-get-card-value");
66
77// Case 1: Ace (A)
88test ( `Should return 11 when given an ace card` , ( ) => {
9+ expect ( getCardValue ( "A♣" ) ) . toEqual ( 11 ) ;
910 expect ( getCardValue ( "A♠" ) ) . toEqual ( 11 ) ;
11+ expect ( getCardValue ( "A♥" ) ) . toEqual ( 11 ) ;
12+ expect ( getCardValue ( "A♦" ) ) . toEqual ( 11 ) ;
1013} ) ;
1114
12- // Suggestion: Group the remaining test data into these categories:
13- // Number Cards (2-10)
14- // Face Cards (J, Q, K)
15- // Invalid Cards
15+ // Case 2: Number Cards (2-10)
16+ test ( `Should return a value equal to the number on the card` , ( ) => {
17+ expect ( getCardValue ( "2♠" ) ) . toEqual ( 2 ) ;
18+ expect ( getCardValue ( "5♥" ) ) . toEqual ( 5 ) ;
19+ expect ( getCardValue ( "9♦" ) ) . toEqual ( 9 ) ;
20+ expect ( getCardValue ( "10♣" ) ) . toEqual ( 10 ) ;
21+ } ) ;
22+
23+ // Case 3: Face Cards (J, Q, K)
24+ test ( `Should return 10 when given a face card` , ( ) => {
25+ expect ( getCardValue ( "K♥" ) ) . toEqual ( 10 ) ;
26+ expect ( getCardValue ( "J♠" ) ) . toEqual ( 10 ) ;
27+ expect ( getCardValue ( "Q♦" ) ) . toEqual ( 10 ) ;
28+ } ) ;
1629
30+ // Case 4: Invalid Cards
31+ test ( `All invalid cards should throw an Invalid error` , ( ) => {
32+ expect ( ( ) => getCardValue ( "9" ) ) . toThrow ( / I n v a l i d / ) ; // missing suit
33+ expect ( ( ) => getCardValue ( "♥" ) ) . toThrow ( / I n v a l i d / ) ; // missing rank
34+ expect ( ( ) => getCardValue ( "1♠" ) ) . toThrow ( / I n v a l i d / ) ; // invalid rank
35+ expect ( ( ) => getCardValue ( "11♠" ) ) . toThrow ( / I n v a l i d / ) ; // rank too high
36+ expect ( ( ) => getCardValue ( "9X" ) ) . toThrow ( / I n v a l i d / ) ; // invalid suit
37+ expect ( ( ) => getCardValue ( "♠9" ) ) . toThrow ( / I n v a l i d / ) ; // wrong order
38+ expect ( ( ) => getCardValue ( "9 ♠" ) ) . toThrow ( / I n v a l i d / ) ; // space inside
39+ expect ( ( ) => getCardValue ( "9♠ " ) ) . toThrow ( / I n v a l i d / ) ; // space after
40+ expect ( ( ) => getCardValue ( "" ) ) . toThrow ( / I n v a l i d / ) ; // empty string
41+ expect ( ( ) => getCardValue ( "j♠" ) ) . toThrow ( / I n v a l i d / ) ; // lowercase
42+ } ) ;
1743// To learn how to test whether a function throws an error as expected in Jest,
1844// please refer to the Jest documentation:
1945// https://jestjs.io/docs/expect#tothrowerror
0 commit comments