I'm going to test function returning array of von Neumann neighbours of cell in 2D Array. Cells contains data about simulation.
To conduct test I'm setting new Cell[,] and populate with Cell instances. The test should check if neighbours returned by function is this same instances as expected and in this same order in array.
public class VonNeumanNeighbourhoodTest
{
private static Cell a,b,c,d,e,f,g,h,i ;
private static Cell[,] space;
public VonNeumanNeighborhoodTest() {
a = new Cell{ GrainMembership = new Grain(0, Color.Red) };
b = new Cell{ GrainMembership = new Grain(1, Color.Green) };
// And so on
i = new Cell{ GrainMembership = new Grain(8, Color.Azure) };
space = new Cell[3, 3]
{
{ a, b, c },
{ d, e, f },
{ g, h, i }
};
}
The problem occures in test method. Cell[] expected
always contains {null, null, null, null} in debug instead of eg.{b, f, h, d} reference.
[Theory]
[ClassData(typeof(AbsorbingTestData))]
public void AbsorbingTest(int x, int y, Cell[] expected)
{
var neighbours = VonNeumanNeighbourhood.Neighbours(space , x, y, AbsorbingBoundary.BoundaryCondition);
for(int i = 0; i < 4; i++)
{
Assert.Same(neighbours[i], expected[i]);//Checking if neighbours and expected are this same instances
}
}
}
private class AbsorbingTestData : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
{
yield return new object[] { 1, 1, new Cell[]{b, f, h, d} }; //e - center
yield return new object[] { 0, 0, new Cell[]{null, b, d, null} }; //a
//More cases
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
I was trying similar code with [MemberData] attribute but with this same results.