1 00:00:00,320 --> 00:00:00,980 If you're not so 2 00:00:00,980 --> 00:00:05,960 sure you implemented something correctly, it's always a good idea to add some tests. 3 00:00:05,960 --> 00:00:09,853 Let's add tests to our tabloid pile class to let us know if our addCards and 4 00:00:09,853 --> 00:00:13,180 removeCards functions are working like we want them to. 5 00:00:13,180 --> 00:00:17,758 And before I get to that, I want to make sure that this is the addCards function. 6 00:00:19,080 --> 00:00:23,560 Okay, now let's start by first creating a test folder for our project. 7 00:00:23,560 --> 00:00:28,390 First, create just a regular directory named Test in the root of your project. 8 00:00:31,550 --> 00:00:38,900 Then open the project structure window, file, project structure, 9 00:00:38,900 --> 00:00:43,470 and on the Modules tab, select your test folder and mark it as Tests. 10 00:00:46,250 --> 00:00:49,020 Then hit OK and now we've got a spot for our tests. 11 00:00:50,330 --> 00:00:53,360 Next up, let's create the tests. 12 00:00:53,360 --> 00:00:57,675 Click somewhere in your Tableau pile class and then use Command or 13 00:00:57,675 --> 00:01:02,960 CTRL+SHIFT+T and hit Enter to create a new test. 14 00:01:02,960 --> 00:01:07,490 Then for the testing library, make sure you've selected JUnit4 and for 15 00:01:07,490 --> 00:01:12,410 the members, let's pick addCards and removeCards. 16 00:01:12,410 --> 00:01:17,220 Also if you have something up here that says fix, just click on it and 17 00:01:17,220 --> 00:01:19,450 pick the intellijay distribution. 18 00:01:19,450 --> 00:01:22,990 Then hit OK, and now it's testing time. 19 00:01:22,990 --> 00:01:26,890 Remember for each test, we need to do three things. 20 00:01:26,890 --> 00:01:31,250 We need to arrange the objects we need, act on those objects, and 21 00:01:31,250 --> 00:01:33,320 then assert that we got the right result. 22 00:01:33,320 --> 00:01:36,610 So let's start by adding in these steps as comments. 23 00:01:36,610 --> 00:01:38,402 You can find them in the teacher's notes below as well. 24 00:01:45,263 --> 00:01:48,557 All right, let's take it from the top with the addCcards function. 25 00:01:49,700 --> 00:01:53,690 To test that our addCards function is working, we're going to need one Tableau 26 00:01:53,690 --> 00:01:58,150 pile and one mutable list of cards to add to that Tableau pile. 27 00:01:58,150 --> 00:02:01,826 So in the Arrange section, let's start by creating a new Tableau pile. 28 00:02:01,826 --> 00:02:06,789 val tableauPile 29 00:02:06,789 --> 00:02:11,400 = TableauPile. 30 00:02:11,400 --> 00:02:16,800 And then let's initialize our Tableau pile to contain only the King of spades, 31 00:02:16,800 --> 00:02:23,700 mutable list of card with a value of 12 for King and then spades. 32 00:02:23,700 --> 00:02:26,700 On the next line, let's create a new variable for 33 00:02:26,700 --> 00:02:30,030 the cards we're going to add to our Tableau pile. 34 00:02:30,030 --> 00:02:34,810 Val cards and let's set this equal to a list of 35 00:02:34,810 --> 00:02:39,820 one of the cards that would come after this one, or choose the Queen of hearts. 36 00:02:39,820 --> 00:02:42,230 So mutable list of and 37 00:02:42,230 --> 00:02:47,350 then the Queen of hearts, which has a value of 11 and a suit of hearts. 38 00:02:47,350 --> 00:02:49,000 Moving on to the act section, 39 00:02:49,000 --> 00:02:52,055 let's try adding that cards list to our Tableau pile. 40 00:02:52,055 --> 00:02:57,240 tableuPile.addCards and pass in our cards list. 41 00:02:58,320 --> 00:03:02,660 And finally in the assert section, let's check that our Tableau has the right 42 00:03:02,660 --> 00:03:08,330 number of cards which sends red Queen does match with the black King is two. 43 00:03:09,640 --> 00:03:14,387 So assertEquals 2 for the expected value and for 44 00:03:14,387 --> 00:03:19,290 the actual value, tableauPile.cards.size. 45 00:03:19,290 --> 00:03:24,031 Then let's hit the Run button next to our test. 46 00:03:27,014 --> 00:03:33,070 And it looks like the addCards function works, well, at least for those two cards. 47 00:03:33,070 --> 00:03:36,055 Anyhow in the next video, we'll continue the quest for 48 00:03:36,055 --> 00:03:38,290 testing with our removeCards function.