public void Equals_ReturnsTrueForObjectsOfEquivPositionAndData() { var thing1 = new Spatial2DThing <string>(new[] { new Point2D() { X = 1, Y = 2 } }); var thing2 = new Spatial2DThing <string>(new[] { new Point2D() { X = 1, Y = 2 } }); var thing3 = new Spatial2DThing <string>(new[] { new Point2D() { X = 1, Y = 3 } }); var thing4 = new Spatial2DThing <string>(new[] { new Point2D() { X = 1, Y = 2 } }); thing1.Data = "A"; thing2.Data = "A"; thing3.Data = "A"; thing4.Data = "B"; Assert.That(thing1.Equals(thing2)); Assert.That(thing1.Equals(thing1)); Assert.That(thing1.Equals(thing3), Is.False); Assert.That(thing1.Equals(thing4), Is.False); }
public void SetObject_AtZero_FiredItemAddedAndModifiedEvent() { var grid = new UniversalGrid <string>(10, 20); var thing1 = new Spatial2DThing <string>(new Point2D()); bool evFired = false; grid.ItemAdded += (s, e) => { Assert.That(e.Target, Is.SameAs(thing1)); evFired = true; }; var modified = false; grid.Modified += (s, e) => { modified = true; }; grid.SetObject(thing1); Assert.That(modified); Assert.That(evFired); }
/// <summary> /// Places an item onto the grid at the given coordinates /// </summary> public ISpatial2DThing <T> SetObject(T item, int x, int y) { var thing = new Spatial2DThing <T>(new Point2D() { X = x, Y = y }) { Data = item }; SetObject(thing); return(thing); }
public void Overlaps_ReturnsTrueWhenPositionsOverlap() { var thing1 = new Spatial2DThing <string>(new[] { new Point2D() { X = 1, Y = 1 } }); var thing2 = new Spatial2DThing <string>(new[] { new Point2D() { X = 1, Y = 1 }, new Point2D() { X = 1, Y = 1 } }); Assert.That(thing1.Overlaps(thing2)); }
public void GetHashCode_ReturnsDifferentValuesForDifferentPositions() { var thing1 = new Spatial2DThing <string>(new[] { new Point2D() { X = 1, Y = 2 } }); var thing2 = new Spatial2DThing <string>(new[] { new Point2D() { X = 1, Y = 1 } }); thing1.Data = "A"; thing2.Data = "A"; Assert.That(thing1.GetHashCode() != thing2.GetHashCode()); }
public void Modified_FiresWhenValueChanged() { var thing1 = new Spatial2DThing <string>(new[] { new Point2D() { X = 1, Y = 2 } }); bool evFired = false; thing1.Data = "A"; thing1.Modified += (s, e) => { evFired = true; }; thing1.Data = "A"; Assert.That(evFired, Is.False); thing1.Data = "B"; Assert.That(evFired); }