Commit 19d8a42

mo_khan <mo@mokhan.ca>
2009-05-23 17:14:02
created plateau for bounds checking
1 parent 3c08872
product/project/Coordinate.cs
@@ -5,9 +5,9 @@ namespace mars.rover
 {
     public class Coordinate : IEquatable<Coordinate>
     {
-        int coordinate;
+        uint coordinate;
 
-        public Coordinate(int coordinate)
+        public Coordinate(uint coordinate)
         {
             this.coordinate = coordinate;
         }
@@ -22,7 +22,7 @@ namespace mars.rover
             coordinate--;
         }
 
-        static public implicit operator Coordinate(int coordinate)
+        static public implicit operator Coordinate(uint coordinate)
         {
             return new Coordinate(coordinate);
         }
@@ -44,7 +44,7 @@ namespace mars.rover
 
         public override int GetHashCode()
         {
-            return coordinate;
+            return coordinate.GetHashCode();
         }
 
         public override string ToString()
product/project/NASA.cs
@@ -6,7 +6,7 @@ namespace mars.rover
         {
         }
 
-        public virtual Rover deploy_rover_to(int x_coordinate, int y_coordinate, Heading heading)
+        public virtual Rover deploy_rover_to(uint x_coordinate, uint y_coordinate, Heading heading)
         {
             return new Rover(x_coordinate, y_coordinate, heading);
         }
product/project/Plateau.cs
@@ -0,0 +1,19 @@
+namespace mars.rover
+{
+    public class Plateau
+    {
+        readonly uint top_x_coordinate;
+        readonly uint top_y_coordinate;
+
+        public Plateau(uint top_x_coordinate, uint top_y_coordinate)
+        {
+            this.top_x_coordinate = top_x_coordinate;
+            this.top_y_coordinate = top_y_coordinate;
+        }
+
+        public virtual bool within_boundary(uint x, uint y)
+        {
+            return y <= top_y_coordinate && x <= top_x_coordinate;
+        }
+    }
+}
\ No newline at end of file
product/project/project.csproj
@@ -54,6 +54,7 @@
     <Compile Include="NASA.cs" />
     <Compile Include="North.cs" />
     <Compile Include="ParameterizedCommand.cs" />
+    <Compile Include="Plateau.cs" />
     <Compile Include="Position.cs" />
     <Compile Include="Presenter.cs" />
     <Compile Include="NASAPresenter.cs" />
product/project.specifications/PlateauSpecs.cs
@@ -0,0 +1,53 @@
+using developwithpassion.bdd.contexts;
+using developwithpassion.bdd.mbunit;
+using developwithpassion.bdd.mbunit.standard.observations;
+using mars.rover;
+
+namespace specifications
+{
+    public class PlateauSpecs
+    {
+    }
+
+    public class when_within_the_boundary : observations_for_a_sut_without_a_contract<Plateau>
+    {
+        it should_return_true = () => result.should_be_true();
+
+        because b = () => { result = sut.within_boundary(3, 3); };
+
+        public override Plateau create_sut()
+        {
+            return new Plateau(3, 3);
+        }
+
+        static bool result;
+    }
+
+    public class when_outside_the_y_boundary : observations_for_a_sut_without_a_contract<Plateau>
+    {
+        it should_return_false = () => result.should_be_false();
+
+        because b = () => { result = sut.within_boundary(3, 4); };
+
+        public override Plateau create_sut()
+        {
+            return new Plateau(3, 3);
+        }
+
+        static bool result;
+    }
+
+    public class when_outside_the_x_boundary : observations_for_a_sut_without_a_contract<Plateau>
+    {
+        it should_return_false = () => result.should_be_false();
+
+        because b = () => { result = sut.within_boundary(3, 4); };
+
+        public override Plateau create_sut()
+        {
+            return new Plateau(3, 3);
+        }
+
+        static bool result;
+    }
+}
\ No newline at end of file
product/project.specifications/project.specifications.csproj
@@ -65,6 +65,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="PlateauSpecs.cs" />
     <Compile Include="Class1.cs" />
     <Compile Include="NASAPresenterSpecs.cs" />
     <Compile Include="NASASpecs.cs" />