1- // This statement loads the getCardValue function you wrote in the implement directory.
2- // We will use the same function, but write tests for it using Jest in this file.
31const getCardValue = require ( "../implement/3-get-card-value" ) ;
42
5- test ( "should return 11 for Ace of Spades" , ( ) => {
6- const aceofSpades = getCardValue ( "A♠" ) ;
7- expect ( aceofSpades ) . toEqual ( 11 ) ;
3+ // Case 1: Handle Number Cards (2-10)
4+ test ( "should return the value of number cards (2-10)" , ( ) => {
5+ expect ( getCardValue ( "2♣" ) ) . toEqual ( 2 ) ;
6+ expect ( getCardValue ( "5♥" ) ) . toEqual ( 5 ) ;
7+ expect ( getCardValue ( "10♦" ) ) . toEqual ( 10 ) ;
88} ) ;
99
10- // Case 2: Handle Number Cards (2-10):
11- test ( "should return a 5 for the card with rank of 5 like(5♥) " , ( ) => {
12- const fiveofHearts = getCardValue ( "5♥" ) ;
13- expect ( fiveofHearts ) . toEqual ( 5 ) ;
10+ // Case 2: Handle Face Cards (J, Q, K)
11+ test ( "should return 10 for face cards (J, Q, K)" , ( ) => {
12+ expect ( getCardValue ( "J♠" ) ) . toEqual ( 10 ) ;
13+ expect ( getCardValue ( "Q♣" ) ) . toEqual ( 10 ) ;
14+ expect ( getCardValue ( "K♦" ) ) . toEqual ( 10 ) ;
15+ } ) ;
16+
17+ // Case 3: Handle Ace (A)
18+ test ( "should return 11 for Ace cards" , ( ) => {
19+ expect ( getCardValue ( "A♠" ) ) . toEqual ( 11 ) ;
20+ expect ( getCardValue ( "A♣" ) ) . toEqual ( 11 ) ;
21+ } ) ;
1422
15- } )
16- // Case 3: Handle Face Cards (J, Q, K):
17- test ( "shoild return 10 fore the faced cart like king(K♦) and queen (Q♣)" )
18- const kingCard = getCardValue ( "K♦" ) ;
19- const queenCard = getCardValue ( "Q♣" ) ;
20- expect ( kingCard ) . toEqual ( 10 ) ;
21- expect ( queenCard ) . toEqual ( 10 ) ;
22- // Case 4: Handle Ace (A):
23- test ( "should return 11 for Ace of Spades" , ( ) => {
24- const aceofSpades = getCardValue ( "A♣" ) ;
25- expect ( aceofSpades ) . toEqual ( 11 ) ;
23+ // Case 4: Handle Invalid Cards
24+ test ( "should return 'Invalid card rank.' for invalid cards" , ( ) => {
25+ expect ( getCardValue ( "z♣" ) ) . toEqual ( "Invalid card rank." ) ;
26+ expect ( getCardValue ( "11♠" ) ) . toEqual ( "Invalid card rank." ) ;
2627} ) ;
27- // Case 5: Handle Invalid Cards:
28- test ( "should return invalid card rank for invalid inputs like(z♣)" , ( ) => {
29- const invalidCard = getCardValue ( "z♣" ) ;
30- expect ( invalidCard ) . toEqual ( "Invalid card rank." ) ;
31- } ) ;
0 commit comments