Esempio n. 1
0
        public void addRandomValueTest()
        {
            GridBlock g1 = new GridBlock(3);

            // Test: initial counters
            Assert.AreEqual(g1.NumberOfElements, 9);
            Assert.AreEqual(g1.countAssignedPositions(), 0);
            Assert.AreEqual(g1.countUnassignedPositions(), 9);

            // Test: 1 add
            g1.addRandomValue();

            Assert.AreEqual(g1.NumberOfElements, 9);
            Assert.AreEqual(g1.countAssignedPositions(), 1);
            Assert.AreEqual(g1.countUnassignedPositions(), 8);

            // Test: maximum adds
            g1.addRandomValue();
            g1.addRandomValue();
            g1.addRandomValue();
            g1.addRandomValue();
            g1.addRandomValue();
            g1.addRandomValue();
            g1.addRandomValue();
            g1.addRandomValue();
            g1.addRandomValue();
            g1.addRandomValue();
            g1.addRandomValue();

            Assert.AreEqual(g1.NumberOfElements, 9);
            Assert.AreEqual(g1.countAssignedPositions(), 9);
            Assert.AreEqual(g1.countUnassignedPositions(), 0);
        }
Esempio n. 2
0
        public void containsValueTest()
        {
            GridBlock g1 = new GridBlock(3);
            g1.setValueAtPosition(0, 1);
            g1.setValueAtPosition(1, 2);

            Assert.IsTrue(g1.containsValue(1));
            Assert.IsTrue(g1.containsValue(2));
            Assert.IsFalse(g1.containsValue(3));
        }
Esempio n. 3
0
        public void countUnassignedPositionsTest()
        {
            GridBlock g1 = new GridBlock(3);

            Assert.AreEqual(g1.countUnassignedPositions(), 9);

            g1.setValueAtPosition(0, 1);
            g1.setValueAtPosition(1, 2);

            Assert.AreEqual(g1.countUnassignedPositions(), 7);
        }
Esempio n. 4
0
        public void fillGridBlockEntirelyTest()
        {
            // test: initial GridBlock
            GridBlock g1 = new GridBlock(3);
            Assert.AreEqual(g1.countAssignedPositions(), 0);
            Assert.AreEqual(g1.countUnassignedPositions(), 9);
            g1.fillGridBlockEntirely();
            Assert.AreEqual(g1.countAssignedPositions(), 9);
            Assert.AreEqual(g1.countUnassignedPositions(), 0);

            // test: GridBlock with some assigned values
            GridBlock g2 = new GridBlock(3);
            g2.setValueAtPosition(0, 5);
            g2.addRandomValue();
            Assert.AreEqual(g2.countAssignedPositions(), 2);
            Assert.AreEqual(g2.countUnassignedPositions(), 7);
            g2.fillGridBlockEntirely();
            Assert.AreEqual(g2.countAssignedPositions(), 9);
            Assert.AreEqual(g2.countUnassignedPositions(), 0);
        }
Esempio n. 5
0
        public void setValueAtPositionTest()
        {
            GridBlock g1 = new GridBlock(3);
            g1.setValueAtPosition(0, 1);
            g1.setValueAtPosition(1, 2);
            g1.setValueAtPosition(2, 3);

            Assert.AreEqual(g1.getValueAtPosition(0), 1);
            Assert.AreEqual(g1.getValueAtPosition(1), 2);
            Assert.AreEqual(g1.getValueAtPosition(2), 3);

            // test: exceptions for wrong indices and values
            try
            {
                g1.setValueAtPosition(-1, 5);
                Assert.Fail("Setting a value at index -1 should have thrown an exception!");
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            try
            {
                g1.setValueAtPosition(9, 5);
                Assert.Fail("Setting a value at index 9 should have thrown an exception!");
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            try
            {
                g1.setValueAtPosition(3, 0);
                Assert.Fail("Setting value 0 should have thrown an exception!");
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            try
            {
                g1.setValueAtPosition(3, 10);
                Assert.Fail("Setting value 10 should have thrown an exception!");
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            try
            {
                g1.setValueAtPosition(0, 3);
                Assert.Fail("Setting value 3 (already assigned) should have thrown an exception!");
            }
            catch (ArgumentException)
            {
            }
        }
Esempio n. 6
0
        public void GridBlockConstructorTest()
        {
            GridBlock gb1 = new GridBlock(1);
            GridBlock gb2 = new GridBlock(2);
            GridBlock gb3 = new GridBlock(3);
            GridBlock gb4 = new GridBlock(4);

            // Test: correct attributes
            Assert.AreEqual(gb1.Dimension, 1);
            Assert.AreEqual(gb1.NumberOfElements, 1);

            Assert.AreEqual(gb2.Dimension, 2);
            Assert.AreEqual(gb2.NumberOfElements, 4);

            Assert.AreEqual(gb3.Dimension, 3);
            Assert.AreEqual(gb3.NumberOfElements, 9);

            Assert.AreEqual(gb4.Dimension, 4);
            Assert.AreEqual(gb4.NumberOfElements, 16);

            // Test: expected exceptions for wrong arguments
            try
            {
                GridBlock g5 = new GridBlock(0);
                Assert.Fail("GridBlock with size 0 did not throw an exception!");
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            try
            {
                GridBlock g5 = new GridBlock(-1);
                Assert.Fail("GridBlock with size -1 did not throw an exception!");
            }
            catch (ArgumentOutOfRangeException)
            {
            }
        }
Esempio n. 7
0
        public void getValueAtPositionTest()
        {
            GridBlock g1 = new GridBlock(3);
            g1.setValueAtPosition(0, 1);
            g1.setValueAtPosition(1, 2);
            g1.setValueAtPosition(2, 3);

            Assert.AreEqual(g1.getValueAtPosition(0), 1);
            Assert.AreEqual(g1.getValueAtPosition(1), 2);
            Assert.AreEqual(g1.getValueAtPosition(2), 3);
            Assert.AreEqual(g1.getValueAtPosition(3), 0);

            // test: expections for wrong indices
            try
            {
                g1.getValueAtPosition(-1);
                Assert.Fail("Getting a value at index -1 should have thrown an exception!");
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            try
            {
                g1.getValueAtPosition(9);
                Assert.Fail("Getting a value at index 9 should have thrown an exception!");
            }
            catch (ArgumentOutOfRangeException)
            {
            }
        }
Esempio n. 8
0
        public void getRowAtIndexTest()
        {
            GridBlock g1 = new GridBlock(3);

            for (int i = 1; i <= g1.NumberOfElements; i++)
            {
                g1.setValueAtPosition(i - 1, i);
            }

            // Test: expected rows vs. actual rows
            List<int> expectedLine0 = new List<int>(3);
            List<int> expectedLine1 = new List<int>(3);
            List<int> expectedLine2 = new List<int>(3);

            expectedLine0.Add(1);
            expectedLine0.Add(2);
            expectedLine0.Add(3);

            expectedLine1.Add(4);
            expectedLine1.Add(5);
            expectedLine1.Add(6);

            expectedLine2.Add(7);
            expectedLine2.Add(8);
            expectedLine2.Add(9);

            List<int> actualLine0 = g1.getRowAtIndex(0);
            List<int> actualLine1 = g1.getRowAtIndex(1);
            List<int> actualLine2 = g1.getRowAtIndex(2);

            Assert.IsTrue(expectedLine0.SequenceEqual(actualLine0));
            Assert.IsTrue(expectedLine1.SequenceEqual(actualLine1));
            Assert.IsTrue(expectedLine2.SequenceEqual(actualLine2));

            // Test: exceptions for non-existent rows
            try
            {
                g1.getRowAtIndex(-1);
                Assert.Fail("Row access at index -1 should have thrown an exception!");
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            try
            {
                g1.getRowAtIndex(-2);
                Assert.Fail("Row access at index -2 should have thrown an exception!");
            }
            catch (ArgumentOutOfRangeException)
            {
            }
        }