소스 검색

More tests written

Lauren Green 6 년 전
부모
커밋
319ab8366d

+ 0
- 2
src/main/java/io/zipcoder/casino/ScoreSheet.java 파일 보기

@@ -2,8 +2,6 @@
2 2
 
3 3
 package io.zipcoder.casino;
4 4
 
5
-import com.sun.tools.example.debug.expr.ASCII_UCodeESC_CharStream;
6
-
7 5
 import java.util.*;
8 6
 
9 7
 public class ScoreSheet {

+ 8
- 1
src/main/java/io/zipcoder/casino/Yahtzee.java 파일 보기

@@ -21,7 +21,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
21 21
         this.betAmount = bid;
22 22
     }
23 23
 
24
-    public void startGame() {
24
+    public void createGame() {
25 25
         Dice dice1 = new Dice();
26 26
         Dice dice2 = new Dice();
27 27
         Dice dice3 = new Dice();
@@ -33,6 +33,10 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
33 33
         dicePlayer.getCup()[2] = dice3;
34 34
         dicePlayer.getCup()[3] = dice4;
35 35
         dicePlayer.getCup()[4] = dice5;
36
+    }
37
+
38
+    public void startGame() {
39
+        createGame();
36 40
 
37 41
         System.out.println("How much would you like to bet on this game?");
38 42
         int betAmount = scanner.nextInt();
@@ -222,4 +226,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
222 226
 
223 227
     }
224 228
 
229
+    public DicePlayer getDicePlayer() {
230
+        return dicePlayer;
231
+    }
225 232
 }

+ 379
- 0
src/test/java/io/zipcoder/casino/ScoreSheetTest.java 파일 보기

@@ -279,4 +279,383 @@ public class ScoreSheetTest {
279 279
 
280 280
     }
281 281
 
282
+    @Test
283
+    public void testSetRowCHANCE() {
284
+        //Given
285
+        ScoreSheet scoreSheet = new ScoreSheet();
286
+        Dice dice1 = new Dice();
287
+        Dice dice2 = new Dice();
288
+        Dice dice3 = new Dice();
289
+        Dice dice4 = new Dice();
290
+        Dice dice5 = new Dice();
291
+        Dice[] cup = new Dice[5];
292
+        cup[0] = dice1;
293
+        cup[1] = dice2;
294
+        cup[2] = dice3;
295
+        cup[3] = dice4;
296
+        cup[4] = dice5;
297
+        for (Dice d : cup) {
298
+            d.roll();
299
+        }
300
+        int expected = dice1.getValue() + dice2.getValue() + dice3.getValue() + dice4.getValue() + dice5.getValue();
301
+
302
+        //When
303
+
304
+        scoreSheet.setRow(ScoreSheet.ROW.CHANCE, cup);
305
+        int actual = scoreSheet.getScore(ScoreSheet.ROW.CHANCE);
306
+
307
+        //Then
308
+        Assert.assertEquals(expected, actual);
309
+
310
+    }
311
+
312
+    @Test
313
+    public void testSetRowACES() {
314
+        //Given
315
+        ScoreSheet scoreSheet = new ScoreSheet();
316
+        Dice dice1 = new Dice();
317
+        Dice dice2 = new Dice();
318
+        Dice dice3 = new Dice();
319
+        Dice dice4 = new Dice();
320
+        Dice dice5 = new Dice();
321
+        Dice[] cup = new Dice[5];
322
+        cup[0] = dice1;
323
+        cup[1] = dice2;
324
+        cup[2] = dice3;
325
+        cup[3] = dice4;
326
+        cup[4] = dice5;
327
+        for (Dice d : cup) {
328
+            d.roll();
329
+        }
330
+
331
+        //When
332
+        scoreSheet.setRow(ScoreSheet.ROW.ACES, cup);
333
+
334
+
335
+        //Then
336
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.ACES) != null));
337
+
338
+    }
339
+
340
+    @Test
341
+    public void testSetRowTWOS() {
342
+        //Given
343
+        ScoreSheet scoreSheet = new ScoreSheet();
344
+        Dice dice1 = new Dice();
345
+        Dice dice2 = new Dice();
346
+        Dice dice3 = new Dice();
347
+        Dice dice4 = new Dice();
348
+        Dice dice5 = new Dice();
349
+        Dice[] cup = new Dice[5];
350
+        cup[0] = dice1;
351
+        cup[1] = dice2;
352
+        cup[2] = dice3;
353
+        cup[3] = dice4;
354
+        cup[4] = dice5;
355
+        for (Dice d : cup) {
356
+            d.roll();
357
+        }
358
+
359
+        //When
360
+        scoreSheet.setRow(ScoreSheet.ROW.TWOS, cup);
361
+
362
+
363
+        //Then
364
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.TWOS) != null));
365
+
366
+    }
367
+
368
+    @Test
369
+    public void testSetRowTHREES() {
370
+        //Given
371
+        ScoreSheet scoreSheet = new ScoreSheet();
372
+        Dice dice1 = new Dice();
373
+        Dice dice2 = new Dice();
374
+        Dice dice3 = new Dice();
375
+        Dice dice4 = new Dice();
376
+        Dice dice5 = new Dice();
377
+        Dice[] cup = new Dice[5];
378
+        cup[0] = dice1;
379
+        cup[1] = dice2;
380
+        cup[2] = dice3;
381
+        cup[3] = dice4;
382
+        cup[4] = dice5;
383
+        for (Dice d : cup) {
384
+            d.roll();
385
+        }
386
+
387
+        //When
388
+        scoreSheet.setRow(ScoreSheet.ROW.THREES, cup);
389
+
390
+
391
+        //Then
392
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.THREES) != null));
393
+
394
+    }
395
+
396
+    @Test
397
+    public void testSetRowFOURS() {
398
+        //Given
399
+        ScoreSheet scoreSheet = new ScoreSheet();
400
+        Dice dice1 = new Dice();
401
+        Dice dice2 = new Dice();
402
+        Dice dice3 = new Dice();
403
+        Dice dice4 = new Dice();
404
+        Dice dice5 = new Dice();
405
+        Dice[] cup = new Dice[5];
406
+        cup[0] = dice1;
407
+        cup[1] = dice2;
408
+        cup[2] = dice3;
409
+        cup[3] = dice4;
410
+        cup[4] = dice5;
411
+        for (Dice d : cup) {
412
+            d.roll();
413
+        }
414
+
415
+        //When
416
+        scoreSheet.setRow(ScoreSheet.ROW.FOURS, cup);
417
+
418
+
419
+        //Then
420
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FOURS) != null));
421
+
422
+    }
423
+
424
+    @Test
425
+    public void testSetRowFIVES() {
426
+        //Given
427
+        ScoreSheet scoreSheet = new ScoreSheet();
428
+        Dice dice1 = new Dice();
429
+        Dice dice2 = new Dice();
430
+        Dice dice3 = new Dice();
431
+        Dice dice4 = new Dice();
432
+        Dice dice5 = new Dice();
433
+        Dice[] cup = new Dice[5];
434
+        cup[0] = dice1;
435
+        cup[1] = dice2;
436
+        cup[2] = dice3;
437
+        cup[3] = dice4;
438
+        cup[4] = dice5;
439
+        for (Dice d : cup) {
440
+            d.roll();
441
+        }
442
+
443
+        //When
444
+        scoreSheet.setRow(ScoreSheet.ROW.FIVES, cup);
445
+
446
+
447
+        //Then
448
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FIVES) != null));
449
+
450
+    }
451
+
452
+    @Test
453
+    public void testSetRowSIXES() {
454
+        //Given
455
+        ScoreSheet scoreSheet = new ScoreSheet();
456
+        Dice dice1 = new Dice();
457
+        Dice dice2 = new Dice();
458
+        Dice dice3 = new Dice();
459
+        Dice dice4 = new Dice();
460
+        Dice dice5 = new Dice();
461
+        Dice[] cup = new Dice[5];
462
+        cup[0] = dice1;
463
+        cup[1] = dice2;
464
+        cup[2] = dice3;
465
+        cup[3] = dice4;
466
+        cup[4] = dice5;
467
+        for (Dice d : cup) {
468
+            d.roll();
469
+        }
470
+
471
+        //When
472
+        scoreSheet.setRow(ScoreSheet.ROW.SIXES, cup);
473
+
474
+
475
+        //Then
476
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.SIXES) != null));
477
+
478
+    }
479
+
480
+    @Test
481
+    public void testSetRowThreeOfAKind() {
482
+        //Given
483
+        ScoreSheet scoreSheet = new ScoreSheet();
484
+        Dice dice1 = new Dice();
485
+        Dice dice2 = new Dice();
486
+        Dice dice3 = new Dice();
487
+        Dice dice4 = new Dice();
488
+        Dice dice5 = new Dice();
489
+        Dice[] cup = new Dice[5];
490
+        cup[0] = dice1;
491
+        cup[1] = dice2;
492
+        cup[2] = dice3;
493
+        cup[3] = dice4;
494
+        cup[4] = dice5;
495
+        for (Dice d : cup) {
496
+            d.roll();
497
+        }
498
+
499
+        //When
500
+        scoreSheet.setRow(ScoreSheet.ROW.THREEOFAKIND, cup);
501
+
502
+
503
+        //Then
504
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.THREEOFAKIND) != null));
505
+
506
+    }
507
+
508
+    @Test
509
+    public void testSetRowFourOfAKind() {
510
+        //Given
511
+        ScoreSheet scoreSheet = new ScoreSheet();
512
+        Dice dice1 = new Dice();
513
+        Dice dice2 = new Dice();
514
+        Dice dice3 = new Dice();
515
+        Dice dice4 = new Dice();
516
+        Dice dice5 = new Dice();
517
+        Dice[] cup = new Dice[5];
518
+        cup[0] = dice1;
519
+        cup[1] = dice2;
520
+        cup[2] = dice3;
521
+        cup[3] = dice4;
522
+        cup[4] = dice5;
523
+        for (Dice d : cup) {
524
+            d.roll();
525
+        }
526
+
527
+        //When
528
+        scoreSheet.setRow(ScoreSheet.ROW.FOUROFAKIND, cup);
529
+
530
+
531
+        //Then
532
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FOUROFAKIND) != null));
533
+
534
+    }
535
+
536
+    @Test
537
+    public void testSetRowFullHouse() {
538
+        //Given
539
+        ScoreSheet scoreSheet = new ScoreSheet();
540
+        Dice dice1 = new Dice();
541
+        Dice dice2 = new Dice();
542
+        Dice dice3 = new Dice();
543
+        Dice dice4 = new Dice();
544
+        Dice dice5 = new Dice();
545
+        Dice[] cup = new Dice[5];
546
+        cup[0] = dice1;
547
+        cup[1] = dice2;
548
+        cup[2] = dice3;
549
+        cup[3] = dice4;
550
+        cup[4] = dice5;
551
+        for (Dice d : cup) {
552
+            d.roll();
553
+        }
554
+
555
+        //When
556
+        scoreSheet.setRow(ScoreSheet.ROW.FULLHOUSE, cup);
557
+
558
+
559
+        //Then
560
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FULLHOUSE) != null));
561
+
562
+    }
563
+
564
+    @Test
565
+    public void testSetRowSmallStraight() {
566
+        //Given
567
+        ScoreSheet scoreSheet = new ScoreSheet();
568
+        Dice dice1 = new Dice();
569
+        Dice dice2 = new Dice();
570
+        Dice dice3 = new Dice();
571
+        Dice dice4 = new Dice();
572
+        Dice dice5 = new Dice();
573
+        Dice[] cup = new Dice[5];
574
+        cup[0] = dice1;
575
+        cup[1] = dice2;
576
+        cup[2] = dice3;
577
+        cup[3] = dice4;
578
+        cup[4] = dice5;
579
+        for (Dice d : cup) {
580
+            d.roll();
581
+        }
582
+
583
+        //When
584
+        scoreSheet.setRow(ScoreSheet.ROW.SMALLSTRAIGHT, cup);
585
+
586
+
587
+        //Then
588
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.SMALLSTRAIGHT) != null));
589
+
590
+    }
591
+
592
+    @Test
593
+    public void testSetRowLargeStraight() {
594
+        //Given
595
+        ScoreSheet scoreSheet = new ScoreSheet();
596
+        Dice dice1 = new Dice();
597
+        Dice dice2 = new Dice();
598
+        Dice dice3 = new Dice();
599
+        Dice dice4 = new Dice();
600
+        Dice dice5 = new Dice();
601
+        Dice[] cup = new Dice[5];
602
+        cup[0] = dice1;
603
+        cup[1] = dice2;
604
+        cup[2] = dice3;
605
+        cup[3] = dice4;
606
+        cup[4] = dice5;
607
+        for (Dice d : cup) {
608
+            d.roll();
609
+        }
610
+
611
+        //When
612
+        scoreSheet.setRow(ScoreSheet.ROW.LARGESTRAIGHT, cup);
613
+
614
+
615
+        //Then
616
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.LARGESTRAIGHT) != null));
617
+
618
+    }
619
+
620
+    @Test
621
+    public void testSetRowYahtzee() {
622
+        //Given
623
+        ScoreSheet scoreSheet = new ScoreSheet();
624
+        Dice dice1 = new Dice();
625
+        Dice dice2 = new Dice();
626
+        Dice dice3 = new Dice();
627
+        Dice dice4 = new Dice();
628
+        Dice dice5 = new Dice();
629
+        Dice[] cup = new Dice[5];
630
+        cup[0] = dice1;
631
+        cup[1] = dice2;
632
+        cup[2] = dice3;
633
+        cup[3] = dice4;
634
+        cup[4] = dice5;
635
+        for (Dice d : cup) {
636
+            d.roll();
637
+        }
638
+
639
+        //When
640
+        scoreSheet.setRow(ScoreSheet.ROW.YAHTZEE, cup);
641
+
642
+
643
+        //Then
644
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.YAHTZEE) != null));
645
+
646
+    }
647
+
648
+    @Test
649
+    public void testGetSize() {
650
+        //Given
651
+        int expected = 13;
652
+
653
+        //When
654
+        int actual = ScoreSheet.getSize();
655
+
656
+        //Then
657
+        Assert.assertEquals(expected, actual);
658
+
659
+    }
660
+
282 661
 }

+ 51
- 0
src/test/java/io/zipcoder/casino/YahtzeeTest.java 파일 보기

@@ -0,0 +1,51 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class YahtzeeTest {
7
+
8
+    Player player = new Player("Dan", 1000);
9
+    Yahtzee yahtzee = new Yahtzee(player);
10
+
11
+    @Test
12
+    public void testBet() {
13
+        //When
14
+        yahtzee.bet(400);
15
+        int expected = 600;
16
+        int actual = player.getCurrentBalance();
17
+
18
+        //Then
19
+        Assert.assertEquals(expected, actual);
20
+
21
+
22
+    }
23
+
24
+    @Test
25
+    public void testSetBidGetBid() {
26
+        //When
27
+        yahtzee.setBid(400);
28
+        int expected = 400;
29
+        int actual = yahtzee.getBid();
30
+
31
+        //Then
32
+        Assert.assertEquals(expected, actual);
33
+
34
+
35
+    }
36
+
37
+    @Test
38
+    public void testCreateGame() {
39
+        //When
40
+        yahtzee.createGame();
41
+        int expected = 5;
42
+        int actual = yahtzee.getDicePlayer().getCup().length;
43
+
44
+        //Then
45
+        Assert.assertEquals(expected, actual);
46
+
47
+
48
+    }
49
+
50
+
51
+}