public static void AssertVisibility(LevelComponent level, string expectedVisibleMap, byte[] actualVisibility) { var expectedFragment = new NormalMapFragment { Map = expectedVisibleMap, Width = level.Width, Height = level.Height }; expectedFragment.EnsureInitialized(level.Game); var expectedVisibility = new byte[level.Height * level.Width]; Point?mismatchedPoint = null; expectedFragment.WriteMap( new Point(0, 0), level, (c, point, l, _) => { var expectedVisible = c == ' ' ? (byte)0 : (byte)255; var i = l.PointToIndex[point.X, point.Y]; expectedVisibility[i] = expectedVisible; var actualVisible = actualVisibility[i] == 0 ? 0 : 255; if (expectedVisible != actualVisible && mismatchedPoint == null) { mismatchedPoint = point; } }, (object)null); if (mismatchedPoint.HasValue) { Assert.False(true, $"Mismatch at ({mismatchedPoint.Value.X}, {mismatchedPoint.Value.Y})" + @" Expected map: " + PrintMap(level, expectedVisibility) + @" Actual map: " + PrintMap(level, actualVisibility) + @" Seed: " + level.Game.InitialSeed); } }
public static void AssertTerrain(LevelComponent level, string expectedMap, byte[] actualTerrain) { var expectedFragment = new NormalMapFragment { Map = expectedMap, Width = level.Width, Height = level.Height }; expectedFragment.EnsureInitialized(level.Game); var expected = new byte[level.Height * level.Width]; var matched = true; expectedFragment.WriteMap( new Point(0, 0), level, (c, point, l, _) => { var expectedFeature = (byte)ToMapFeature(c); var i = l.PointToIndex[point.X, point.Y]; expected[i] = expectedFeature; if (expectedFeature != actualTerrain[i] && (expectedFeature == (byte)MapFeature.Default || expectedFeature == (byte)MapFeature.Unexplored) && !(actualTerrain[i] == (byte)MapFeature.Default || actualTerrain[i] == (byte)MapFeature.Unexplored)) { matched = false; } }, (object)null); Assert.True(matched, @"Expected: " + PrintMap(level, null, expected) + @" Actual: " + PrintMap(level, null, actualTerrain) + @" Seed: " + level.Game.InitialSeed); }