/// <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); }
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(); } } }
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)); }
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)); }
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); }
public void SetUp() { _puzzle = new Puzzle(_testPuzzle); _iterator = new RowIterator(_puzzle, 0); }