public void GetSite_Mutable_0_0() { MutableSite site = null; Assert.IsFalse(landscape.GetSite(new Location(0, 0), ref site)); Assert.IsNull(site); }
public void GetSite_Mutable() { MutableSite site = null; MutableSite siteFrom1stCall = null; int index = 0; Location?nextActiveSite; if (index < activeSites.Count) { nextActiveSite = activeSites[index]; } else { nextActiveSite = null; } for (uint row = 1; row <= grid.Rows; ++row) { for (uint col = 1; col <= grid.Columns; ++col) { Location location = new Location(row, col); Assert.IsTrue(landscape.GetSite(location, ref site)); if (siteFrom1stCall == null) { siteFrom1stCall = site; } else { Assert.AreSame(siteFrom1stCall, site); } Assert.IsTrue(site.IsMutable); if (nextActiveSite != null && nextActiveSite == location) { Assert.AreEqual(location, site.Location); Assert.AreEqual(index + 1, site.DataIndex); Assert.AreEqual(landscape, site.Landscape); Assert.AreEqual(true, site.IsActive); index++; if (index < activeSites.Count) { nextActiveSite = activeSites[index]; } else { nextActiveSite = null; } } else { Assert.AreEqual(location, site.Location); Assert.AreEqual(landscape.InactiveSiteDataIndex, site.DataIndex); Assert.AreEqual(landscape, site.Landscape); Assert.AreEqual(false, site.IsActive); } } } }
public void UpperLeft_8Neighbors_Mutable() { Site site = landscape.GetSite(1, 1); // Check all 8 immediate neighbors starting with the one due // north and working clockwise. MutableSite neighbor = null; // North Assert.IsFalse(site.GetNeighbor(new RelativeLocation(-1, 0), ref neighbor)); Assert.IsNull(neighbor); // North-east Assert.IsFalse(site.GetNeighbor(new RelativeLocation(-1, 1), ref neighbor)); Assert.IsNull(neighbor); // East Assert.IsTrue(site.GetNeighbor(new RelativeLocation(0, 1), ref neighbor)); CheckNeighbor(neighbor, new Location(1, 2)); // South-east Assert.IsTrue(site.GetNeighbor(new RelativeLocation(1, 1), ref neighbor)); CheckNeighbor(neighbor, new Location(2, 2)); // South Assert.IsTrue(site.GetNeighbor(new RelativeLocation(1, 0), ref neighbor)); CheckNeighbor(neighbor, new Location(2, 1)); // South-west Assert.IsFalse(site.GetNeighbor(new RelativeLocation(1, -1), ref neighbor)); // Neighbor unchanged, so it stills refers to south neighbor CheckNeighbor(neighbor, new Location(2, 1)); // West Assert.IsFalse(site.GetNeighbor(new RelativeLocation(0, -1), ref neighbor)); // Neighbor unchanged, so it stills refers to south neighbor CheckNeighbor(neighbor, new Location(2, 1)); // North-west Assert.IsFalse(site.GetNeighbor(new RelativeLocation(-1, -1), ref neighbor)); // Neighbor unchanged, so it stills refers to south neighbor CheckNeighbor(neighbor, new Location(2, 1)); }
public void GetNeighbor_Mutable() { Site site = landscape[3, 7]; MutableSite neighbor = null; Assert.IsTrue(site.GetNeighbor(new RelativeLocation(0, 1), ref neighbor)); CheckNeighbor(neighbor, new Location(3, 8)); Assert.IsTrue(site.GetNeighbor(new RelativeLocation(2, 0), ref neighbor)); CheckNeighbor(neighbor, new Location(5, 7)); Assert.IsTrue(site.GetNeighbor(new RelativeLocation(0, -4), ref neighbor)); CheckNeighbor(neighbor, new Location(3, 3)); Assert.IsTrue(site.GetNeighbor(new RelativeLocation(-1, 0), ref neighbor)); CheckNeighbor(neighbor, new Location(2, 7)); Assert.IsTrue(site.GetNeighbor(new RelativeLocation(3, -3), ref neighbor)); CheckNeighbor(neighbor, new Location(6, 4)); }