Ad
  • Custom User Avatar

    Please try the following test cases, some are copied from other suggestions and modified.

    [TestFixture]
    public class SolutionTest
    {
        [Test]
        public void TestCase()
        {
            /*arrange*/
            int[,] field = new int[10, 10]
                           { {1, 0, 0, 0, 0, 1, 1, 0, 0, 0},
                             {1, 0, 1, 0, 0, 0, 0, 0, 1, 0},
                             {1, 0, 1, 0, 1, 1, 1, 0, 1, 0},
                             {1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
                             {0, 0, 0, 0, 1, 1, 1, 0, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
                             {0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsTrue(res);
    
        }
        [Test]
        public void TestCase1()
        {
            /*arrange*/
            int[,] field = new int[10, 10]
                           { { 0, 0, 0, 1, 1, 1, 0, 0, 0, 0 },
                             { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0 },
                             { 1, 1, 1, 0, 1, 1, 0, 0, 0, 1 },
                             { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
                             { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
                             { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                             { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                             { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
                             { 1, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
                             { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsFalse(res);
        }
        [Test]
        public void TestCase2()
        {
            /*arrange*/
            int[,] field = new int[10, 10]
                           { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {0, 1, 1, 0, 1, 0, 0, 1, 1, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {1, 0, 0, 1, 1, 1, 0, 0, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
                             {1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {1, 0, 0, 0, 1, 1, 0, 0, 0, 1},
                             {0, 0, 1, 0, 0, 0, 0, 1, 0, 0} };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsFalse(res);
        }
        [Test]
        public void TestCase3()
        {
            /*arrange*/
            int[,] field = new int[10, 10]
                           { {0, 1, 1, 0, 0, 0, 0, 0, 1, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
                             {1, 0, 0, 1, 0, 1, 0, 0, 0, 0},
                             {1, 0, 0, 0, 0, 0, 0, 1, 0, 0},
                             {0, 0, 1, 1, 1, 1, 0, 1, 0, 1},
                             {0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 1, 0, 0} };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsFalse(res);
        }
        [Test]
        public void TestCase4()
        {
            /*arrange*/
            int[,] field = new int[10, 10]
                           { {0, 1, 1, 1, 0, 0, 0, 0, 1, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {0, 0, 0, 1, 0, 0, 0, 0, 0, 1},
                             {0, 0, 0, 1, 1, 0, 0, 0, 0, 1},
                             {0, 0, 0, 1, 0, 0, 0, 0, 0, 1},
                             {0, 0, 0, 0, 0, 0, 1, 0, 0, 1},
                             {0, 0, 0, 0, 0, 0, 1, 0, 0, 1},
                             {0, 1, 0, 0, 0, 0, 0, 0, 0, 1},
                             {0, 1, 0, 0, 0, 0, 0, 1, 0, 0},
                             {0, 0, 0, 0, 0, 1, 0, 0, 0, 0} };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsFalse(res);
        }
        [Test]
        public void TestCase5()
        {
            /*arrange*/
            int[,] field = new int[10, 10] { {0, 0, 0, 0, 0, 0, 1, 1, 1, 0},
                             {0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
                             {0, 0, 0, 0, 0, 1, 1, 0, 1, 0},
                             {0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
                             {0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
                             {0, 0, 0, 0, 0, 0, 1, 0, 0, 1},
                             {0, 0, 0, 0, 0, 0, 1, 0, 1, 1},
                             {0, 0, 0, 0, 0, 0, 1, 0, 1, 0},
                             {0, 0, 1, 0, 0, 0, 1, 0, 1, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 1, 0} };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsFalse(res);
        }
        [Test]
        public void TestCase6()
        {
            /*arrange*/
            int[,] field = new int[10, 10] { {0, 0, 1, 0, 0, 0, 0, 1, 0, 0},
                             {1, 0, 1, 0, 1, 1, 0, 0, 0, 1},
                             {1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {0, 0, 0, 0, 0, 1, 1, 1, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {0, 0, 1, 1, 0, 1, 0, 0, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {1, 1, 1, 0, 0, 0, 1, 0, 1, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsFalse(res);
        }
        [Test]
        public void TestCase7()
        {
            /*arrange*/
            int[,] field = new int[10, 10] { {1, 0, 0, 0, 0, 1, 1, 0, 0, 0},
                             {1, 0, 1, 0, 0, 0, 0, 0, 1, 0},
                             {1, 0, 1, 0, 1, 1, 1, 0, 1, 0},
                             {1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
                             {0, 0, 0, 0, 1, 1, 1, 0, 0, 0},
                             {0, 0, 0, 1, 0, 0, 0, 0, 1, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsFalse(res);
        }
        [Test]
        public void TestCase8()
        {
            /*arrange*/
            int[,] field = new int[10, 10] {
                             {0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
                             {0, 1, 0, 1, 0, 0, 0, 0, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                             {1, 1, 1, 0, 1, 0, 0, 0, 0, 0},
                             {0, 0, 0, 0, 0, 0, 0, 1, 1, 1},
                             {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                             {1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
                             {1, 0, 0, 0, 0, 1, 0, 0, 0, 0},
                             {1, 0, 0, 0, 0, 1, 0, 1, 1, 0},
                             {1, 0, 0, 0, 0, 0, 0, 0, 0, 0} };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsTrue(res);
        }
        [Test]
        public void TestCase9()
        {
            /*arrange*/
            int[,] field = new int[10, 10] { {1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                              {1, 0, 0, 0, 0, 1, 0, 0, 0, 0},
                              {1, 0, 0, 0, 0, 1, 0, 0, 0, 1},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                              {1, 0, 1, 1, 1, 0, 1, 1, 1, 0},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                              {0, 0, 0, 1, 1, 1, 0, 0, 1, 0},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                              {0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
                              {0, 0, 0, 0, 0, 0, 1, 1, 0, 0} };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsFalse(res);
        }
        [Test]
        public void TestCase10()
        {
            /*arrange*/
            int[,] field = new int[10, 10] { {0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
                              {0, 1, 1, 0, 0, 1, 0, 0, 0, 1},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                              {0, 0, 0, 1, 0, 1, 1, 0, 0, 0},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                              {0, 0, 1, 0, 0, 0, 0, 0, 0, 1},
                              {0, 0, 1, 0, 0, 1, 0, 0, 0, 0},
                              {0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
                              {1, 0, 0, 0, 0, 0, 1, 0, 0, 0},
                              {1, 0, 0, 1, 1, 0, 0, 0, 0, 0} };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsFalse(res);
        }
        [Test]
        public void TestCase11()
        {
            /*arrange*/
            int[,] field = new int[10, 10] { {1, 0, 0, 0, 0, 1, 0, 0, 0, 1},
                              {0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                              {0, 0, 0, 1, 0, 1, 0, 1, 0, 0},
                              {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                              {0, 0, 1, 0, 1, 0, 0, 1, 0, 0},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                              {1, 0, 1, 0, 0, 1, 0, 0, 1, 0},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                              {1, 0, 0, 1, 0, 0, 0, 0, 0, 1} };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsFalse(res);
        }
        [Test]
        public void TestCase12()
        {
            /*arrange*/
            int[,] field = new int[10, 10] { {1, 0, 1, 0, 1, 0, 1, 0, 1, 0},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                              {1, 0, 1, 0, 1, 0, 1, 0, 1, 0},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                              {0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                              {0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                              {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} };
            /*act*/
            bool res = BattleshipField.ValidateBattlefield(field);
            /*assert*/
            Assert.IsFalse(res);
        }
    }
    
  • Custom User Avatar

    battleField9 should be true.

  • Custom User Avatar

    This is completed one, enjoy;)

  • Custom User Avatar

    Please ignore this one, I have better one and cannot delete this.

  • Custom User Avatar

    Please ignore this one, I have better one and cannot delete this.

  • Custom User Avatar

    Please ignore this one, I have better one and cannot delete this.