1 00:00:00,790 --> 00:00:03,190 The following content is provided under a Creative 2 00:00:03,190 --> 00:00:04,730 Commons license. 3 00:00:04,730 --> 00:00:07,030 Your support will help MIT OpenCourseWare 4 00:00:07,030 --> 00:00:11,390 continue to offer high quality educational resources for free. 5 00:00:11,390 --> 00:00:13,990 To make a donation, or view additional materials 6 00:00:13,990 --> 00:00:17,860 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:17,860 --> 00:00:18,830 at ocw.mit.edu. 8 00:00:23,807 --> 00:00:25,390 ANA BELL: Let's look at this exercise. 9 00:00:32,460 --> 00:00:36,660 So we have this function is even, same one as before, 10 00:00:36,660 --> 00:00:40,270 except now I'm giving you this implementation. 11 00:00:40,270 --> 00:00:48,120 If n is positive and n divided by 2's remainder is 0, 12 00:00:48,120 --> 00:00:48,990 return true. 13 00:00:48,990 --> 00:00:51,600 So if n is even and positive return true. 14 00:00:51,600 --> 00:00:56,370 The next one, if n is negative and divisible by 2 return true. 15 00:00:56,370 --> 00:00:57,940 OK, so far. 16 00:00:57,940 --> 00:01:01,440 And otherwise return false. 17 00:01:01,440 --> 00:01:04,620 Question being, with that implementation 18 00:01:04,620 --> 00:01:11,070 is this test set n is 4, n is minus 4 path complete? 19 00:01:11,070 --> 00:01:13,920 And the answer is, yes. 20 00:01:13,920 --> 00:01:19,620 Because 4 is a positive number and divisible by 2. 21 00:01:23,620 --> 00:01:27,600 Minus 4 is a negative number and divisible by 2. 22 00:01:27,600 --> 00:01:29,380 And 5 would hit upon the else. 23 00:01:33,510 --> 00:01:36,800 So the answer is actually yes for that first question. 24 00:01:36,800 --> 00:01:37,300 Perfect. 25 00:01:40,360 --> 00:01:43,090 Second question, with that implementation, 26 00:01:43,090 --> 00:01:48,550 which value for n is incorrectly labeled by that program? 27 00:01:48,550 --> 00:01:51,190 Well, n is very large still works, and is very small 28 00:01:51,190 --> 00:01:51,790 still works. 29 00:01:51,790 --> 00:01:54,310 And remember, I said you have to test boundary conditions. 30 00:01:54,310 --> 00:01:56,393 In this case, boundary conditions for this program 31 00:01:56,393 --> 00:01:58,570 being when n is equal to zero. 32 00:01:58,570 --> 00:02:01,450 So I think the orange is n is equal to 0. 33 00:02:01,450 --> 00:02:02,890 Perfect.