Commit 25c5796

mo_khan <mo@mokhan.ca>
2009-05-23 17:24:18
made coordinate implement icomparable
1 parent 19d8a42
Changed files (3)
product/project/Coordinate.cs
@@ -3,7 +3,7 @@ using System.Globalization;
 
 namespace mars.rover
 {
-    public class Coordinate : IEquatable<Coordinate>
+    public class Coordinate : IEquatable<Coordinate>, IComparable<Coordinate>
     {
         uint coordinate;
 
@@ -47,6 +47,11 @@ namespace mars.rover
             return coordinate.GetHashCode();
         }
 
+        public int CompareTo(Coordinate other)
+        {
+            return coordinate.CompareTo(other.coordinate);
+        }
+
         public override string ToString()
         {
             return coordinate.ToString(CultureInfo.InvariantCulture);
product/project.specifications/CoordinateSpecs.cs
@@ -0,0 +1,20 @@
+using developwithpassion.bdd.contexts;
+using developwithpassion.bdd.mbunit;
+using developwithpassion.bdd.mbunit.standard.observations;
+using mars.rover;
+
+namespace specifications
+{
+    public class CoordinateSpecs
+    {
+    }
+
+    public class when_a_coordinate_is_compared_to_another_coordinate : observations_for_a_static_sut
+    {
+        it should_tell_which_is_greater = () => new Coordinate(2).CompareTo(1).should_be_greater_than(0);
+        it should_tell_which_is_lower = () => new Coordinate(1).CompareTo(2).should_be_less_than(0);
+        it should_tell_when_they_are_equal = () => new Coordinate(1).CompareTo(1).should_be_equal_to(0);
+
+        static int 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="CoordinateSpecs.cs" />
     <Compile Include="PlateauSpecs.cs" />
     <Compile Include="Class1.cs" />
     <Compile Include="NASAPresenterSpecs.cs" />