Commit 3c08872

mo_khan <mo@mokhan.ca>
2009-05-23 16:57:31
missed files in last commit
1 parent 51a7609
product/project/Coordinate.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Globalization;
+
+namespace mars.rover
+{
+    public class Coordinate : IEquatable<Coordinate>
+    {
+        int coordinate;
+
+        public Coordinate(int coordinate)
+        {
+            this.coordinate = coordinate;
+        }
+
+        public virtual void increment()
+        {
+            coordinate++;
+        }
+
+        public virtual void decrement()
+        {
+            coordinate--;
+        }
+
+        static public implicit operator Coordinate(int coordinate)
+        {
+            return new Coordinate(coordinate);
+        }
+
+        public bool Equals(Coordinate other)
+        {
+            if (ReferenceEquals(null, other)) return false;
+            if (ReferenceEquals(this, other)) return true;
+            return other.coordinate == coordinate;
+        }
+
+        public override bool Equals(object obj)
+        {
+            if (ReferenceEquals(null, obj)) return false;
+            if (ReferenceEquals(this, obj)) return true;
+            if (obj.GetType() != typeof (Coordinate)) return false;
+            return Equals((Coordinate) obj);
+        }
+
+        public override int GetHashCode()
+        {
+            return coordinate;
+        }
+
+        public override string ToString()
+        {
+            return coordinate.ToString(CultureInfo.InvariantCulture);
+        }
+    }
+}
\ No newline at end of file
product/project/East.cs
@@ -0,0 +1,41 @@
+namespace mars.rover
+{
+    public class East : Heading
+    {
+        public Heading turn_left()
+        {
+            return new North();
+        }
+
+        public Heading turn_right()
+        {
+            return new South();
+        }
+
+        public void move_forward_from(Coordinate x, Coordinate y)
+        {
+            x.increment();
+        }
+
+        public bool Equals(Heading other)
+        {
+            if (null == other) return false;
+            return other is East;
+        }
+
+        public override string ToString()
+        {
+            return "East";
+        }
+
+        public override bool Equals(object obj)
+        {
+            return Equals(obj as Heading);
+        }
+
+        public override int GetHashCode()
+        {
+            return ToString().GetHashCode();
+        }
+    }
+}
\ No newline at end of file
product/project/Heading.cs
@@ -0,0 +1,11 @@
+using System;
+
+namespace mars.rover
+{
+    public interface Heading : IEquatable<Heading>
+    {
+        Heading turn_left();
+        Heading turn_right();
+        void move_forward_from(Coordinate x, Coordinate y);
+    }
+}
\ No newline at end of file
product/project/Headings.cs
@@ -0,0 +1,10 @@
+namespace mars.rover
+{
+    static public class Headings
+    {
+        static public Heading North = new North();
+        static public Heading East = new East();
+        static public Heading West = new West();
+        static public Heading South = new South();
+    }
+}
\ No newline at end of file
product/project/North.cs
@@ -0,0 +1,41 @@
+namespace mars.rover
+{
+    public class North : Heading
+    {
+        public Heading turn_left()
+        {
+            return new West();
+        }
+
+        public Heading turn_right()
+        {
+            return new East();
+        }
+
+        public void move_forward_from(Coordinate x, Coordinate y)
+        {
+            y.increment();
+        }
+
+        public bool Equals(Heading other)
+        {
+            if (null == other) return false;
+            return other is North;
+        }
+
+        public override bool Equals(object obj)
+        {
+            return Equals(obj as Heading);
+        }
+
+        public override int GetHashCode()
+        {
+            return ToString().GetHashCode();
+        }
+
+        public override string ToString()
+        {
+            return "North";
+        }
+    }
+}
\ No newline at end of file
product/project/Position.cs
@@ -0,0 +1,26 @@
+using System;
+
+namespace mars.rover
+{
+    public class Position
+    {
+        public Position(int x, int y, Heading heading)
+        {
+        }
+
+        public virtual void change_heading_to_left()
+        {
+            throw new NotImplementedException();
+        }
+
+        public virtual void change_heading_to_right()
+        {
+            throw new NotImplementedException();
+        }
+
+        public virtual void advance()
+        {
+            throw new NotImplementedException();
+        }
+    }
+}
\ No newline at end of file
product/project/Rover.cs
@@ -0,0 +1,31 @@
+namespace mars.rover
+{
+    public class Rover
+    {
+        public Coordinate y { get; private set; }
+        public Coordinate x { get; private set; }
+        public Heading heading { get; private set; }
+
+        public Rover(Coordinate x, Coordinate y, Heading heading)
+        {
+            this.x = x;
+            this.y = y;
+            this.heading = heading;
+        }
+
+        public virtual void turn_left()
+        {
+            heading = heading.turn_left();
+        }
+
+        public virtual void turn_right()
+        {
+            heading = heading.turn_right();
+        }
+
+        public virtual void move_forward()
+        {
+            heading.move_forward_from(x, y);
+        }
+    }
+}
\ No newline at end of file
product/project/South.cs
@@ -0,0 +1,43 @@
+using System;
+
+namespace mars.rover
+{
+    public class South : Heading
+    {
+        public Heading turn_left()
+        {
+            return new East();
+        }
+
+        public Heading turn_right()
+        {
+            return new West();
+        }
+
+        public void move_forward_from(Coordinate x, Coordinate y)
+        {
+            y.decrement();
+        }
+
+        public bool Equals(Heading other)
+        {
+            if (null == other) return false;
+            return other is South;
+        }
+
+        public override string ToString()
+        {
+            return "South";
+        }
+
+        public override bool Equals(object obj)
+        {
+            return Equals(obj as Heading);
+        }
+
+        public override int GetHashCode()
+        {
+            return ToString().GetHashCode();
+        }
+    }
+}
\ No newline at end of file
product/project/West.cs
@@ -0,0 +1,41 @@
+namespace mars.rover
+{
+    public class West : Heading
+    {
+        public Heading turn_left()
+        {
+            return new South();
+        }
+
+        public Heading turn_right()
+        {
+            return new North();
+        }
+
+        public void move_forward_from(Coordinate x, Coordinate y)
+        {
+            x.decrement();
+        }
+
+        public bool Equals(Heading other)
+        {
+            if (null == other) return false;
+            return other is West;
+        }
+
+        public override string ToString()
+        {
+            return "West";
+        }
+
+        public override bool Equals(object obj)
+        {
+            return Equals(obj as Heading);
+        }
+
+        public override int GetHashCode()
+        {
+            return ToString().GetHashCode();
+        }
+    }
+}
\ No newline at end of file
product/project.specifications/NASASpecs.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 NASASpecs
+    {
+    }
+
+    public class when_nasa_deploys_a_rover_to_a_position_on_mars : observations_for_a_sut_without_a_contract<NASA>
+    {
+        it should_return_a_new_rover = () => result.should_not_be_null();
+
+        because b = () => { result = sut.deploy_rover_to(1, 2, Headings.North); };
+
+        static Rover result;
+    }
+}
\ No newline at end of file
product/project.specifications/PositionSpecs.cs
@@ -0,0 +1,7 @@
+namespace specifications
+{
+    public class PositionSpecs
+    {
+        
+    }
+}
\ No newline at end of file
product/project.specifications/RoverSpecs.cs
@@ -0,0 +1,127 @@
+using developwithpassion.bdd.contexts;
+using developwithpassion.bdd.mbunit;
+using developwithpassion.bdd.mbunit.standard.observations;
+using mars.rover;
+
+namespace specifications
+{
+    public class RoverSpecs
+    {
+    }
+
+    public abstract class when_facing_north : observations_for_a_sut_without_a_contract<Rover>
+    {
+        public override Rover create_sut()
+        {
+            return new Rover(1, 2, Headings.North);
+        }
+    }
+
+    public abstract class when_facing_east : observations_for_a_sut_without_a_contract<Rover>
+    {
+        public override Rover create_sut()
+        {
+            return new Rover(1, 2, Headings.East);
+        }
+    }
+
+    public abstract class when_facing_west : observations_for_a_sut_without_a_contract<Rover>
+    {
+        public override Rover create_sut()
+        {
+            return new Rover(1, 2, Headings.West);
+        }
+    }
+
+    public abstract class when_facing_south : observations_for_a_sut_without_a_contract<Rover>
+    {
+        public override Rover create_sut()
+        {
+            return new Rover(1, 2, Headings.South);
+        }
+    }
+
+    public class when_a_rover_that_is_facing_north_is_told_to_turn_90_degrees_to_the_left : when_facing_north
+    {
+        it should_be_facing_west = () => sut.heading.should_be_equal_to(Headings.West);
+
+        because b = () => sut.turn_left();
+    }
+
+    public class when_a_rover_that_is_facing_north_is_told_to_turn_90_degrees_to_the_right : when_facing_north
+    {
+        it should_be_facing_east = () => sut.heading.should_be_equal_to(Headings.East);
+
+        because b = () => sut.turn_right();
+    }
+
+    public class when_a_rover_that_is_facing_east_is_told_to_turn_90_degrees_to_the_left : when_facing_east
+    {
+        it should_be_facing_north = () => sut.heading.should_be_equal_to(Headings.North);
+
+        because b = () => sut.turn_left();
+    }
+
+    public class when_a_rover_that_is_facing_east_is_told_to_turn_90_degrees_to_the_right : when_facing_east
+    {
+        it should_be_facing_south = () => sut.heading.should_be_equal_to(Headings.South);
+
+        because b = () => sut.turn_right();
+    }
+
+    public class when_a_rover_that_is_facing_south_is_told_to_turn_90_degrees_to_the_left : when_facing_south
+    {
+        it should_be_facing_east = () => sut.heading.should_be_equal_to(Headings.East);
+
+        because b = () => sut.turn_left();
+    }
+
+    public class when_a_rover_that_is_facing_south_is_told_to_turn_90_degrees_to_the_right : when_facing_south
+    {
+        it should_be_facing_west = () => sut.heading.should_be_equal_to(Headings.West);
+
+        because b = () => sut.turn_right();
+    }
+
+    public class when_a_rover_that_is_facing_west_is_told_to_turn_90_degrees_to_the_left : when_facing_west
+    {
+        it should_be_facing_south = () => sut.heading.should_be_equal_to(Headings.South);
+
+        because b = () => sut.turn_left();
+    }
+
+    public class when_a_rover_that_is_facing_west_is_told_to_turn_90_degrees_to_the_right : when_facing_west
+    {
+        it should_be_facing_north = () => sut.heading.should_be_equal_to(Headings.North);
+
+        because b = () => sut.turn_right();
+    }
+
+    public class when_facing_north_and_moving_forward_one_grid_point : when_facing_north
+    {
+        it should_increment_its_y_coordinate = () => sut.y.should_be_equal_to<Coordinate>(3);
+
+        because b = () => sut.move_forward();
+    }
+
+    public class when_facing_south_and_moving_forward_one_grid_point : when_facing_south
+    {
+        it should_decrement_its_y_coordinate = () => sut.y.should_be_equal_to<Coordinate>(1);
+
+        because b = () => sut.move_forward();
+    }
+
+    public class when_facing_west_and_moving_forward_one_grid_point : when_facing_west
+    {
+        it should_decrement_its_x_coordinate = () => sut.x.should_be_equal_to<Coordinate>(0);
+
+        because b = () => sut.move_forward();
+    }
+
+    public class when_facing_east_and_moving_forward_one_grid_point : when_facing_east
+    {
+        it should_increment_its_x_coordinate = () => sut.x.should_be_equal_to<Coordinate>(2);
+
+        because b = () => sut.move_forward();
+    }
+}
\ No newline at end of file