@@ -5,12 +5,73 @@ 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- test ( "Valid single-digit card" , ( ) => {
9- assert . equal ( getCardValue ( "9♠" ) , 9 ) ;
8+ test ( "Valid single-digit number cards return correct values" , ( ) => {
9+ assert . equal ( getCardValue ( "2♠" ) , 2 ) ;
10+ assert . equal ( getCardValue ( "5♥" ) , 5 ) ;
11+ assert . equal ( getCardValue ( "9♦" ) , 9 ) ;
1012} ) ;
1113
12- test ( "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" ) ;
14+ test ( "Valid double-digit card (10) returns 10" , ( ) => {
15+ assert . equal ( getCardValue ( "10♥" ) , 10 ) ;
16+ assert . equal ( getCardValue ( "10♣" ) , 10 ) ;
1417} ) ;
1518
16- // TODO: What other invalid card cases can you think of?
19+ test ( "Ace cards return 11" , ( ) => {
20+ assert . equal ( getCardValue ( "A♠" ) , 11 ) ;
21+ assert . equal ( getCardValue ( "A♦" ) , 11 ) ;
22+ } ) ;
23+
24+ test ( "Face cards (J, Q, K) return 10" , ( ) => {
25+ assert . equal ( getCardValue ( "J♣" ) , 10 ) ;
26+ assert . equal ( getCardValue ( "Q♦" ) , 10 ) ;
27+ assert . equal ( getCardValue ( "K♠" ) , 10 ) ;
28+ } ) ;
29+
30+ // Invalid Input Cases
31+ test ( "Throws error for arbitrary non-card string" , ( ) => {
32+ assert . throws (
33+ ( ) => getCardValue ( "invalid" ) ,
34+ / E x p e c t e d a c a r d r a n k f o l l o w e d b y a s u i t /
35+ ) ;
36+ } ) ;
37+
38+ test ( "Throws error for invalid ranks or suit-like characters" , ( ) => {
39+ assert . throws (
40+ ( ) => getCardValue ( "1♠" ) ,
41+ / E x p e c t e d a c a r d r a n k f o l l o w e d b y a s u i t /
42+ ) ;
43+ assert . throws (
44+ ( ) => getCardValue ( "11♥" ) ,
45+ / E x p e c t e d a c a r d r a n k f o l l o w e d b y a s u i t /
46+ ) ;
47+ assert . throws (
48+ ( ) => getCardValue ( "Z♠" ) ,
49+ / E x p e c t e d a c a r d r a n k f o l l o w e d b y a s u i t /
50+ ) ;
51+ } ) ;
52+
53+ test ( "Throws error for invalid or missing suit" , ( ) => {
54+ assert . throws (
55+ ( ) => getCardValue ( "10" ) ,
56+ / E x p e c t e d a c a r d r a n k f o l l o w e d b y a s u i t /
57+ ) ;
58+ assert . throws (
59+ ( ) => getCardValue ( "AX" ) ,
60+ / E x p e c t e d a c a r d r a n k f o l l o w e d b y a s u i t /
61+ ) ;
62+ } ) ;
63+
64+ test ( "Throws error for reversed order (suit before rank)" , ( ) => {
65+ assert . throws (
66+ ( ) => getCardValue ( "♠A" ) ,
67+ / E x p e c t e d a c a r d r a n k f o l l o w e d b y a s u i t /
68+ ) ;
69+ } ) ;
70+
71+ test ( "Throws error for empty string or non-string input" , ( ) => {
72+ assert . throws (
73+ ( ) => getCardValue ( "" ) ,
74+ / E x p e c t e d a c a r d r a n k f o l l o w e d b y a s u i t /
75+ ) ;
76+ assert . throws ( ( ) => getCardValue ( 10 ) , / E x p e c t e d a s t r i n g / ) ;
77+ } ) ;
0 commit comments