1 00:00:06,220 --> 00:00:14,920 So we know that we have a lot of different ascertained actions that we can use to logically evaluate. 2 00:00:15,890 --> 00:00:17,420 If something is true or not. 3 00:00:17,780 --> 00:00:23,870 So we see up here that we have a cert equals result and for so we're basically checking to make sure 4 00:00:23,870 --> 00:00:29,360 that the result variable here which contains the value of two plus two equals four, which we know is 5 00:00:29,360 --> 00:00:29,870 true. 6 00:00:30,470 --> 00:00:35,090 But if we change this to five and then run testing again. 7 00:00:36,010 --> 00:00:37,570 We see that they both fail. 8 00:00:38,080 --> 00:00:46,060 So again, assert equals is just saying, hey, I want to make sure the left hand side equals the right 9 00:00:46,090 --> 00:00:46,900 hand side. 10 00:00:47,020 --> 00:00:51,400 So let's change this back to where it will be successful. 11 00:00:51,400 --> 00:00:59,440 And now we have another assert macro and that is useful when we want to make sure that some condition 12 00:00:59,440 --> 00:01:01,150 evaluates to true. 13 00:01:01,420 --> 00:01:08,350 So what we'll do here is we'll come out of the module and we'll create another function called Simple 14 00:01:08,350 --> 00:01:12,910 Add that's going to return a boolean. 15 00:01:14,050 --> 00:01:24,400 And we'll say if two plus two equals four return true, else false. 16 00:01:24,550 --> 00:01:28,150 So we know that this is going to return true. 17 00:01:28,450 --> 00:01:37,300 So we'll come up here and we'll say Function call, simple add. 18 00:01:41,010 --> 00:01:41,760 And then. 19 00:01:42,740 --> 00:01:48,470 We will just say a cert simple ad. 20 00:01:50,910 --> 00:01:56,850 And now we see that it says cannot find function simple ad in this scope because remember we're outside 21 00:01:56,850 --> 00:01:57,900 of our module. 22 00:01:57,900 --> 00:02:06,300 So in order for this function to be available to us, we need to include use super. 23 00:02:07,300 --> 00:02:08,620 And then everything. 24 00:02:10,610 --> 00:02:11,600 On the outside. 25 00:02:12,210 --> 00:02:19,260 And Super's basically saying, hey, come out of these brackets and I want what's available out here 26 00:02:19,260 --> 00:02:19,980 as well. 27 00:02:21,510 --> 00:02:30,120 So now if we run this, we'll be able and I need to include test here and now you can see this is going 28 00:02:30,120 --> 00:02:34,100 to say run test and we don't want this. 29 00:02:34,110 --> 00:02:36,420 It fails to run anymore. 30 00:02:36,420 --> 00:02:37,080 So. 31 00:02:39,930 --> 00:02:43,490 A trait that we can add here is. 32 00:02:44,340 --> 00:02:49,760 Ignore and this is going to allow us to just ignore running this test. 33 00:02:49,770 --> 00:02:51,420 That way we don't have any failures. 34 00:02:51,420 --> 00:03:00,180 So now if we run cargo test, we see that one it fails was ignored after we added this ignore attribute. 35 00:03:01,460 --> 00:03:04,010 And then we said call simple ad. 36 00:03:06,330 --> 00:03:13,470 We had simple out here and then our test was called simple add and in this case it evaluated the true 37 00:03:13,500 --> 00:03:17,210 because our function down here evaluated a true. 38 00:03:17,220 --> 00:03:25,920 So the difference between assert equals and assert is we can logically evaluate one item here. 39 00:03:25,920 --> 00:03:27,360 Whereas up here you're. 40 00:03:28,430 --> 00:03:31,310 Trying to evaluate that the left and the right are equal. 41 00:03:31,310 --> 00:03:34,310 So it's just a little bit more flexibility in that regard. 42 00:03:35,060 --> 00:03:41,300 And then one other test that we can have is assert not equals. 43 00:03:42,620 --> 00:03:50,420 And what we can do up here is say not equals, and then we want it to now be five, right? 44 00:03:50,420 --> 00:03:52,780 So this is going to be us testing. 45 00:03:52,790 --> 00:03:58,760 Hey, we know that these two are not going to be equal, so we want to make sure that they're not equal 46 00:03:58,910 --> 00:04:03,560 because result, for whatever reason did equal five. 47 00:04:03,560 --> 00:04:07,250 When we know that it's two plus two, then we have a really big issue. 48 00:04:07,400 --> 00:04:13,490 So in this case, we're going to evaluate that it's being evaluated correctly, which it was. 49 00:04:13,490 --> 00:04:16,480 So we also have assert not equals. 50 00:04:17,300 --> 00:04:24,140 And then sometimes we want to make sure that test panic so we're going to get rid of this ignore. 51 00:04:26,000 --> 00:04:30,680 Attribute and we're going to put should panic. 52 00:04:31,250 --> 00:04:36,050 So now we are expecting this test to panic. 53 00:04:36,290 --> 00:04:40,340 So when we expect it to panic and it does panic now. 54 00:04:41,110 --> 00:04:51,430 We have and OC and sometimes you want to make sure that certain situations a panic is caught or an error 55 00:04:51,970 --> 00:04:58,030 of some sort is caught because it's good to make sure that your air handling is correct too in certain 56 00:04:58,030 --> 00:04:59,110 situations. 57 00:04:59,920 --> 00:05:05,620 So we have many ways to write, test and logically map out how we want our test to be executed. 58 00:05:05,830 --> 00:05:10,360 And by default, the test are ran in parallel to speed up the testing. 59 00:05:11,350 --> 00:05:19,720 But if you have additional threads available to you, then you can write cargo test and then tack tack 60 00:05:19,720 --> 00:05:25,090 and then tack tack again test threads and then you can set it to your number of threads. 61 00:05:25,090 --> 00:05:28,840 So we'll set it to one here and then we can set it to four here. 62 00:05:29,050 --> 00:05:33,250 We don't have many tests and they're also not very expensive tests, so. 63 00:05:34,140 --> 00:05:38,310 Checking out how the time difference in this case isn't viable. 64 00:05:39,030 --> 00:05:45,300 But also, sometimes you might not want to run all your tests because if you get a really large program, 65 00:05:45,300 --> 00:05:50,670 you could have hundreds, if not thousands of tests and running them all the time just to check the 66 00:05:50,670 --> 00:05:56,680 functionality of one component just might not be a viable option for you. 67 00:05:56,700 --> 00:06:04,170 So what we can do is we can run a subset of tests or we can just say, Hey, I want you to only run 68 00:06:04,170 --> 00:06:10,920 this one test so we can say Cargo test, call, simple ad. 69 00:06:11,070 --> 00:06:15,900 So this is going to be the name of our test function and we rerun it. 70 00:06:15,900 --> 00:06:23,160 We see that the only test function that ran was the one that we explicitly called well in the event 71 00:06:23,160 --> 00:06:24,750 that we want to run. 72 00:06:25,620 --> 00:06:31,560 A subset of test, then we can run cargo test it. 73 00:06:31,560 --> 00:06:38,420 And so we have the IT word and it fails and, and it works. 74 00:06:38,430 --> 00:06:44,700 And now that we can see that down here, we ran it works and we ran, it fails. 75 00:06:44,700 --> 00:06:49,260 So that's how we can run a subset of test. 76 00:06:49,260 --> 00:06:52,320 And that's really all there is to it to testing. 77 00:06:52,320 --> 00:06:55,470 So in the next section, we're going to build out our first. 78 00:06:56,600 --> 00:07:03,230 A command line interface program that's going to do a find and replace on a file.