@@ -3,14 +3,42 @@ import test from "node:test";
33
44import { getCardValue } from "../implement/3-get-card-value.js" ;
55
6- // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
7-
86test ( "Valid single-digit card" , ( ) => {
97 assert . equal ( getCardValue ( "9♠" ) , 9 ) ;
108} ) ;
119
1210test ( "Arbitrary non-card string" , ( ) => {
13- assert . throws ( ( ) => getCardValue ( "invalid" ) , / 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 " / , "Expected clear error" ) ;
11+ assert . throws (
12+ ( ) => getCardValue ( "invalid" ) ,
13+ / 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 " / ,
14+ "Expected clear error"
15+ ) ;
16+ } ) ;
17+
18+ test ( "Ace returns 11" , ( ) => {
19+ assert . equal ( getCardValue ( "A♠" ) , 11 ) ;
20+ assert . equal ( getCardValue ( "A♥" ) , 11 ) ;
21+ } ) ;
22+
23+ test ( "Face cards return 10" , ( ) => {
24+ assert . equal ( getCardValue ( "J♠" ) , 10 ) ;
25+ assert . equal ( getCardValue ( "Q♥" ) , 10 ) ;
26+ assert . equal ( getCardValue ( "K♦" ) , 10 ) ;
27+ } ) ;
28+
29+ test ( "Number cards return their value" , ( ) => {
30+ assert . equal ( getCardValue ( "2♣" ) , 2 ) ;
31+ assert . equal ( getCardValue ( "5♥" ) , 5 ) ;
32+ assert . equal ( getCardValue ( "7♠" ) , 7 ) ;
33+ assert . equal ( getCardValue ( "10♦" ) , 10 ) ;
1434} ) ;
1535
16- // TODO: What other invalid card cases can you think of?
36+ test ( "Invalid cards throw an error" , ( ) => {
37+ assert . throws ( ( ) => getCardValue ( "A" ) ) ;
38+ assert . throws ( ( ) => getCardValue ( "♠" ) ) ;
39+ assert . throws ( ( ) => getCardValue ( "11♠" ) ) ;
40+ assert . throws ( ( ) => getCardValue ( "1♠" ) ) ;
41+ assert . throws ( ( ) => getCardValue ( "hello" ) ) ;
42+ assert . throws ( ( ) => getCardValue ( "" ) ) ;
43+ assert . throws ( ( ) => getCardValue ( "A♠♠" ) ) ;
44+ } ) ;
0 commit comments