File tree Expand file tree Collapse file tree 2 files changed +7
-10
lines changed
Sprint-3/1-implement-and-rewrite-tests Expand file tree Collapse file tree 2 files changed +7
-10
lines changed Original file line number Diff line number Diff line change 8
8
// write one test at a time, and make it pass, build your solution up methodically
9
9
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
10
10
function getCardValue ( card ) {
11
-
12
- const rank = card . slice ( 0 , - 1 ) ; // Extract rank before the suit
11
+ const rank = card . slice ( 0 , - 1 ) ; // Get everything except the last char (the suit)
13
12
14
13
if ( rank === "A" ) {
15
14
return 11 ;
@@ -18,10 +17,8 @@ function getCardValue(card) {
18
17
} else if ( ! isNaN ( rank ) && Number ( rank ) >= 2 && Number ( rank ) <= 9 ) {
19
18
return Number ( rank ) ;
20
19
} else {
21
- throw new Error ( ' Invalid card rank: "${rank}"' ) ; //rather than just "Invalid card rank" we can show the actual rank that was invalid
20
+ throw new Error ( ` Invalid card rank: "${ rank } "` ) ; // rather than just "Invalid card rank" we can show the actual rank that was invalid
22
21
}
23
-
24
-
25
22
}
26
23
27
24
// The line below allows us to load the getCardValue function into tests in other files.
Original file line number Diff line number Diff line change @@ -29,23 +29,23 @@ test("should return 11 for Ace (A)", () => {
29
29
// Case 5: Handle Invalid Cards:
30
30
31
31
test ( "should throw an error for invalid input '1♣'" , ( ) => {
32
- expect ( ( ) => getCardValue ( "1♣" ) ) . toThrow ( " Invalid card" ) ;
32
+ expect ( ( ) => getCardValue ( "1♣" ) ) . toThrow ( ' Invalid card rank: "1"' ) ;
33
33
} ) ;
34
34
35
35
test ( "should throw an error for invalid input '1♦'" , ( ) => {
36
- expect ( ( ) => getCardValue ( "1♦" ) ) . toThrow ( " Invalid card" ) ;
36
+ expect ( ( ) => getCardValue ( "1♦" ) ) . toThrow ( ' Invalid card rank: "1"' ) ;
37
37
} ) ;
38
38
39
39
test ( "should throw an error for invalid input 'B♥'" , ( ) => {
40
- expect ( ( ) => getCardValue ( "B♥" ) ) . toThrow ( " Invalid card" ) ;
40
+ expect ( ( ) => getCardValue ( "B♥" ) ) . toThrow ( ' Invalid card rank: "B"' ) ;
41
41
} ) ;
42
42
43
43
test ( "should throw an error for invalid input 'Z♠'" , ( ) => {
44
- expect ( ( ) => getCardValue ( "Z♠" ) ) . toThrow ( " Invalid card" ) ;
44
+ expect ( ( ) => getCardValue ( "Z♠" ) ) . toThrow ( ' Invalid card rank: "Z"' ) ;
45
45
} ) ;
46
46
47
47
test ( "should throw an error for empty string" , ( ) => {
48
- expect ( ( ) => getCardValue ( "" ) ) . toThrow ( " Invalid card" ) ;
48
+ expect ( ( ) => getCardValue ( "" ) ) . toThrow ( ' Invalid card rank: ""' ) ;
49
49
} ) ;
50
50
51
51
You can’t perform that action at this time.
0 commit comments