@@ -5,47 +5,46 @@ import { getCardValue } from "../implement/3-get-card-value.js";
55
66// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
77
8+ import { getCardValue } from "../implement/1-get-card-value.js" ;
9+
810test ( "Valid single-digit card" , ( ) => {
9- assert . equal ( getCardValue ( "9♠" ) , 9 ) ;
11+ expect ( getCardValue ( "9♠" ) ) . toEqual ( 9 ) ;
1012} ) ;
1113
1214test ( "Arbitrary non-card string" , ( ) => {
13- assert . throws (
14- ( ) => getCardValue ( "invalid" ) ,
15- / E x p e c t e d a n u m b e r f o l l o w e d b y a s u i t , b u t g o t " i n v a l i d " / ,
16- "Expected clear error"
15+ expect ( ( ) => getCardValue ( "invalid" ) ) . toThrow (
16+ 'Expected a number followed by a suit, but got "invalid"'
1717 ) ;
1818} ) ;
1919
20- // TODO: What other invalid card cases can you think of?
2120test ( "Ace returns 11" , ( ) => {
22- assert . equal ( getCardValue ( "A♠" ) , 11 ) ;
21+ expect ( getCardValue ( "A♠" ) ) . toEqual ( 11 ) ;
2322} ) ;
2423
2524test ( "Number card returns its numeric value" , ( ) => {
26- assert . equal ( getCardValue ( "2♥" ) , 2 ) ;
27- assert . equal ( getCardValue ( "7♦" ) , 7 ) ;
28- assert . equal ( getCardValue ( "10♣" ) , 10 ) ;
25+ expect ( getCardValue ( "2♥" ) ) . toEqual ( 2 ) ;
26+ expect ( getCardValue ( "7♦" ) ) . toEqual ( 7 ) ;
27+ expect ( getCardValue ( "10♣" ) ) . toEqual ( 10 ) ;
2928} ) ;
3029
3130test ( "Face cards return 10" , ( ) => {
32- assert . equal ( getCardValue ( "J♣" ) , 10 ) ;
33- assert . equal ( getCardValue ( "Q♦" ) , 10 ) ;
34- assert . equal ( getCardValue ( "K♥" ) , 10 ) ;
31+ expect ( getCardValue ( "J♣" ) ) . toEqual ( 10 ) ;
32+ expect ( getCardValue ( "Q♦" ) ) . toEqual ( 10 ) ;
33+ expect ( getCardValue ( "K♥" ) ) . toEqual ( 10 ) ;
3534} ) ;
3635
3736test ( "Invalid format throws an error" , ( ) => {
38- assert . throws ( ( ) => getCardValue ( "A★" ) , Error ) ;
39- assert . throws ( ( ) => getCardValue ( "11♠" ) , Error ) ;
40- assert . throws ( ( ) => getCardValue ( "X♥" ) , Error ) ;
41- assert . throws ( ( ) => getCardValue ( "A" ) , Error ) ;
42- assert . throws ( ( ) => getCardValue ( "♠A" ) , Error ) ;
43- assert . throws ( ( ) => getCardValue ( " A♠" ) , Error ) ;
44- assert . throws ( ( ) => getCardValue ( "A♠♠" ) , Error ) ;
45- assert . throws ( ( ) => getCardValue ( undefined ) , Error ) ;
46- assert . throws ( ( ) => getCardValue ( null ) , Error ) ;
47- assert . throws ( ( ) => getCardValue ( "" ) , Error ) ;
48- assert . throws ( ( ) => getCardValue ( "a♠" ) , Error ) ;
49- assert . throws ( ( ) => getCardValue ( "k♥" ) , Error ) ;
50- assert . throws ( ( ) => getCardValue ( "q♦" ) , Error ) ;
37+ expect ( ( ) => getCardValue ( "A★" ) ) . toThrow ( Error ) ;
38+ expect ( ( ) => getCardValue ( "11♠" ) ) . toThrow ( Error ) ;
39+ expect ( ( ) => getCardValue ( "X♥" ) ) . toThrow ( Error ) ;
40+ expect ( ( ) => getCardValue ( "A" ) ) . toThrow ( Error ) ;
41+ expect ( ( ) => getCardValue ( "♠A" ) ) . toThrow ( Error ) ;
42+ expect ( ( ) => getCardValue ( " A♠" ) ) . toThrow ( Error ) ;
43+ expect ( ( ) => getCardValue ( "A♠♠" ) ) . toThrow ( Error ) ;
44+ expect ( ( ) => getCardValue ( undefined ) ) . toThrow ( Error ) ;
45+ expect ( ( ) => getCardValue ( null ) ) . toThrow ( Error ) ;
46+ expect ( ( ) => getCardValue ( "" ) ) . toThrow ( Error ) ;
47+ expect ( ( ) => getCardValue ( "a♠" ) ) . toThrow ( Error ) ;
48+ expect ( ( ) => getCardValue ( "k♥" ) ) . toThrow ( Error ) ;
49+ expect ( ( ) => getCardValue ( "q♦" ) ) . toThrow ( Error ) ;
5150} ) ;
0 commit comments