So we know that we have a lot of different ascertained actions that we can use to logically evaluate.
If something is true or not.
So we see up here that we have a cert equals result and for so we're basically checking to make sure
that the result variable here which contains the value of two plus two equals four, which we know is
true.
But if we change this to five and then run testing again.
We see that they both fail.
So again, assert equals is just saying, hey, I want to make sure the left hand side equals the right
hand side.
So let's change this back to where it will be successful.
And now we have another assert macro and that is useful when we want to make sure that some condition
evaluates to true.
So what we'll do here is we'll come out of the module and we'll create another function called Simple
Add that's going to return a boolean.
And we'll say if two plus two equals four return true, else false.
So we know that this is going to return true.
So we'll come up here and we'll say Function call, simple add.
And then.
We will just say a cert simple ad.
And now we see that it says cannot find function simple ad in this scope because remember we're outside
of our module.
So in order for this function to be available to us, we need to include use super.
And then everything.
On the outside.
And Super's basically saying, hey, come out of these brackets and I want what's available out here
as well.
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
to say run test and we don't want this.
It fails to run anymore.
So.
A trait that we can add here is.
Ignore and this is going to allow us to just ignore running this test.
That way we don't have any failures.
So now if we run cargo test, we see that one it fails was ignored after we added this ignore attribute.
And then we said call simple ad.
We had simple out here and then our test was called simple add and in this case it evaluated the true
because our function down here evaluated a true.
So the difference between assert equals and assert is we can logically evaluate one item here.
Whereas up here you're.
Trying to evaluate that the left and the right are equal.
So it's just a little bit more flexibility in that regard.
And then one other test that we can have is assert not equals.
And what we can do up here is say not equals, and then we want it to now be five, right?
So this is going to be us testing.
Hey, we know that these two are not going to be equal, so we want to make sure that they're not equal
because result, for whatever reason did equal five.
When we know that it's two plus two, then we have a really big issue.
So in this case, we're going to evaluate that it's being evaluated correctly, which it was.
So we also have assert not equals.
And then sometimes we want to make sure that test panic so we're going to get rid of this ignore.
Attribute and we're going to put should panic.
So now we are expecting this test to panic.
So when we expect it to panic and it does panic now.
We have and OC and sometimes you want to make sure that certain situations a panic is caught or an error
of some sort is caught because it's good to make sure that your air handling is correct too in certain
situations.
So we have many ways to write, test and logically map out how we want our test to be executed.
And by default, the test are ran in parallel to speed up the testing.
But if you have additional threads available to you, then you can write cargo test and then tack tack
and then tack tack again test threads and then you can set it to your number of threads.
So we'll set it to one here and then we can set it to four here.
We don't have many tests and they're also not very expensive tests, so.
Checking out how the time difference in this case isn't viable.
But also, sometimes you might not want to run all your tests because if you get a really large program,
you could have hundreds, if not thousands of tests and running them all the time just to check the
functionality of one component just might not be a viable option for you.
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
this one test so we can say Cargo test, call, simple ad.
So this is going to be the name of our test function and we rerun it.
We see that the only test function that ran was the one that we explicitly called well in the event
that we want to run.
A subset of test, then we can run cargo test it.
And so we have the IT word and it fails and, and it works.
And now that we can see that down here, we ran it works and we ran, it fails.
So that's how we can run a subset of test.
And that's really all there is to it to testing.
So in the next section, we're going to build out our first.
A command line interface program that's going to do a find and replace on a file.