1
00:00:06,000 --> 00:00:07,170
Hey everybody what's going on.

2
00:00:07,200 --> 00:00:11,300
Caleb with Debb slopes just continuing the last video it started to get a little bit long.

3
00:00:11,340 --> 00:00:16,200
And basically what we're doing is we're writing test for our data model we're basically going to check

4
00:00:16,200 --> 00:00:19,740
to make sure the values are how they should be.

5
00:00:19,740 --> 00:00:23,350
We're also going to basically test some of our functions and features.

6
00:00:23,460 --> 00:00:27,710
And then in the following video we're actually going to continue testing functions and features.

7
00:00:27,780 --> 00:00:29,180
I'm going to show you a few things.

8
00:00:29,300 --> 00:00:32,290
You know things you might want to test you might want to think about.

9
00:00:32,520 --> 00:00:38,940
And let's go ahead and pull up in a project so we left off testing the initialization and making sure

10
00:00:38,940 --> 00:00:44,690
that when we give our instances values that they actually take them and their set.

11
00:00:44,790 --> 00:00:52,470
We also set up a protocol stub to allow our struct to be equatable meaning we can directly correlate

12
00:00:52,500 --> 00:00:58,450
between two instances of our custom class which is pretty or custom struct which is pretty cool.

13
00:00:58,470 --> 00:01:00,420
So let's let's go ahead and write a test.

14
00:01:00,420 --> 00:01:06,220
Now I want to write a test to basically check to see that these values come in as zero.

15
00:01:06,230 --> 00:01:11,400
When I started so phunk test values.

16
00:01:11,800 --> 00:01:17,930
That's what we're testing the values are initially 0.

17
00:01:17,940 --> 00:01:26,100
So let's go ahead and let's say ex-city assert equal and we're going to go ahead and use our system

18
00:01:26,100 --> 00:01:30,260
under test cases we have an empty instance we just created a blank instance.

19
00:01:30,260 --> 00:01:33,930
And so I can type as the dot value a.

20
00:01:34,230 --> 00:01:36,690
And it should be equal to zero.

21
00:01:36,690 --> 00:01:42,150
Now we're going to assert the same thing ex-city assert equals Sutt value B.

22
00:01:42,330 --> 00:01:45,240
And we're going to make sure that is also zero.

23
00:01:45,450 --> 00:01:52,230
So if I build this the little test diamond will appear if I click on it the test will run and we'll

24
00:01:52,230 --> 00:01:53,870
see how we did.

25
00:01:53,880 --> 00:01:58,590
We're going to make sure that when we create a brand new instance that those test values come in as

26
00:01:58,690 --> 00:01:59,540
zero.

27
00:01:59,970 --> 00:02:06,660
And let's see the test is running shouldn't be taking this long.

28
00:02:06,900 --> 00:02:07,440
Oh there we go.

29
00:02:07,440 --> 00:02:09,570
Sorry I had to reopen the simulator.

30
00:02:09,570 --> 00:02:09,930
Awesome.

31
00:02:09,930 --> 00:02:14,660
So our test passes that means that these values do come in as zero.

32
00:02:14,850 --> 00:02:19,250
Now you're probably wondering now do I need to test everything and.

33
00:02:19,320 --> 00:02:25,690
Well as the app currently works it depends on these values being 0 from the very beginning.

34
00:02:25,710 --> 00:02:29,760
And so if someone were to come in and change that these tests would then fail showing hey there's a

35
00:02:29,760 --> 00:02:30,630
problem.

36
00:02:30,630 --> 00:02:34,890
The way that our app works on a foundational level has been changed so it's really important to test

37
00:02:34,890 --> 00:02:41,550
as much as you can but ultimately realize that it's not kind of a make or break thing if you don't test

38
00:02:41,670 --> 00:02:43,450
every single single single thing.

39
00:02:43,590 --> 00:02:48,970
It's probably going to be fine but it's always good to err on the side of testing more than less.

40
00:02:48,990 --> 00:02:51,690
So go ahead and let's do another one here.

41
00:02:51,720 --> 00:02:56,480
We're going to test if inserting a value actually changes the value of a.

42
00:02:56,610 --> 00:03:11,430
So phunk test values inserting values changes value a K so we have our system under test which is our

43
00:03:11,430 --> 00:03:13,490
calculation manager so Sutt.

44
00:03:13,500 --> 00:03:19,410
And if I call the insert function what that's going to do is it's going to change value according to

45
00:03:19,410 --> 00:03:20,150
my code.

46
00:03:20,250 --> 00:03:22,440
So I'm going to pass in a value.

47
00:03:22,440 --> 00:03:23,740
How about 10.

48
00:03:24,010 --> 00:03:24,700
OK.

49
00:03:25,110 --> 00:03:32,800
And we're going to go ahead and say ex-city assert equal sut value a should now be equal to 10.

50
00:03:33,120 --> 00:03:38,700
And remember every single time we set it to nil and we create a brand new fresh instance of calculation

51
00:03:38,700 --> 00:03:39,060
manager.

52
00:03:39,060 --> 00:03:42,630
So let's go ahead and let's run this test with commend you.

53
00:03:42,740 --> 00:03:46,830
It's going to run every single one of our tests which we probably don't need to do.

54
00:03:46,830 --> 00:03:48,090
We just needed to run that one.

55
00:03:48,090 --> 00:03:52,790
But anyway good to make sure my other tests still pass and look at that.

56
00:03:52,830 --> 00:03:54,630
It passes when we insert a value.

57
00:03:54,810 --> 00:03:56,460
The value is properly set.

58
00:03:56,460 --> 00:03:57,660
Very cool.

59
00:03:57,660 --> 00:04:03,600
So next you know we could check value b we know it's going to work the same way but we should check

60
00:04:03,600 --> 00:04:13,950
to see if the operand is nil every time we create a new instance so phunk test operand wups is initially

61
00:04:15,040 --> 00:04:15,810
no.

62
00:04:16,230 --> 00:04:20,190
So let's just say ex-city assert nil

63
00:04:22,940 --> 00:04:24,730
ex-city a certain nil there it is.

64
00:04:24,880 --> 00:04:30,910
And we're going to say sut current operand build to show the diamond and then click on it to run just

65
00:04:30,910 --> 00:04:36,740
that one singular test and hopefully it will pass because it's nil when we first create it.

66
00:04:36,760 --> 00:04:37,330
Awesome.

67
00:04:37,540 --> 00:04:40,990
And we have not set a value in our instance so that's perfect.

68
00:04:41,050 --> 00:04:45,630
It is in fact nil as it should be it's not going to carry over from a previous calculation.

69
00:04:45,970 --> 00:04:50,620
And now let's let's actually test setting the operand.

70
00:04:50,620 --> 00:04:55,090
So we got to kind of think about the user process here and we're going to well let's write the test

71
00:04:55,090 --> 00:05:06,900
first so phunk test operand K sets operand you know what let's do a better name.

72
00:05:06,900 --> 00:05:11,350
How about when given operand sets operand.

73
00:05:11,930 --> 00:05:12,490
OK.

74
00:05:12,690 --> 00:05:15,160
And so what we're going to do is we're going to go through the process here.

75
00:05:15,180 --> 00:05:21,130
We're going to say hey let's insert a value right because we type you know maybe 10 plus that the upper

76
00:05:21,130 --> 00:05:24,210
end so let's do it like the user would they would type.

77
00:05:24,300 --> 00:05:30,060
They wouldn't type this but what would happen is we would insert a value of maybe 20 and then we would

78
00:05:30,060 --> 00:05:35,610
type sut dot and we would add the operand and we have a function for that set operand.

79
00:05:35,730 --> 00:05:39,100
So we can set the opera and maybe I'm going to do 20.

80
00:05:39,390 --> 00:05:42,750
Subtract something else.

81
00:05:42,750 --> 00:05:50,850
And what I can do now is I can test ex-city not nil and I can verify that our operand is set a value

82
00:05:50,860 --> 00:05:54,020
it's not nil anymore so I can type S U T.

83
00:05:54,210 --> 00:05:56,210
Current operand build it.

84
00:05:56,220 --> 00:05:57,480
And now we can run this test.

85
00:05:57,480 --> 00:06:03,030
So let's make sure that our operand actually now has a value set.

86
00:06:03,090 --> 00:06:07,110
It's testing everything and boom the test comes back a success.

87
00:06:07,110 --> 00:06:14,040
Now if I were to ever basically set this to have a value like maybe I wanted to set it to be multiply

88
00:06:14,100 --> 00:06:16,870
initially that would be a really bad thing to do.

89
00:06:17,370 --> 00:06:21,630
But basically if I did that and tried to run all of my tests now watch what happens.

90
00:06:23,850 --> 00:06:26,740
It's going to go ahead and launch my tests.

91
00:06:26,820 --> 00:06:29,490
I changed my code and how it works and look at that.

92
00:06:29,520 --> 00:06:34,530
One of our tests now fails it says Hey hey it's it's not that's not what it's supposed to do.

93
00:06:34,530 --> 00:06:35,760
Man what's wrong with you.

94
00:06:35,970 --> 00:06:38,030
So that's awesome.

95
00:06:38,160 --> 00:06:45,390
But there is something that we could be doing it's not necessary but this message here is not very descriptive.

96
00:06:45,420 --> 00:06:51,930
So what we can actually do at the end of any assertion at the very end we can type a comma and then

97
00:06:51,930 --> 00:06:55,770
insert a string basically describing what is supposed to happen.

98
00:06:55,770 --> 00:07:02,610
So we should say should or maybe have at this operand should be nil.

99
00:07:02,880 --> 00:07:10,550
And now when I run the tests check out what happens it's going to run it's going to launch our tests

100
00:07:10,640 --> 00:07:12,530
they will fail and then check it out.

101
00:07:12,530 --> 00:07:16,650
When I look at the error message it's going to actually print out what should be happening.

102
00:07:16,670 --> 00:07:18,570
Operand should be nil.

103
00:07:18,590 --> 00:07:25,190
So if I get rid of this and then go back and run all my tests again that test will now pass pretty cool

104
00:07:25,190 --> 00:07:25,960
how this works.

105
00:07:26,060 --> 00:07:30,370
I'm sure you can see that this is really really really helpful stuff.

106
00:07:30,380 --> 00:07:31,380
There we go past.

107
00:07:31,430 --> 00:07:38,900
So let's write one last test here to make sure that when we actually perform a calculation that it actually

108
00:07:38,900 --> 00:07:40,350
does what it's supposed to do.

109
00:07:40,370 --> 00:07:46,500
So go ahead and type phunk test calculation for.

110
00:07:46,550 --> 00:07:49,520
Well let's just say for values.

111
00:07:49,520 --> 00:07:53,630
So we're going to go ahead and go through the whole process we're going to insert two values.

112
00:07:53,630 --> 00:07:58,820
We're going to set the operand and then we're going to call our calculate function down here which returns

113
00:07:58,820 --> 00:07:59,700
an integer value.

114
00:07:59,810 --> 00:08:02,090
So type set.

115
00:08:02,150 --> 00:08:07,380
Insert and let's do maybe 15 sut insert.

116
00:08:07,460 --> 00:08:08,480
And what's the next value.

117
00:08:08,480 --> 00:08:12,950
How about gee I don't know how about five.

118
00:08:13,070 --> 00:08:13,460
OK.

119
00:08:13,460 --> 00:08:18,430
And you know what we should we should call a set operand here and let's do subtract.

120
00:08:18,590 --> 00:08:25,580
So we imagine we're on the calculator we type 15 subtract 5 and then we want to call calculate and we're

121
00:08:25,580 --> 00:08:27,950
going to set that when we push the equals button later.

122
00:08:28,070 --> 00:08:34,430
But what we can do is we can basically call sut dot calculate and that's going to return an integer

123
00:08:34,430 --> 00:08:37,060
to us with whatever the calculation value is.

124
00:08:37,190 --> 00:08:39,090
But of course we're not using that call.

125
00:08:39,170 --> 00:08:50,600
So we should use X TC assert equal and we should basically pass in such to calculate loops like so.

126
00:08:51,110 --> 00:08:55,160
And then we're going to want to make sure that it actually equals what we think it should.

127
00:08:55,160 --> 00:08:58,510
So right now 15 minus 5 should be 10.

128
00:08:58,820 --> 00:09:02,840
When we run this test it should work and you should check this with all the operands.

129
00:09:02,840 --> 00:09:04,910
This is just one example of a test.

130
00:09:05,000 --> 00:09:06,220
So I'm going to build it.

131
00:09:06,410 --> 00:09:10,940
I'm going to click my little test icon here and let's see if our code is good if our test work.

132
00:09:11,030 --> 00:09:14,340
That means that we're ready to move this into production.

133
00:09:14,360 --> 00:09:14,850
Awesome.

134
00:09:14,870 --> 00:09:16,620
Look at that it works very very cool.

135
00:09:16,640 --> 00:09:25,360
Now we can do it again with multiply we could say you know 10 times five should be 50 after it's calculated.

136
00:09:25,370 --> 00:09:31,290
So let's do that again let's run this test 10 times five should result in 50.

137
00:09:31,490 --> 00:09:32,600
Launching the test.

138
00:09:32,600 --> 00:09:34,700
Testing and success.

139
00:09:34,800 --> 00:09:36,170
It worked awesome.

140
00:09:36,170 --> 00:09:39,760
So we are now successfully testing our calculation.

141
00:09:39,800 --> 00:09:48,380
And now let's make sure that when we actually test our values that it actually clears them all out.

142
00:09:48,380 --> 00:09:59,480
So let's type phunk test maybe clear K when called Clear's values.

143
00:10:00,200 --> 00:10:04,760
So let's just go ahead and go through this process again let's insert all of this.

144
00:10:04,760 --> 00:10:11,840
Or how about let's just insert one value can let's say we changed our mind and we called Set clear values.

145
00:10:11,870 --> 00:10:17,210
Now the things that should be cleared according to the function value should be set back to zero even

146
00:10:17,210 --> 00:10:18,410
though it was set right here.

147
00:10:18,410 --> 00:10:26,870
So let's make sure that it is X X s.t. assert equal and some value a should now be 0.

148
00:10:27,010 --> 00:10:33,060
K x TC assert equal value B should also be zero.

149
00:10:33,380 --> 00:10:36,850
And our value entery array should be empty.

150
00:10:36,860 --> 00:10:37,790
There should be nothing in it.

151
00:10:37,790 --> 00:10:43,690
So go ahead and type LCT assert equal some value and tree array.

152
00:10:43,790 --> 00:10:45,940
And it should be an empty array.

153
00:10:45,950 --> 00:10:48,180
So let's go ahead and let's try that out.

154
00:10:48,200 --> 00:10:50,130
Of course it's going to return a string.

155
00:10:50,130 --> 00:10:55,040
We use that later to basically set the label of the calculator to be a string.

156
00:10:55,040 --> 00:11:00,380
Now we're just going to go ahead and do an underscore equals and then go ahead and run this test so

157
00:11:00,470 --> 00:11:06,800
build it and then click the little diamond there it'll go ahead and run and then we'll see if it passed.

158
00:11:06,800 --> 00:11:09,250
Here we go testing and look at that.

159
00:11:09,320 --> 00:11:12,350
It passes so our data model is clean.

160
00:11:12,350 --> 00:11:17,870
We have run tests to check the initialization to check the setting of values the modifying of values

161
00:11:17,930 --> 00:11:21,450
as well as some of our functions that run from our model.

162
00:11:21,500 --> 00:11:22,550
Very very cool stuff.

163
00:11:22,550 --> 00:11:27,020
Let's head over to the next video where we're going to start testing out some of our features and functions

164
00:11:27,020 --> 00:11:29,180
and writing tests for our view controller.

165
00:11:29,180 --> 00:11:29,940
I'll see you there.
