示例#1
0
        /// <summary>
        /// Attaches the instance to the specified buffer.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="width">The width of the buffer, in pixels.</param>
        /// <param name="height">The height of the buffer, in pixels.</param>
        /// <param name="stride">The stride of the buffer, in bytes.</param>
        public void Attach(byte[] buffer, int width, int height, int stride)
        {
            m_buf    = buffer;
            m_width  = width;
            m_height = height;
            m_stride = stride;
            if (height > m_max_height)
            {
                m_max_height = height;
                m_rows       = new int[m_max_height];
            }

            int rowIndex = 0;

            if (stride < 0)
            {
                rowIndex = m_buf.Length - (height - 1) * stride;
            }

            for (int y = 0; y < height; y++)
            {
                m_rows[y] = rowIndex;
                rowIndex += stride;
            }

            rowIterator = new RowIterator(m_buf, m_rows[0], Width);
        }
示例#2
0
 public void Next_IteratesThroughRow_HasExpected(int row, int[] rowValues)
 {
     _iterator = new RowIterator(_puzzle, row);
     foreach (int value in rowValues)
     {
         Assert.AreEqual(value, _iterator.GetCurrent().Value);
         if (!_iterator.IsDone())
         {
             _iterator.Next();
         }
     }
 }
示例#3
0
        public void Validate_RowWithDuplicateValue_ReturnsFalse()
        {
            var puzzle = new Puzzle(new int[9, 9]
            {
                { 1, 2, 0, 0, 0, 4, 0, 8, 2 },
                { 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, 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, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
            });

            var iterator  = new RowIterator(puzzle, 0);
            var validator = new ValidateSection();

            Assert.IsFalse(validator.Execute(iterator));
        }
示例#4
0
        public void Validate_ValidRow_ReturnsTrue()
        {
            var puzzle = new Puzzle(new int[9, 9]
            {
                { 1, 2, 0, 0, 0, 4, 0, 8, 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, 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, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
            });

            var iterator  = new RowIterator(puzzle, 0);
            var validator = new ValidateSection();

            Assert.IsTrue(validator.Execute(iterator));
        }
示例#5
0
        public void GetValues_Invalid_ReturnsEmptyList()
        {
            var puzzle = new Puzzle(new int[9, 9]
            {
                { 1, 2, 0, 0, 0, 4, 0, 8, 2 },
                { 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, 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, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
            });

            var iterator  = new RowIterator(puzzle, 0);
            var validator = new ValidateSection();

            validator.Execute(iterator);
            Assert.AreEqual(0, validator.GetValues().Count);
        }
示例#6
0
 public void SetUp()
 {
     _puzzle   = new Puzzle(_testPuzzle);
     _iterator = new RowIterator(_puzzle, 0);
 }