1 00:00:01,070 --> 00:00:05,430 In this course we'll see many examples of how to write unit tests. 2 00:00:05,430 --> 00:00:08,590 First let's take a look at the code we'll be testing. 3 00:00:08,590 --> 00:00:10,270 You may already be familiar with this code. 4 00:00:10,270 --> 00:00:15,110 It comes from the treehouse defense game that you might have seen in other courses. 5 00:00:15,110 --> 00:00:19,600 Let's quickly review some of the classes in the treehouse defense game. 6 00:00:19,600 --> 00:00:23,190 To start, we'll only be concerned with just a few classes. 7 00:00:23,190 --> 00:00:26,630 First we have the point class which represents a single point 8 00:00:26,630 --> 00:00:28,200 on a two dimensional grid. 9 00:00:28,200 --> 00:00:30,290 Here we have the values for x and y, 10 00:00:30,290 --> 00:00:36,401 a constructor that initializes those values and a method named DistanceTo. 11 00:00:36,401 --> 00:00:40,050 DistanceTo simply returns the distance to another point. 12 00:00:41,210 --> 00:00:45,790 The map class represents a space where objects in the game can be. 13 00:00:45,790 --> 00:00:47,890 It has a width and a height. 14 00:00:47,890 --> 00:00:50,558 The width and height must be greater than 1. 15 00:00:50,558 --> 00:00:53,860 There's an OnMap method that determines if a point is on the map. 16 00:00:55,400 --> 00:00:58,530 The map location class represents a point on the map and 17 00:00:58,530 --> 00:01:02,320 is more specific to the treehouse defense game than a normal point. 18 00:01:02,320 --> 00:01:05,320 The constructor throws an exception if someone tries to 19 00:01:05,320 --> 00:01:08,180 create a map location that isn't on the map. 20 00:01:08,180 --> 00:01:12,020 It has a method named InRangeOf which determines if the map location 21 00:01:12,020 --> 00:01:14,970 is within a given distance of another map location. 22 00:01:14,970 --> 00:01:20,462 Finally there's a file named exception.cs, which contains our custom exception types. 23 00:01:20,462 --> 00:01:24,840 So far it only contains the out of bounds exception that is thrown by the map 24 00:01:24,840 --> 00:01:26,340 location constructor. 25 00:01:26,340 --> 00:01:30,370 For right now this is enough code to get started writing unit tests. 26 00:01:30,370 --> 00:01:33,610 We'll build up the treehouse defense game a bit more as we go along.