示例#1
0
        public void NumberSpiralsOutward(int value)
        {
            var spiral = new SpiralTest(value);

            spiral.CalculateSpiralDimensions();
            spiral.DetermineNumberLocations();

            // Confirm pattern through first group of values.  Assume patterns holds afterwards.
            int originX = (spiral.Columns - 1) / 2;
            int originY = (spiral.Rows - 1) / 2;

            Assert.AreEqual(0, spiral._spiralValue[originX, originY]);
            Assert.AreEqual(1, spiral._spiralValue[originX + 1, originY]);
            Assert.AreEqual(2, spiral._spiralValue[originX + 1, originY + 1]);
            Assert.AreEqual(3, spiral._spiralValue[originX, originY + 1]);
            Assert.AreEqual(4, spiral._spiralValue[originX - 1, originY + 1]);
            Assert.AreEqual(5, spiral._spiralValue[originX - 1, originY]);
            Assert.AreEqual(6, spiral._spiralValue[originX - 1, originY - 1]);
            Assert.AreEqual(7, spiral._spiralValue[originX, originY - 1]);
            Assert.AreEqual(8, spiral._spiralValue[originX + 1, originY - 1]);
            Assert.AreEqual(9, spiral._spiralValue[originX + 2, originY - 1]);
            Assert.AreEqual(10, spiral._spiralValue[originX + 2, originY]);
            Assert.AreEqual(11, spiral._spiralValue[originX + 2, originY + 1]);
            Assert.AreEqual(12, spiral._spiralValue[originX + 2, originY + 2]);
            Assert.AreEqual(13, spiral._spiralValue[originX + 1, originY + 2]);
            Assert.AreEqual(14, spiral._spiralValue[originX, originY + 2]);
            Assert.AreEqual(15, spiral._spiralValue[originX - 1, originY + 2]);
            Assert.AreEqual(16, spiral._spiralValue[originX - 2, originY + 2]);
            Assert.AreEqual(17, spiral._spiralValue[originX - 2, originY + 1]);
            Assert.AreEqual(18, spiral._spiralValue[originX - 2, originY]);
            Assert.AreEqual(19, spiral._spiralValue[originX - 2, originY - 1]);
            Assert.AreEqual(20, spiral._spiralValue[originX - 2, originY - 2]);
        }
示例#2
0
        public void RowColumnCountsAsExpected()
        {
            var spiral = new SpiralTest(24);

            spiral.CalculateSpiralDimensions();
            Assert.AreEqual(5, spiral.Rows);
            Assert.AreEqual(5, spiral.Columns);

            spiral = new SpiralTest(40);
            spiral.CalculateSpiralDimensions();
            Assert.AreEqual(6, spiral.Rows);
            Assert.AreEqual(7, spiral.Columns);

            spiral = new SpiralTest(0);
            spiral.CalculateSpiralDimensions();
            Assert.AreEqual(1, spiral.Rows);
            Assert.AreEqual(1, spiral.Columns);

            spiral = new SpiralTest(1);
            spiral.CalculateSpiralDimensions();
            Assert.AreEqual(1, spiral.Rows);
            Assert.AreEqual(2, spiral.Columns);

            spiral = new SpiralTest(100);
            spiral.CalculateSpiralDimensions();
            Assert.AreEqual(10, spiral.Rows);
            Assert.AreEqual(11, spiral.Columns);
        }
示例#3
0
        public void SpiralWroteAllNumbers(int value)
        {
            var spiral = new SpiralTest(value);

            spiral.CalculateAndPrintSpiral();

            // Check that there were enough write commands to write all numbers, including zero.
            Assert.IsTrue(spiral._writeCount == value + 1);
        }
示例#4
0
        public void AbortInvalidValues(int value)
        {
            var spiral = new SpiralTest(value);

            spiral.CalculateSpiralDimensions();
        }