1 00:00:05,850 --> 00:00:12,420 I started off with creating a new library directory and like all of my other examples, let's keep this 2 00:00:12,420 --> 00:00:16,080 simple and just see the important aspects of what we are working on. 3 00:00:16,990 --> 00:00:22,660 So let's start off with the default example that Rust gives us and let's break it down really quickly. 4 00:00:22,750 --> 00:00:30,430 So at the very top, we see we have cfg test C CFG stands for configuration and tells us to only include 5 00:00:30,430 --> 00:00:33,880 the following when given a certain configuration option. 6 00:00:33,940 --> 00:00:39,040 So we are essentially configuring the following only for when we want to run test. 7 00:00:39,430 --> 00:00:43,600 Then we create a test module and we add this bit. 8 00:00:45,150 --> 00:00:45,960 Right here. 9 00:00:46,050 --> 00:00:51,390 And what this is going to do is it's basically going to tell the rest compiler, hey, the following 10 00:00:51,390 --> 00:00:57,060 function is a test and I'll show what happens when we forget that little bit right there. 11 00:00:58,440 --> 00:01:06,690 And then inside of that, we have the the test function and we have many options that we can choose 12 00:01:06,690 --> 00:01:12,630 from and we can see in the default example, it has the assert equals macro. 13 00:01:12,930 --> 00:01:18,670 And this is going to make sure that the left hand side is going to equal the right hand side. 14 00:01:18,690 --> 00:01:26,940 So to run this, we simply run cargo test and we concede that it outputs running one test and it is 15 00:01:26,940 --> 00:01:27,960 testing. 16 00:01:28,760 --> 00:01:30,950 It works, which is the name of our function. 17 00:01:30,950 --> 00:01:32,450 And in this case it passed. 18 00:01:32,450 --> 00:01:34,580 So it outputs okay to us. 19 00:01:35,740 --> 00:01:38,860 And it lets us know that we had one that passed. 20 00:01:40,130 --> 00:01:46,700 So what happens if we take this little porch portion out that I mentioned earlier and now we try to 21 00:01:46,700 --> 00:01:47,270 run it? 22 00:01:49,730 --> 00:01:51,970 Well, it says it's running zero test. 23 00:01:51,980 --> 00:01:52,280 Right. 24 00:01:52,280 --> 00:01:55,490 So now the rest compiler doesn't know that this is. 25 00:01:55,760 --> 00:02:01,070 So that's why that little bit is important to include above the function. 26 00:02:02,370 --> 00:02:06,080 So we can see that everything worked. 27 00:02:06,090 --> 00:02:10,440 So let's add another function and make it a failing one just to see what that looks like. 28 00:02:11,430 --> 00:02:14,810 And we can do this by using the panic keyword. 29 00:02:14,820 --> 00:02:20,490 So remember, we've got to include test and then we're going to say function. 30 00:02:20,640 --> 00:02:21,750 It fails. 31 00:02:23,470 --> 00:02:25,120 And now we're going to just say. 32 00:02:26,140 --> 00:02:26,950 Panic 33 00:02:29,440 --> 00:02:30,490 test failed. 34 00:02:32,710 --> 00:02:35,920 And now if we run this running cargo test. 35 00:02:37,020 --> 00:02:39,630 We now see what a failing test looks like. 36 00:02:39,630 --> 00:02:42,450 So again, it's going to tell us what function was ran. 37 00:02:42,450 --> 00:02:43,170 In this case. 38 00:02:43,400 --> 00:02:48,210 It fails and it failed, which is great because that's what we wanted to see. 39 00:02:48,240 --> 00:02:51,660 We just wanted to see what a failing test looks like. 40 00:02:52,430 --> 00:02:58,820 And we can use panic to induce a failing test in this situation. 41 00:02:59,240 --> 00:03:01,970 So that's just a very broad overview of testing. 42 00:03:01,970 --> 00:03:07,940 So let's get into a little bit more examples using annotations in the next lecture.