public void ChunkGathering() { var map = new Map2D <float>(16, 16); map[1, 1] = 2.0f; map[31, 31] = 4.0f; // Assert we have 2 chunks in memory. Assert.AreEqual((16 * 16) * 2, map.Count); // A single chunk { var chunksFound = map.ChunksWithin(0, 0, 15, 15, createIfNull: false).ToList(); Assert.AreEqual(1, chunksFound.Count()); Assert.AreEqual(0, chunksFound.Select(s => s.Item1.X).First()); // Assert that it is the correct chunk Assert.That(chunksFound.ElementAt(0).Item2.Contains(2.0f)); } // Two chunks { var chunksFound = map.ChunksWithin(0, 0, 31, 31, createIfNull: false).ToList(); Assert.AreEqual(2, chunksFound.Count); Assert.AreEqual(1, chunksFound.Select(s => s.Item1.X).ElementAt(1)); // Assert that these are the correct chunks. Assert.That(chunksFound.ElementAt(0).Item2.Contains(2.0f)); Assert.That(chunksFound.ElementAt(1).Item2.Contains(4.0f)); } }
public void SupportsIrregularSizedMapChunks() { var map = new Map2D <float>(16, 32); var oldBoot = new Entity { Name = "Old Boot" }; var newBoot = new Entity { Name = "New Boot" }; map.PutEntity(1, 1, oldBoot); // W:{1,1}, C:{0,0} map.PutEntity(16, 33, newBoot); // w:{33,33}, C:{0,2} Assert.That(map.GetEntitiesInChunk(new ChunkSpace(0, 0, 0)).Count(), Is.EqualTo(1)); Assert.That(map.GetEntitiesInChunk(new ChunkSpace(0, 2, 0)).Count(), Is.EqualTo(1)); Assert.That(map.GetEntitiesInChunk(new ChunkSpace(0, 0, 0)).Single(), Is.EqualTo(oldBoot)); Assert.That(map.GetEntitiesInChunk(new ChunkSpace(0, 2, 0)).Single(), Is.EqualTo(newBoot)); Assert.That(map.GetEntitiesAt(1, 1).Single() == oldBoot); Assert.That(map.GetEntitiesAt(16, 33).Single() == newBoot); Assert.That(map.ChunksWithin(0, 0, 33, 33, createIfNull: false).Count(), Is.EqualTo(2)); }