WEBVTT

00:00:00.790 --> 00:00:03.190
The following content is
provided under a Creative

00:00:03.190 --> 00:00:04.730
Commons license.

00:00:04.730 --> 00:00:07.030
Your support will help
MIT OpenCourseWare

00:00:07.030 --> 00:00:11.390
continue to offer high quality
educational resources for free.

00:00:11.390 --> 00:00:13.990
To make a donation, or
view additional materials

00:00:13.990 --> 00:00:17.860
from hundreds of MIT courses,
visit MIT OpenCourseWare

00:00:17.860 --> 00:00:18.830
at ocw.mit.edu.

00:00:23.807 --> 00:00:25.390
ANA BELL: Let's look
at this exercise.

00:00:32.460 --> 00:00:36.660
So we have this function is
even, same one as before,

00:00:36.660 --> 00:00:40.270
except now I'm giving
you this implementation.

00:00:40.270 --> 00:00:48.120
If n is positive and n
divided by 2's remainder is 0,

00:00:48.120 --> 00:00:48.990
return true.

00:00:48.990 --> 00:00:51.600
So if n is even and
positive return true.

00:00:51.600 --> 00:00:56.370
The next one, if n is negative
and divisible by 2 return true.

00:00:56.370 --> 00:00:57.940
OK, so far.

00:00:57.940 --> 00:01:01.440
And otherwise return false.

00:01:01.440 --> 00:01:04.620
Question being, with
that implementation

00:01:04.620 --> 00:01:11.070
is this test set n is 4, n
is minus 4 path complete?

00:01:11.070 --> 00:01:13.920
And the answer is, yes.

00:01:13.920 --> 00:01:19.620
Because 4 is a positive
number and divisible by 2.

00:01:23.620 --> 00:01:27.600
Minus 4 is a negative
number and divisible by 2.

00:01:27.600 --> 00:01:29.380
And 5 would hit upon the else.

00:01:33.510 --> 00:01:36.800
So the answer is actually
yes for that first question.

00:01:36.800 --> 00:01:37.300
Perfect.

00:01:40.360 --> 00:01:43.090
Second question, with
that implementation,

00:01:43.090 --> 00:01:48.550
which value for n is incorrectly
labeled by that program?

00:01:48.550 --> 00:01:51.190
Well, n is very large still
works, and is very small

00:01:51.190 --> 00:01:51.790
still works.

00:01:51.790 --> 00:01:54.310
And remember, I said you have
to test boundary conditions.

00:01:54.310 --> 00:01:56.393
In this case, boundary
conditions for this program

00:01:56.393 --> 00:01:58.570
being when n is equal to zero.

00:01:58.570 --> 00:02:01.450
So I think the orange
is n is equal to 0.

00:02:01.450 --> 00:02:02.890
Perfect.