public void GetUnknownNodes() { var want = new List <Node> { new Node(new Vector3(-1, 0, -1)), new Node(new Vector3(-1, 0, 0)), new Node(new Vector3(-1, 0, 1)), new Node(new Vector3(0, 0, -1)), new Node(new Vector3(0, 0, 1)), new Node(new Vector3(1, 0, -1)), new Node(new Vector3(1, 0, 0)), new Node(new Vector3(1, 0, 1)) }; var grid = SetupZoneMap.SetupSmallGrid(); grid.MapGrid[1, 1].Unknown = false; var got = grid.UnknownNodes; Assert.Equal(want.Count, got.Count); for (var i = 0; i < want.Count; i++) { Assert.Equal(want[i].WorldPosition, got[i].WorldPosition); Assert.Equal(want[i].Unknown, got[i].Unknown); } }
public void NavigatorDiscoversAllUnknownNodes() { const string want = @" ------------------- | | | | ------------------- | | | | ------------------- | | | | ------------------- "; var grid = SetupZoneMap.SetupSmallGrid(); var traveler = new Traveler(); traveler.CurrentZone = new Zone("test") { Map = grid }; traveler.Position = Vector3.One; traveler.DiscoverAllNodes(); Assert.Empty(traveler.CurrentZone.Map.UnknownNodes); string got = grid.PrintKnown(); Assert.Equal(want, got); }
public void TestPrintSmallGridWithObstacles() { const string want = @" ------------------- | x | x | | ------------------- | x | x | | ------------------- | | | | ------------------- "; // var MapGrid = SetupSmallGrid(); var grid = SetupZoneMap.SetupSmallGrid(); var pos1 = new Vector3(0, 0, 1); var pos2 = new Vector3(-1, 0, 1); var pos3 = new Vector3(-1, 0, 0); grid.AddUnWalkableNode(Vector3.Zero); grid.AddUnWalkableNode(pos1); grid.AddUnWalkableNode(pos2); grid.AddUnWalkableNode(pos3); string got = grid.Print(); SetupZoneMap.AssertPointNotWalkable(grid, pos1); SetupZoneMap.AssertPointNotWalkable(grid, pos2); SetupZoneMap.AssertPointNotWalkable(grid, pos3); Assert.Equal(want, got); }
public void KnownNodeActorCanUpdateKnownNodes() { var map = SetupZoneMap.SetupSmallGrid(); string mapName = SetupPersister.GetCurrentMethodName(); var persister = new FilePersister(mapName); var actor = new KnownNodeActor(persister, map); var traveler = new Traveler(); var watcher = new Watcher(traveler, actor); var newPos = new Vector3(1, 0, 1); traveler.Position = newPos; var wantGrid = SetupZoneMap.SetupSmallGrid(); wantGrid.AddKnownNode(newPos); var want = wantGrid.UnknownNodes; var got = persister.Load <ZoneMap>(); Assert.Equal(want.Count, got.UnknownNodes.Count); for (var i = 0; i < want.Count; i++) { Assert.Equal(want[i], got.UnknownNodes[i]); } }
public void NodeFromWorldPointCanGetANodeFromPositiveVector() { var grid = SetupZoneMap.SetupSmallGrid(); var want = grid.MapGrid[2, 2]; var got = grid.GetNodeFromWorldPoint(new Vector3(1, 0, 1)); Assert.Equal(want.WorldPosition, got.WorldPosition); }
public void TestSerializeZoneMapToJson() { var want = SetupZoneMap.SetupSmallGrid(); var serializer = new ZoneMapSerializer(); string json = serializer.Serialize(want); var got = serializer.DeSerialize(json); SetupZoneMap.AssertGridMapEqual(want.MapGrid, got.MapGrid); }
public void TestCanSetUnknownState() { const bool want = false; var grid = SetupZoneMap.SetupSmallGrid(); grid.MapGrid[0, 0].Unknown = want; bool got = grid.MapGrid[0, 0].Unknown; Assert.Equal(want, got); }
public void AddUnWalkableNodeUpdatesTheNode(float x, float y, int gridX, int gridY) { var grid = SetupZoneMap.SetupSmallGrid(); var position = new Vector3(x, 0, y); var want = new Node(position, false); grid.AddUnWalkableNode(position); var got = grid.MapGrid[gridX, gridY]; Assert.Equal(want.Walkable, got.Walkable); }
public void TestAddKnownNodes(float x, float y, int gridX, int gridY) { var grid = SetupZoneMap.SetupSmallGrid(); var position = new Vector3(x, 0, y); const bool want = false; grid.AddKnownNode(position); bool got = grid.MapGrid[gridX, gridY].Unknown; Assert.Equal(want, got); }
public void AddZoneBorder() { var want = Vector3.One; var zone = new Zone("tests"); zone.Map = SetupZoneMap.SetupSmallGrid(); zone.AddBoundary("A", want, "B", want * -1); var got = zone.Boundaries.Find(b => b.ToZone == "B").FromPosition; Assert.Equal(want, got); }
public void TestCanSaveToFile() { var want = SetupZoneMap.SetupSmallGrid(); var mapName = SetupPersister.GetCurrentMethodName(); var persister = new FilePersister(mapName); persister.Save(want); var got = persister.Load <ZoneMap>(); persister.Delete(); SetupZoneMap.AssertGridMapEqual(want.MapGrid, got.MapGrid); }
public void TestGridFactoryCanGetGridFromFile() { var want = SetupZoneMap.SetupSmallGrid(); var gridFactory = GridFactorySetup.SetupGridFactory(); string mapName = SetupPersister.GetCurrentMethodName(); // Uncomment to make golden file if zoneMap changes. gridFactory.Persister.MapName = mapName; gridFactory.Persister.Save(want); var got = gridFactory.LoadGrid(mapName); SetupZoneMap.AssertGridMapEqual(want.MapGrid, got.MapGrid); }
public void CanCreateAZoneWithConstructor() { var name = "TestMap"; var map = SetupZoneMap.SetupSmallGrid(); var boundaries = new List <ZoneBoundary>(); var got = new Zone(name) { Map = map, Boundaries = boundaries }; Assert.Equal(name, got.Name); Assert.Equal(map, got.Map); Assert.Equal(boundaries, got.Boundaries); }
public void TestCanPrintUnknownGrid() { const string want = @" ------------------- | ? | ? | ? | ------------------- | ? | ? | ? | ------------------- | ? | ? | ? | ------------------- "; var grid = SetupZoneMap.SetupSmallGrid(); string got = grid.PrintKnown(); Assert.Equal(want, got); }
public void TestPrintSmallGrid() { const string want = @" ------------------- | | | | ------------------- | | | | ------------------- | | | | ------------------- "; var grid = SetupZoneMap.SetupSmallGrid(); string got = grid.Print(); Assert.Equal(want, got); }
public void TestPrintWithCoordsSmallGrid() { const string want = @" ------------------------- | -1,1 | 0,1 | 1,1 | ------------------------- | -1,0 | 0,0 | 1,0 | ------------------------- | -1,-1 | 0,-1 | 1,-1 | ------------------------- "; var grid = SetupZoneMap.SetupSmallGrid(); string got = grid.PrintWithCoords(); Assert.Equal(want, got); }
public void BenchmarkSerializeZoneMap() { var want = SetupZoneMap.SetupSmallGrid(); var serializer = new ZoneMapSerializer(); int time = Benchmark.Run("StreamReader.ReadToEnd", 5, () => { string json = serializer.Serialize(want); var got = serializer.DeSerialize(json); }); int benchTime = 1; Assert.True(time < benchTime, "time per iteration was: " + time + "ms which is greater than expected time of: " + benchTime + "ms"); }
public void LoadGridOrCreateNewLoadsGridIfExists() { var want = SetupZoneMap.SetupSmallGrid(); var gridFactory = GridFactorySetup.SetupGridFactory(); string mapName = SetupPersister.GetCurrentMethodName(); want.MapName = mapName; // Uncomment to make golden file if zoneMap changes. gridFactory.Persister.MapName = mapName; gridFactory.Persister.Save(want); var got = gridFactory.LoadGridOrCreateNew(mapName); SetupZoneMap.AssertGridMapEqual(want.MapGrid, got.MapGrid); Assert.Equal(want.MapName, got.MapName); }
public void TestCanLoadGridFromFile() { var want = SetupZoneMap.SetupSmallGrid(); var mapName = SetupPersister.GetCurrentMethodName(); var persister = new FilePersister(mapName); // Path assumes to start from ./debug/ so we want to set it to the test fixtures dir. string grandParentDirectory = Directory.GetParent(persister.FilePath).FullName; string parentDirectory = Directory.GetParent(grandParentDirectory).FullName; persister.FilePath = Path.Combine(parentDirectory, "fixtures"); // Uncomment to make golden file if zoneMap changes. persister.Save(want); var got = persister.Load <ZoneMap>(); SetupZoneMap.AssertGridMapEqual(want.MapGrid, got.MapGrid); }
public void TestCanPrintUnknownGridWithKnownSpots() { const string want = @" ------------------- | ? | ? | ? | ------------------- | ? | | | ------------------- | | ? | | ------------------- "; var grid = SetupZoneMap.SetupSmallGrid(); grid.AddKnownNode(new Vector3(0, 0, 0)); grid.AddKnownNode(new Vector3(1, 0, 0)); grid.AddKnownNode(new Vector3(1, 0, -1)); grid.AddKnownNode(new Vector3(-1, 0, -1)); string got = grid.PrintKnown(); Assert.Equal(want, got); }
public void SerializeMakesACleanMap() { string want = @"{ 'MapGrid': [ [ { 'GridX': 0, 'GridY': 0, 'X': -1, 'Y': 0, 'Z': -1, 'Unknown': true, 'Walkable': true }, { 'GridX': 0, 'GridY': 1, 'X': -1, 'Y': 0, 'Z': 0, 'Unknown': true, 'Walkable': true }, { 'GridX': 0, 'GridY': 2, 'X': -1, 'Y': 0, 'Z': 1, 'Unknown': true, 'Walkable': true } ], [ { 'GridX': 1, 'GridY': 0, 'X': 0, 'Y': 0, 'Z': -1, 'Unknown': true, 'Walkable': true }, { 'GridX': 1, 'GridY': 1, 'X': 0, 'Y': 0, 'Z': 0, 'Unknown': true, 'Walkable': true }, { 'GridX': 1, 'GridY': 2, 'X': 0, 'Y': 0, 'Z': 1, 'Unknown': true, 'Walkable': true } ], [ { 'GridX': 2, 'GridY': 0, 'X': 1, 'Y': 0, 'Z': -1, 'Unknown': true, 'Walkable': true }, { 'GridX': 2, 'GridY': 1, 'X': 1, 'Y': 0, 'Z': 0, 'Unknown': true, 'Walkable': true }, { 'GridX': 2, 'GridY': 2, 'X': 1, 'Y': 0, 'Z': 1, 'Unknown': true, 'Walkable': true } ] ], 'MapName': 'Small ZoneMap', 'GridWorldSize': { 'X': 3.0, 'Y': 3.0 } }"; var map = SetupZoneMap.SetupSmallGrid(); string got = PathfinderSerializer.Serialize(map); Assert.Equal(want, got); }