Exemplo n.º 1
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)
            {
            }
        }
Exemplo n.º 2
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)
            {
            }
        }