示例#1
0
        public void TestShouldTurnAndMoveInTheRightDirection()
        {
            var     mf      = new MoveForwardCommand();
            var     tc      = new TurnClockwiseCommand();
            Tractor tractor = new Tractor();

            tc.Execute(tractor);
            mf.Execute(tractor);
            Assert.AreEqual(1, tractor.GetPositionX());
            Assert.AreEqual(0, tractor.GetPositionY());

            tc.Execute(tractor);
            mf.Execute(tractor);
            Assert.AreEqual(1, tractor.GetPositionX());
            Assert.AreEqual(-1, tractor.GetPositionY());

            tc.Execute(tractor);
            mf.Execute(tractor);
            Assert.AreEqual(0, tractor.GetPositionX());
            Assert.AreEqual(-1, tractor.GetPositionY());

            tc.Execute(tractor);
            mf.Execute(tractor);
            Assert.AreEqual(0, tractor.GetPositionX());
            Assert.AreEqual(0, tractor.GetPositionY());
        }
示例#2
0
        public void TestShouldTurnAndMoveInTheRightDirection()
        {
            Tractor tractor = new Tractor(new Field()
            {
                Height = 5, Width = 5
            });
            var moveCommand = new MoveForwardCommand(tractor);
            var turnCommand = new TurnClockwiseCommand(tractor);

            turnCommand.Execute();
            moveCommand.Execute();
            Assert.AreEqual(1, tractor.UnitPosition.X);
            Assert.AreEqual(0, tractor.UnitPosition.Y);

            turnCommand.Execute();
            moveCommand.Execute();
            Assert.AreEqual(1, tractor.UnitPosition.X);
            Assert.AreEqual(-1, tractor.UnitPosition.Y);

            turnCommand.Execute();
            moveCommand.Execute();
            Assert.AreEqual(0, tractor.UnitPosition.X);
            Assert.AreEqual(-1, tractor.UnitPosition.Y);

            turnCommand.Execute();
            moveCommand.Execute();
            Assert.AreEqual(0, tractor.UnitPosition.X);
            Assert.AreEqual(0, tractor.UnitPosition.Y);
        }
示例#3
0
 public void TestInitialize()
 {
     _field   = new Field(5, 5);
     _tractor = new Tractor(_field);
     _stone   = new Stone(_field);
     _wind    = new Wind(_field);
     _units   = new List <Unit> {
         _tractor, _stone, _wind
     };
     _moveCommand = new MoveForwardCommand(_units);
     _turnCommand = new TurnClockwiseCommand(_units);
 }
示例#4
0
        public void TestShouldTurn()
        {
            var  tc   = new TurnClockwiseCommand();
            Wind wind = new Wind();

            tc.Execute(wind);
            Assert.AreEqual(Orientation.East, wind.Orientation);

            tc.Execute(wind);
            Assert.AreEqual(Orientation.South, wind.Orientation);

            tc.Execute(wind);
            Assert.AreEqual(Orientation.West, wind.Orientation);

            tc.Execute(wind);
            Assert.AreEqual(Orientation.North, wind.Orientation);
        }
示例#5
0
        public void TestShouldTurn()
        {
            var     tc      = new TurnClockwiseCommand();
            Tractor tractor = new Tractor();

            tc.Execute(tractor);
            Assert.AreEqual(Orientation.East, tractor.Orientation);

            tc.Execute(tractor);
            Assert.AreEqual(Orientation.South, tractor.Orientation);

            tc.Execute(tractor);
            Assert.AreEqual(Orientation.West, tractor.Orientation);

            tc.Execute(tractor);
            Assert.AreEqual(Orientation.North, tractor.Orientation);
        }
示例#6
0
        public void TestShouldTurn()
        {
            Tractor tractor = new Tractor(new Field()
            {
                Height = 5, Width = 5
            });
            var turnCommand = new TurnClockwiseCommand(tractor);

            turnCommand.Execute();
            Assert.AreEqual(Orientation.East, tractor.UnitOrientation);

            turnCommand.Execute();
            Assert.AreEqual(Orientation.South, tractor.UnitOrientation);

            turnCommand.Execute();
            Assert.AreEqual(Orientation.West, tractor.UnitOrientation);

            turnCommand.Execute();
            Assert.AreEqual(Orientation.North, tractor.UnitOrientation);
        }
示例#7
0
        public void TestShouldCorrectCommandExec()
        {
            var     mf      = new MoveForwardCommand();
            var     tc      = new TurnClockwiseCommand();
            Tractor tractor = new Tractor();
            Stone   stone   = new Stone(new int[] { 2, 4 });
            Wind    wind    = new Wind();

            mf.Execute(tractor);
            mf.Execute(wind);
            mf.Execute(stone);
            tc.Execute(tractor);
            tc.Execute(wind);
            tc.Execute(stone);

            Assert.AreEqual(0, tractor.GetPositionX());
            Assert.AreEqual(1, tractor.GetPositionY());
            Assert.AreEqual(Orientation.East, tractor.Orientation);

            Assert.AreEqual(Orientation.East, wind.Orientation);

            Assert.AreEqual(2, stone.GetPositionX());
            Assert.AreEqual(4, stone.GetPositionY());
        }