private List <int> ApplyRule(List <int> inputItems, IRule rule, int uniqueItemsCount) { List <int> outputItems = new List <int>(inputItems); outputItems = rule.ApplyRule(outputItems, uniqueItemsCount); return(outputItems); }
public void Iterate() { int[,] new_field = new int[fieldSize, fieldSize]; Parallel.For(0, fieldSize, (int x) => { for (int y = 0; y < fieldSize; y++) { switch (rule.GetNeighbourhood()) { case Neighbourhoods.VonNeumann: int[] neighbours = new int[5]; neighbours[0] = field[x, y]; neighbours[1] = field[mod(x - 1, fieldSize), y]; neighbours[2] = field[x, mod(y + 1, fieldSize)]; neighbours[3] = field[mod(x + 1, fieldSize), y]; neighbours[4] = field[x, mod(y - 1, fieldSize)]; new_field[x, y] = rule.ApplyRule(neighbours); break; case Neighbourhoods.Moore: neighbours = new int[9]; neighbours[0] = field[mod(x, fieldSize), mod(y, fieldSize)]; neighbours[1] = field[mod(x + 1, fieldSize), mod(y - 1, fieldSize)]; neighbours[2] = field[mod(x + 1, fieldSize), mod(y, fieldSize)]; neighbours[3] = field[mod(x + 1, fieldSize), mod(y + 1, fieldSize)]; neighbours[4] = field[mod(x, fieldSize), mod(y - 1, fieldSize)]; neighbours[5] = field[mod(x, fieldSize), mod(y + 1, fieldSize)]; neighbours[6] = field[mod(x - 1, fieldSize), mod(y - 1, fieldSize)]; neighbours[7] = field[mod(x - 1, fieldSize), mod(y, fieldSize)]; neighbours[8] = field[mod(x - 1, fieldSize), mod(y + 1, fieldSize)]; new_field[x, y] = rule.ApplyRule(neighbours); break; } } }); field = new_field; }
private static string TestIRule(IRule rule, string request) { // Arrange var context = MakeContext(request); // Act rule.ApplyRule(context); // Assert return(context.HttpContext.Request.Path.ToString()); }