@@ -8,6 +8,50 @@ test("should return 11 for Ace of Spades", () => {
88} ) ;
99
1010// Case 2: Handle Number Cards (2-10):
11+ test ( "should return correct value for number cards (2–10)" , ( ) => {
12+ expect ( getCardValue ( "2♥" ) ) . toEqual ( 2 ) ;
13+ expect ( getCardValue ( "7♣" ) ) . toEqual ( 7 ) ;
14+ expect ( getCardValue ( "10♦" ) ) . toEqual ( 10 ) ;
15+ expect ( getCardValue ( "5♠" ) ) . toEqual ( 5 ) ;
16+ } ) ;
1117// Case 3: Handle Face Cards (J, Q, K):
18+ test ( "should return 10 for face cards (J, Q, K)" , ( ) => {
19+ expect ( getCardValue ( "J♠" ) ) . toEqual ( 10 ) ;
20+ expect ( getCardValue ( "Q♦" ) ) . toEqual ( 10 ) ;
21+ expect ( getCardValue ( "K♥" ) ) . toEqual ( 10 ) ;
22+ expect ( getCardValue ( "J♣" ) ) . toEqual ( 10 ) ;
23+ } ) ;
1224// Case 4: Handle Ace (A):
25+ test ( "should return 11 for Ace cards" , ( ) => {
26+ expect ( getCardValue ( "A♦" ) ) . toEqual ( 11 ) ;
27+ expect ( getCardValue ( "A♥" ) ) . toEqual ( 11 ) ;
28+ expect ( getCardValue ( "A♣" ) ) . toEqual ( 11 ) ;
29+ expect ( getCardValue ( "A♠" ) ) . toEqual ( 11 ) ;
30+ } ) ;
1331// Case 5: Handle Invalid Cards:
32+ test ( "should throw an error for invalid card ranks and provide a descriptive message" , ( ) => {
33+ // These specific ranks are all invalid
34+ expect ( ( ) => getCardValue ( "Z♠" ) ) . toThrow (
35+ 'Invalid or unrecognized card rank: "Z"'
36+ ) ;
37+ expect ( ( ) => getCardValue ( "1♥" ) ) . toThrow (
38+ 'Invalid or unrecognized card rank: "1"'
39+ ) ;
40+ expect ( ( ) => getCardValue ( "11♦" ) ) . toThrow (
41+ 'Invalid or unrecognized card rank: "11"'
42+ ) ;
43+ expect ( ( ) => getCardValue ( "X♣" ) ) . toThrow (
44+ 'Invalid or unrecognized card rank: "X"'
45+ ) ;
46+
47+ // These should throw because they result in an empty or whitespace rank
48+ expect ( ( ) => getCardValue ( " ♣" ) ) . toThrow (
49+ 'Invalid or unrecognized card rank: " "'
50+ ) ;
51+ expect ( ( ) => getCardValue ( "♣" ) ) . toThrow (
52+ 'Invalid or unrecognized card rank: ""'
53+ ) ;
54+ expect ( ( ) => getCardValue ( "" ) ) . toThrow (
55+ 'Invalid or unrecognized card rank: ""'
56+ ) ;
57+ } ) ;
0 commit comments