1
00:00:02,260 --> 00:00:09,270
This what's up and what the price as does Snopes dot com.

2
00:00:09,290 --> 00:00:15,590
And in this exciting video we are going to create the logic for the application or the math that does

3
00:00:15,590 --> 00:00:21,350
the calculations and sometimes this is called The business logic if you look up programming definitions.

4
00:00:21,350 --> 00:00:27,980
Business Logic is the code that basically does the thinking and that code is very important and needs

5
00:00:27,980 --> 00:00:29,540
to be tested needs to be well-written.

6
00:00:29,540 --> 00:00:36,860
And so what we're going to do is we are going to create the not only the code to do the math we're asking

7
00:00:36,900 --> 00:00:40,820
to write a unit test your very first unit test so it can be well tested and trust me.

8
00:00:41,120 --> 00:00:45,620
If you have any type of unit tests in your project when you are applying for a job if you're doing an

9
00:00:45,620 --> 00:00:50,630
example project you will get a thousand more points than the other candidates who do not have unit test.

10
00:00:50,630 --> 00:00:54,230
It's very important to companies so this is a good thing to start learning right here right from the

11
00:00:54,230 --> 00:00:55,150
beginning.

12
00:00:55,160 --> 00:01:01,250
So what we're going to do is we're going to select our just look at your project up here and then we're

13
00:01:01,250 --> 00:01:05,110
going to go to Ed. at Target.

14
00:01:05,180 --> 00:01:05,440
OK.

15
00:01:05,450 --> 00:01:08,230
And we're going to add a unit testing Bunuel now.

16
00:01:08,270 --> 00:01:12,770
Before I do that if you created your project with a testing bundle it'll be right here ready so you

17
00:01:12,770 --> 00:01:17,430
know when you create a new project and if you want to do unit tests or you itas We've had ours off.

18
00:01:17,630 --> 00:01:21,590
But if yours is on then you don't need to do this step but I'm assuming that you've done the same thing.

19
00:01:21,590 --> 00:01:28,490
I haven't heard of turnoffs So we're going to go to editor at Target and we're going to add a U.S. unit

20
00:01:28,490 --> 00:01:32,290
testing bundle and we're going to say window shop retests.

21
00:01:32,300 --> 00:01:33,080
Great great great.

22
00:01:33,080 --> 00:01:34,060
All part of this project.

23
00:01:34,070 --> 00:01:34,740
Wonderful.

24
00:01:35,910 --> 00:01:36,290
Awesome.

25
00:01:36,300 --> 00:01:39,740
So now we have unit test as you can see in this folder here.

26
00:01:39,780 --> 00:01:41,210
We have some functions for us here.

27
00:01:41,220 --> 00:01:42,450
So that's great.

28
00:01:42,450 --> 00:01:46,260
So the next thing to do is actually create some code.

29
00:01:46,760 --> 00:01:53,100
So here in the windows shopper I'm going to create a new group and we're going to call this model and

30
00:01:53,100 --> 00:01:54,600
what we're going to do.

31
00:01:54,620 --> 00:01:54,990
We might.

32
00:01:55,030 --> 00:01:58,530
So we might have had this code let's say in a model file on a wage model.

33
00:01:58,530 --> 00:02:00,000
It's a small app but it's fine.

34
00:02:00,000 --> 00:02:02,600
So in this model file We're going to do a new file.

35
00:02:02,730 --> 00:02:07,490
It's going to be a swift file and we're going to call this wage for lack of a better term.

36
00:02:07,560 --> 00:02:10,500
We would assume maybe in the future would add more logic here.

37
00:02:10,600 --> 00:02:12,080
It's going to create this wage.

38
00:02:12,210 --> 00:02:16,220
And what we want to do is create a class called wage.

39
00:02:16,320 --> 00:02:21,520
And inside this class we're going to create a class function class funk.

40
00:02:21,890 --> 00:02:27,150
And what we want to do is create a function that will basically take inputs and then produce an output

41
00:02:27,150 --> 00:02:33,420
basically the math behind this if you can think about it is we take the price of the item and we divide

42
00:02:33,420 --> 00:02:36,910
it by your hourly wage and that's going to tell us how many hours that you need.

43
00:02:36,970 --> 00:02:39,470
And so we want to write a function that does that for us.

44
00:02:39,540 --> 00:02:42,930
OK so we're going to call this get ours.

45
00:02:42,960 --> 00:02:43,420
All right.

46
00:02:43,440 --> 00:02:48,110
I'm going to say for wage to say wage and swimmy of type double.

47
00:02:48,180 --> 00:02:55,170
And then we're going to say and price right now the price the Colon's can be here and of type double

48
00:02:55,430 --> 00:02:59,700
and we're going to return an integer you know because that's the that's the number that says 14 hours

49
00:02:59,700 --> 00:03:00,160
15 hours.

50
00:03:00,160 --> 00:03:03,630
We don't want to say fifteen point five hours because we just want solid numbers.

51
00:03:03,630 --> 00:03:04,300
OK.

52
00:03:04,680 --> 00:03:08,700
And we're going to return it.

53
00:03:08,730 --> 00:03:09,390
All right.

54
00:03:09,480 --> 00:03:11,570
Now maybe you are seeing some new things here.

55
00:03:11,670 --> 00:03:12,700
OK.

56
00:03:12,750 --> 00:03:14,130
Hours for wage why do you have.

57
00:03:14,130 --> 00:03:16,110
Why do you have to parameter names here.

58
00:03:16,110 --> 00:03:19,510
Well what I have here actually is a parameter name.

59
00:03:19,530 --> 00:03:22,020
And then the variable name itself.

60
00:03:22,020 --> 00:03:26,680
So this is more for autocomplete when you're typing in things you can see a readable description if

61
00:03:26,690 --> 00:03:27,000
you like.

62
00:03:27,000 --> 00:03:28,420
All that makes a lot of sense.

63
00:03:28,560 --> 00:03:30,330
And this is the actual variable that you use.

64
00:03:30,330 --> 00:03:36,000
And so you can actually name your parameters like so and this indexes the parameter name space and then

65
00:03:36,000 --> 00:03:38,440
the variable name with the colon and then the type.

66
00:03:38,760 --> 00:03:43,830
OK so get ours and what we want to do is we want to write code to get the appropriate hours.

67
00:03:43,830 --> 00:03:48,280
Now I'm not going to be doing test driven development here where you do want thing you felt you another

68
00:03:48,290 --> 00:03:52,680
thing I felt I'm going to write unit tests the way I write it and most people I know write them which

69
00:03:52,710 --> 00:03:54,690
is you build it out and then you test it.

70
00:03:54,870 --> 00:03:55,630
OK.

71
00:03:55,630 --> 00:03:58,080
And so remember we talked about the math.

72
00:03:58,080 --> 00:03:59,930
It's basically price divided by wage.

73
00:03:59,940 --> 00:04:02,070
But ours is a unique circumstance.

74
00:04:02,430 --> 00:04:04,170
So let's let's do some math here.

75
00:04:04,170 --> 00:04:11,220
Let's say we have an item that's $250 and move this up here $250 and 53 cents.

76
00:04:11,460 --> 00:04:14,570
And let's say we make $15 an hour or 15 50 an hour.

77
00:04:14,640 --> 00:04:15,310
OK.

78
00:04:15,750 --> 00:04:18,840
So that's saying you need to work sixteen point sixteen hours.

79
00:04:18,840 --> 00:04:20,740
Well that's confusing where we don't want to.

80
00:04:20,790 --> 00:04:24,480
We're just trying to make a purchase decision we don't want to calculate mid hours of what we actually

81
00:04:24,480 --> 00:04:26,990
want to have happen is we want the result to be 17.

82
00:04:27,120 --> 00:04:27,620
OK.

83
00:04:27,690 --> 00:04:31,180
Because we know 17 hours guarantees the purchase OK.

84
00:04:31,350 --> 00:04:34,140
And it's cleaner and easier to read and that's the logic that we want.

85
00:04:34,140 --> 00:04:39,150
So what we want it what we don't want to end up doing is we want to round up whatever the value is we

86
00:04:39,150 --> 00:04:41,400
want around up to the next whole number.

87
00:04:41,400 --> 00:04:42,260
Okay.

88
00:04:42,360 --> 00:04:44,550
And so we need to write the logic for that as well too.

89
00:04:44,700 --> 00:04:49,140
So we would do the division math and then we round up to the next whole number so we can guarantee that

90
00:04:49,140 --> 00:04:54,490
if we work this many hours it pays for it and you might have a little more left over but that's ok.

91
00:04:54,510 --> 00:04:57,350
I think that calls for a better user experience.

92
00:04:57,370 --> 00:04:58,860
And so it's pretty simple actually.

93
00:04:58,860 --> 00:05:04,610
So we just say return and what we're going to do is we're going to say seal this is math ceiling.

94
00:05:04,620 --> 00:05:07,420
So it's going to go up to the next level.

95
00:05:07,470 --> 00:05:11,280
So if you give us 15 50 it would go up to 16.

96
00:05:11,280 --> 00:05:11,850
Okay.

97
00:05:12,120 --> 00:05:15,410
And we're going to say price divided by wage.

98
00:05:15,410 --> 00:05:16,090
Right.

99
00:05:16,500 --> 00:05:17,910
So that's what we want.

100
00:05:17,970 --> 00:05:22,790
But the problem with this is it's going to return a double k cannot return double the type int.

101
00:05:22,980 --> 00:05:26,820
And remember the application costs for an integer because that's what we're showing to the user.

102
00:05:26,820 --> 00:05:30,510
So this is easy enough we'll just convert it to an int when it's done.

103
00:05:30,790 --> 00:05:33,920
So in like so.

104
00:05:34,270 --> 00:05:38,280
And the good thing about this is if it's like even five point zero it or get rid of the zero and just

105
00:05:38,280 --> 00:05:41,090
converted to an integer which is exactly what we want.

106
00:05:41,400 --> 00:05:47,100
So that math is not that hard but let's go and write the unit test for now to ensure that it's giving

107
00:05:47,100 --> 00:05:48,160
us what we want.

108
00:05:48,390 --> 00:05:48,980
OK.

109
00:05:49,140 --> 00:05:54,270
So what we're going to do is we're going to go into our window shopper tests and let's just put a function

110
00:05:54,270 --> 00:06:05,250
in here I'm going to say phunk or just say test wage or get our test tests wage for hours test hours

111
00:06:06,960 --> 00:06:09,170
which said tests get hours.

112
00:06:09,530 --> 00:06:15,210
So I'm going to say OK and all we want to do is run some tests to make sure that our code is actually

113
00:06:15,750 --> 00:06:17,000
working correctly.

114
00:06:17,010 --> 00:06:20,160
We read in the code we think it works correctly but how do we know for sure.

115
00:06:20,160 --> 00:06:21,420
So it's pretty simple.

116
00:06:21,450 --> 00:06:27,370
We're going to use ex-city assert and I'm not covering everything in unit tests.

117
00:06:27,390 --> 00:06:30,400
I'm just covering what we need to know for this application.

118
00:06:30,390 --> 00:06:34,340
So ex-city assert and you can assert true or false.

119
00:06:34,440 --> 00:06:36,040
We're just going to say X-C to you sir.

120
00:06:36,060 --> 00:06:39,870
And then pasand an expression because it's just easier for this example.

121
00:06:39,900 --> 00:06:42,240
And so what we want to do is we want to call this wage function.

122
00:06:42,240 --> 00:06:46,100
So wage get hours and remember this is a class function.

123
00:06:46,110 --> 00:06:53,850
So you don't have to create a copy or an object of wage to use this you just wage Dopp then the function

124
00:06:53,850 --> 00:06:54,260
name.

125
00:06:54,270 --> 00:06:59,430
And this is only one function in memory that every instance of a wage is going to use or you can access

126
00:06:59,430 --> 00:07:00,620
from anywhere.

127
00:07:00,630 --> 00:07:06,700
So in here I should be able to type in wage Daut but not at home nothing's coming up.

128
00:07:06,720 --> 00:07:13,320
So because we added the unit tests later on in the project our code files don't recognize that target.

129
00:07:13,470 --> 00:07:19,260
So we need to do is actually go over to our wage file here and open up the right hand side here and

130
00:07:19,260 --> 00:07:21,140
see this little file that's highlighted here.

131
00:07:21,140 --> 00:07:22,530
This is called the file inspector.

132
00:07:22,530 --> 00:07:28,680
Now you have to do is click this target here window shopper tests and it will now let you test and have

133
00:07:28,680 --> 00:07:29,940
access to this wage file.

134
00:07:29,940 --> 00:07:38,430
So now if I go back to window shop or tests I can say wage dot hours and it's now available so we can

135
00:07:38,580 --> 00:07:39,690
start passing in numbers here.

136
00:07:39,690 --> 00:07:44,460
So what I can do is I can say for wage so let's say we were making $15 an hour actually make it easy.

137
00:07:44,460 --> 00:07:48,430
We'll say $25 an hour and the price is one hundred.

138
00:07:48,450 --> 00:07:55,840
So we should assert that the result we get is equal to 4.

139
00:07:56,200 --> 00:07:56,900
OK.

140
00:07:57,250 --> 00:08:00,170
So right because 25 and 200 is for maybe using it.

141
00:08:00,190 --> 00:08:04,680
But Mark we did the ceiling thing where it goes up one well it only goes up one if there's a decimal.

142
00:08:04,680 --> 00:08:06,030
This is this is zero right.

143
00:08:06,040 --> 00:08:11,020
So 25 to 100 is for without any remainder so this should be for for sure.

144
00:08:11,300 --> 00:08:12,190
Let's the one with numbers.

145
00:08:12,190 --> 00:08:16,620
Now what we can do is we can actually run some math here so we can actually run this one right here.

146
00:08:16,630 --> 00:08:25,420
So let's copy this Kamensky and I'll delete it here in a second so we can run another assertion accede

147
00:08:25,760 --> 00:08:30,680
to assert let's say wage that get ours for wage.

148
00:08:30,690 --> 00:08:36,300
And so let's say the wage is 15 50 and the price is two hundred and fifty.

149
00:08:36,420 --> 00:08:40,790
Fifty three by command space again remember sixteen point sixteen.

150
00:08:40,790 --> 00:08:43,580
So using the ceiling function this should be 17.

151
00:08:43,590 --> 00:08:45,520
That's the value we're looking for in our function.

152
00:08:45,800 --> 00:08:49,330
If it comes out true and this works it means that we rewrote the correct code.

153
00:08:49,530 --> 00:08:53,920
So this should be equal to 17 because of the ceiling function which makes it go up by 1.

154
00:08:54,180 --> 00:08:58,320
So this should be equal to 17.

155
00:08:58,320 --> 00:08:59,140
All right.

156
00:08:59,460 --> 00:09:02,240
So what we just done here is we've just written a few tests.

157
00:09:02,430 --> 00:09:05,710
We've met we've passed the numbers here so this is how unit testing works.

158
00:09:05,730 --> 00:09:09,840
You you you call a function and you pass data and you get data back.

159
00:09:09,840 --> 00:09:10,800
That's good code.

160
00:09:10,800 --> 00:09:13,500
Good code is when you pass and parameters and get things back.

161
00:09:13,500 --> 00:09:18,000
Bad code is when you have a bunch of functions that depend on other functions that's called function

162
00:09:18,270 --> 00:09:20,220
dependency and it's very very bad.

163
00:09:20,280 --> 00:09:22,540
Functions that depend on other functions is bad.

164
00:09:22,590 --> 00:09:24,400
Let me say this again this is a protip.

165
00:09:24,530 --> 00:09:25,380
OK.

166
00:09:25,440 --> 00:09:32,280
When building your business logic functions that depend on other functions is very very bad.

167
00:09:32,580 --> 00:09:34,030
You want the modularized.

168
00:09:34,040 --> 00:09:35,870
OK you don't want them to rely on anything.

169
00:09:35,880 --> 00:09:40,410
So you passed data in and they spit data out and that is that's perfect.

170
00:09:40,410 --> 00:09:46,020
It's called functional programming and that's the way you want to build your applications and so we

171
00:09:46,020 --> 00:09:46,920
are testing that.

172
00:09:46,920 --> 00:09:52,800
If we pass in a 25 and a 100 that we get a 4 it's going to assert that otherwise it's going to fail.

173
00:09:52,890 --> 00:09:58,050
And then in the second case we're asserting that this decimal value this way it's 15 to 50 and the price

174
00:09:58,050 --> 00:10:00,800
is equal to 17 that it rounds up.

175
00:10:01,130 --> 00:10:04,270
OK and let's make sure.

176
00:10:04,440 --> 00:10:06,670
So point 16.

177
00:10:06,720 --> 00:10:11,170
You know normally if you were doing that of around a function with around down around.

178
00:10:11,190 --> 00:10:15,510
But we know that it's covering all of our bases because this is below point 5 and still rounding up

179
00:10:15,510 --> 00:10:18,180
to 17 or so we think.

180
00:10:18,270 --> 00:10:21,140
So I think these are two tests and I think there are enough.

181
00:10:21,250 --> 00:10:21,960
What I'm trying to say.

182
00:10:21,960 --> 00:10:27,120
I think we have enough tests here and I need to do to actually run your function here or your unit tests.

183
00:10:27,120 --> 00:10:28,920
Click this little icon right here.

184
00:10:29,000 --> 00:10:32,450
So click the play button on it.

185
00:10:32,480 --> 00:10:34,690
It's going to build it and then it's going to run it.

186
00:10:34,820 --> 00:10:37,830
You always always always want to run tests before you run your code.

187
00:10:37,940 --> 00:10:44,580
So in other protip always run your tests before you run your code every single time.

188
00:10:44,750 --> 00:10:48,860
Test run your tests before you run your code.

189
00:10:48,860 --> 00:10:54,840
That way you ensure that you haven't broken anything and it's testing as you can see up here at the

190
00:10:54,840 --> 00:10:58,190
top and it says tests has succeeded.

191
00:10:58,230 --> 00:10:59,400
Hooray.

192
00:10:59,430 --> 00:11:03,270
And if you're absolutely new to unit testing maybe you're thinking Mark I really don't understand the

193
00:11:03,270 --> 00:11:04,100
point of this.

194
00:11:04,140 --> 00:11:07,790
Like I really don't like my is good so why do I need to test it.

195
00:11:08,160 --> 00:11:10,130
Well here's a perfect reason why.

196
00:11:10,300 --> 00:11:19,380
OK here's the perfect reason why so let's go on to the Google and let's type in Iowa development round

197
00:11:19,560 --> 00:11:20,900
double OK.

198
00:11:22,500 --> 00:11:25,060
I'm just grabbing a random stack overflow.

199
00:11:25,300 --> 00:11:29,770
Let's let's use Swift actually 2011s still up there in the rankings.

200
00:11:29,780 --> 00:11:32,870
OK running a double double blah blah blah blah blah.

201
00:11:33,120 --> 00:11:33,670
OK.

202
00:11:33,840 --> 00:11:34,750
So interesting.

203
00:11:34,860 --> 00:11:37,140
So you can round a you can use around.

204
00:11:37,200 --> 00:11:41,820
OK that's that's an actual function you can run a swift and you can round something right.

205
00:11:41,820 --> 00:11:48,030
And so my point in showing you this that you could go on to stack overflow is because there's multiple

206
00:11:48,030 --> 00:11:53,100
ways you can do things you can round stuff you can call DOT rounded and all you can do all kinds of

207
00:11:53,100 --> 00:11:54,490
things.

208
00:11:54,600 --> 00:11:58,620
And so my point is there's multiple ways of accomplishing something so let's say you wrote this beautiful

209
00:11:58,620 --> 00:12:00,450
code and it works OK.

210
00:12:00,510 --> 00:12:05,630
And now you've just hired another developer or you're working with a buddy and he comes in and he's

211
00:12:06,210 --> 00:12:10,110
he goes to your wage function and he's like you know what does this seal thing this doesn't make sense.

212
00:12:10,110 --> 00:12:11,420
I don't think that's what we want.

213
00:12:11,670 --> 00:12:16,200
So what he does is he says I think it be better if we use the round function.

214
00:12:16,780 --> 00:12:17,490
OK.

215
00:12:17,810 --> 00:12:21,850
Like so and then we go ahead and pass in price divided by rage.

216
00:12:22,950 --> 00:12:27,260
Let's say he says this because I think this is a much better solution.

217
00:12:27,400 --> 00:12:28,390
And then he commits.

218
00:12:28,390 --> 00:12:29,460
He doesn't even tell you about it.

219
00:12:29,470 --> 00:12:30,060
Right.

220
00:12:30,400 --> 00:12:31,420
Well.

221
00:12:31,810 --> 00:12:34,260
Well let's go ahead and go back to our unit test.

222
00:12:34,300 --> 00:12:37,150
Your bro has just messed with your code and browes never do that.

223
00:12:37,150 --> 00:12:39,730
Dude if your bro is messing with your code he's probably not your bro.

224
00:12:39,760 --> 00:12:42,070
You need to find a new bro because he's not a coat bro.

225
00:12:42,370 --> 00:12:47,570
And let's go to a window shop or tests and what we want to do is run it again and see what happens.

226
00:12:52,110 --> 00:12:54,300
So it broke.

227
00:12:54,600 --> 00:12:55,530
What in the world.

228
00:12:55,530 --> 00:12:58,160
It broke what's going on here.

229
00:12:58,230 --> 00:12:59,410
This is really interesting.

230
00:12:59,460 --> 00:13:03,090
So our unit tests just saved our life so let's go take a look here.

231
00:13:03,500 --> 00:13:07,140
What I want to do is I just want to I want to print this here

232
00:13:11,200 --> 00:13:14,360
see if it will let us or if we have to put it inside a string.

233
00:13:14,920 --> 00:13:16,050
I want to print this here.

234
00:13:16,390 --> 00:13:18,000
Let's see if it will work now.

235
00:13:18,120 --> 00:13:19,440
You wanted in a string that's fine.

236
00:13:19,480 --> 00:13:20,410
No big deal.

237
00:13:20,710 --> 00:13:26,330
We'll use some string Interpol lation like so I would just pass that industry.

238
00:13:26,350 --> 00:13:29,710
So what it does I just put a print statement in there and let's just run the tests and see what happens

239
00:13:29,720 --> 00:13:31,760
so running the tests.

240
00:13:31,770 --> 00:13:34,240
Well we should see a couple of prints.

241
00:13:35,210 --> 00:13:36,330
Okay perfect.

242
00:13:36,340 --> 00:13:39,700
So a 4 and then a 16 is what we got.

243
00:13:40,000 --> 00:13:43,220
But wait a minute wait a minute.

244
00:13:44,360 --> 00:13:45,670
16 but we want to 17.

245
00:13:45,680 --> 00:13:48,140
Our logic called for 17 and we got to 16.

246
00:13:48,160 --> 00:13:57,410
Well it just so happens that the round function if it's point four 9 or lower rounded down if it's point

247
00:13:57,410 --> 00:14:01,790
five or higher it rounds up around it to 17.

248
00:14:01,790 --> 00:14:05,800
Only if it was point five or higher so our bro just broke our logic.

249
00:14:05,810 --> 00:14:09,640
And if you did not have that unit test you might never know you might have published a few versions.

250
00:14:09,650 --> 00:14:15,110
And some people are like hey I think your apps broken because I work 16 hours and it wasn't enough money

251
00:14:15,110 --> 00:14:15,970
to buy the thing you're like.

252
00:14:15,980 --> 00:14:16,490
Well why not.

253
00:14:16,490 --> 00:14:17,950
Because he needed some change.

254
00:14:17,960 --> 00:14:18,760
You never rounded up.

255
00:14:18,770 --> 00:14:24,110
And so you just created a terrible user experience because your bro came in and messed with your code.

256
00:14:24,110 --> 00:14:27,110
But if you had unit tests and if you you're running them every time.

257
00:14:27,110 --> 00:14:29,320
Like we just did you would know that it's broken.

258
00:14:29,440 --> 00:14:34,400
Teske our So what you do with the unit test is you test out the desired result which in our case was

259
00:14:34,400 --> 00:14:37,390
17 the Foresta worked but the 17 did not.

260
00:14:37,610 --> 00:14:39,740
So we knew that we knew that something was wrong right out the gate.

261
00:14:39,740 --> 00:14:42,000
So basically here's the here's the scenario.

262
00:14:42,020 --> 00:14:47,070
Let's say you made 10 changes your bromate 20 changes and you're about to go to version 2 and publishes

263
00:14:47,080 --> 00:14:47,450
the after.

264
00:14:47,450 --> 00:14:50,460
But first you're like I'm going to be a good developer and run all my tests in your run.

265
00:14:50,470 --> 00:14:51,330
And it breaks.

266
00:14:51,350 --> 00:14:56,180
And then you come to find out that your bro messed with your code and now you can make a decision you

267
00:14:56,180 --> 00:14:58,850
could fire the guy or at least yell at them.

268
00:14:59,150 --> 00:15:01,350
Don't buy him any food at least for sure.

269
00:15:01,430 --> 00:15:05,250
And then also you can go in here and you can fix the code.

270
00:15:05,270 --> 00:15:06,590
So that's the value of unit tests.

271
00:15:06,620 --> 00:15:10,430
You run the tests and make sure nothing in your code is because stuff changes especially if you have

272
00:15:10,430 --> 00:15:12,760
like five or 10 developers working on a project.

273
00:15:12,770 --> 00:15:14,510
Things can change.

274
00:15:14,600 --> 00:15:17,420
So luckily we had our test to let us know that it's broken.

275
00:15:17,420 --> 00:15:19,370
You never ever ship with any red Xs.

276
00:15:19,370 --> 00:15:20,060
OK.

277
00:15:20,090 --> 00:15:28,670
So protip never ship code with the red Xs K or never ship code that with failing unit tests because

278
00:15:29,390 --> 00:15:30,530
you know something is wrong.

279
00:15:30,710 --> 00:15:37,080
So now we can go back to our wage and we can put it back the way that it was supposed to be OK.

280
00:15:37,220 --> 00:15:39,110
That's the value of unit tests.

281
00:15:39,200 --> 00:15:40,820
Very very powerful.

282
00:15:40,860 --> 00:15:44,560
So we know our codes are working and we know our test is working.

283
00:15:44,570 --> 00:15:47,720
We know this function is safe to call from anywhere and it'll give us exactly what we want.

284
00:15:47,720 --> 00:15:50,810
So let's go then call this video done that was Unit testing.

285
00:15:50,810 --> 00:15:52,030
Very important stuff.

286
00:15:52,070 --> 00:15:53,590
We just scratched the surface of it.

287
00:15:53,600 --> 00:15:57,860
But you now know enough to start testing other type of model code.

288
00:15:57,860 --> 00:15:59,750
You can't really test controllers with unit tests.

289
00:15:59,750 --> 00:16:00,840
Very very difficult.

290
00:16:00,950 --> 00:16:01,330
OK.

291
00:16:01,340 --> 00:16:05,330
And you don't want to test views but whenever there's pure logic that doesn't require any type of use

292
00:16:05,330 --> 00:16:10,670
like this here math things like that strings anything that you want to do in the business layer and

293
00:16:10,670 --> 00:16:16,220
the business logic write unit tests for everything in the smallest of the test the smaller the the tests

294
00:16:16,220 --> 00:16:19,640
the better the more decoupled your functions are the better.

295
00:16:19,640 --> 00:16:22,340
You don't want function chaining or functions depending on other functions.

296
00:16:22,340 --> 00:16:24,100
So really important stuff.

297
00:16:24,110 --> 00:16:25,900
Watch this video again if you forget any of this stuff.

298
00:16:25,910 --> 00:16:27,040
But that's it for now.

299
00:16:27,050 --> 00:16:28,330
Marc price of slopes.

300
00:16:28,330 --> 00:16:30,340
Come let's go on and forward and finish this at.
