private void ScanRegion(RegionQueue regions, MutablePuzzle puzzle, Region region) { var placedDigits = region.GetPlacedDigits(); for (int i = 1; i <= Puzzle.LineLength; i++) { var digit = SudokuValues.FromHumanValue(i); if (placedDigits.HasAnyOptions(digit)) { continue; } var positions = region.GetPositions(digit); if (positions.IsSingle) { var index = positions.ToIndex(); var coords = region.GetCoordinate(index); var update = new CellUpdate(digit.Invert(), coords); puzzle.RemoveOptions(update); regions.Enqueue(RegionType.Row, coords.Row); regions.Enqueue(RegionType.Column, coords.Column); regions.Enqueue(RegionType.Box, coords.Box); } } }
public void GameLogicAllZombieTest() { int size = 5; GameOfLife target = new GameOfLife(size); CellUpdate[] cellUpdates = new CellUpdate[size * size]; int c = 0; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { cellUpdates[c] = new CellUpdate(i, j, null); c++; } } target.ChangeCellStates(cellUpdates); int?[,] Grid = target.GetGrid(); c = 0; // Reset count for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { Assert.AreEqual(null, Grid[i, j], "Failed at " + i + "," + j); c++; } } }
public void AsEditCellValue(bool isNull) { // Setup: Create a cell update var value = isNull ? "NULL" : "foo"; var col = GetWrapper <string>("NTEXT"); CellUpdate cu = new CellUpdate(col, value); // If: I convert the cell update to an EditCell EditCell ec = cu.AsEditCell; // Then: // ... It should not be null Assert.NotNull(ec); // ... The display value should be the same as the value we supplied Assert.Equal(value, ec.DisplayValue); // ... The null-ness of the value should be the same as what we supplied Assert.Equal(isNull, ec.IsNull); // ... We don't care *too* much about the raw value, but we'll check it anyhow Assert.Equal(isNull ? (object)DBNull.Value : value, ec.RawObject); // ... The edit cell should be dirty Assert.True(ec.IsDirty); }
public void UpdateField() { Field.Iteration += 1; Field TempField = new Field(new TwoIntegerVariable { X = Field.Cells.GetLength(0), Y = Field.Cells.GetLength(1) }); for (int x = 0; x < Field.Cells.GetLength(0); x++) { for (int y = 0; y < Field.Cells.GetLength(1); y++) { Cell c = new Cell(); TempField.Cells[x, y] = new Cell(); CellUpdate Update = new CellUpdate(c); Update.ChangeStatus(Field.Cells[x, y].IsAlive); Update.ChangeStatus(new Neighbors(Field.Cells).GetNeighborCount(x, y)); //Update.ChangeStatus(Neighbors().GetNeighborCount(x, y)); bug is here Update = new CellUpdate(TempField.Cells[x, y]); Update.ChangeStatus(c.IsAlive); } } int AliveCells = new AliveCells(Field.Cells).GetAliveCellsCount(); Field.Cells = TempField.Cells; }
public void ByteArrayTest(string strValue, byte[] expectedValue, string expectedString) { // If: I attempt to create a CellUpdate for a binary column DbColumnWrapper col = GetWrapper <byte[]>("binary"); CellUpdate cu = new CellUpdate(col, strValue); // Then: The value should be a binary and should match the expected data Assert.IsType <byte[]>(cu.Value); Assert.Equal(expectedValue, cu.Value); Assert.Equal(expectedString, cu.ValueAsString); Assert.Equal(col, cu.Column); }
public void NullTextStringTest() { // If: I attempt to create a CellUpdate with the text 'NULL' (with mixed case) DbColumnWrapper col = GetWrapper <string>("ntext"); CellUpdate cu = new CellUpdate(col, "'NULL'"); // Then: The value should be NULL Assert.IsType <string>(cu.Value); Assert.Equal("NULL", cu.Value); Assert.Equal("'NULL'", cu.ValueAsString); Assert.Equal(col, cu.Column); }
public void BoolTest(string input, bool output, string outputString) { // If: I attempt to create a CellUpdate for a boolean column DbColumnWrapper col = GetWrapper <bool>("bit"); CellUpdate cu = new CellUpdate(col, input); // Then: The value should match what was expected Assert.IsType <bool>(cu.Value); Assert.Equal(output, cu.Value); Assert.Equal(outputString, cu.ValueAsString); Assert.Equal(col, cu.Column); }
public void NullStringAllowedTest() { // If: I attempt to create a CellUpdate to set it to NULL const string nullString = "NULL"; DbColumnWrapper col = GetWrapper <string>("ntext"); CellUpdate cu = new CellUpdate(col, nullString); // Then: The value should be a DBNull and the string value should be the same as what // was given Assert.IsType <DBNull>(cu.Value); Assert.Equal(DBNull.Value, cu.Value); Assert.Equal(nullString, cu.ValueAsString); Assert.Equal(col, cu.Column); }
public void RoundTripTest(DbColumnWrapper col, object obj) { // Setup: Figure out the test string string testString = obj.ToString(); // If: I attempt to create a CellUpdate CellUpdate cu = new CellUpdate(col, testString); // Then: The value and type should match what we put in Assert.IsType(col.DataType, cu.Value); Assert.Equal(obj, cu.Value); Assert.Equal(testString, cu.ValueAsString); Assert.Equal(col, cu.Column); }
public void GameLogicTest() { int size = 5; GameOfLife target = new GameOfLife(size); CellUpdate[] cellUpdates = new CellUpdate[size * size]; int?[] states = { 1, 1, 0, 1, 0, null, 0, 1, 1, 1, null, 1, null, 0, null, 1, 1, null, 1, 1, null, null, 0, null, 1 }; int c = 0; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { cellUpdates[c] = new CellUpdate(i, j, states[c]); c++; } } target.ChangeCellStates(cellUpdates); target.NextDay(); int?[,] Grid = target.GetGrid(); // 2: Alive or zombie // 3: Dead or zombie int?[] nextDayStates = { 3, 3, 0, 1, 1, null, 0, 3, 2, 2, null, 2, null, 0, null, 2, 2, null, 2, 2, null, null, 0, null, 2 }; c = 0; // Reset count for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (nextDayStates[c] == 3) { Assert.IsTrue(Grid[i, j] == 0 || Grid[i, j] == null, "Failed at " + i + "," + j); } else if (nextDayStates[c] == 2) { Assert.IsTrue(Grid[i, j] == 1 || Grid[i, j] == null, "Failed at " + i + "," + j); } else { Assert.AreEqual(nextDayStates[c], Grid[i, j], "Failed at " + i + "," + j); } c++; } } }
public void CreateBlinker() { for (int x = 0; x < Field.Cells.GetLength(0); x++) { for (int y = 0; y < Field.Cells.GetLength(1); y++) { Field.Cells[x, y] = new Cell(); CellUpdate = new CellUpdate(Field.Cells[x, y]); if (x == 2 && ((y == 1) || (y == 2) || (y == 3))) { CellUpdate.ChangeStatus(true); } else { CellUpdate.ChangeStatus(false); } } } }
public void RandomPopulation() { Random r = new Random(); for (int x = 0; x < Field.Cells.GetLength(0); x++) { for (int y = 0; y < Field.Cells.GetLength(1); y++) { Field.Cells[x, y] = new Cell(); CellUpdate = new CellUpdate(Field.Cells[x, y]); if (r.Next(2) == 1) { CellUpdate.ChangeStatus(true); } else { CellUpdate.ChangeStatus(false); } } } }
public SingleCellChangeSet(CellUpdate update) { _update = update; }