public void MultiSpatialMapMove() { var mySpatialMap = new MultiSpatialMap <MyIDImpl>(); var myId1 = new MyIDImpl(0); var myId2 = new MyIDImpl(1); mySpatialMap.Add(myId1, (1, 2)); mySpatialMap.Add(myId2, (2, 3)); mySpatialMap.Move(myId1, (5, 6)); Assert.Equal(new Point(5, 6), mySpatialMap.GetPositionOf(myId1)); var retVal = mySpatialMap.Contains((5, 6)); Assert.True(retVal); retVal = mySpatialMap.Contains((1, 2)); Assert.False(retVal); retVal = mySpatialMap.Contains((2, 3)); Assert.True(retVal); mySpatialMap.Move(myId2, (5, 6)); Assert.False(mySpatialMap.Contains((2, 3))); Assert.True(mySpatialMap.Contains((5, 6))); Assert.Equal(2, mySpatialMap.GetItemsAt((5, 6)).Count()); }
public void MultiSpatialMapMoveValid() { var mySpatialMap = new MultiSpatialMap <MyIDImpl>(); var myId1 = new MyIDImpl(0); var myId2 = new MyIDImpl(1); var myId3 = new MyIDImpl(2); var myId4 = new MyIDImpl(3); mySpatialMap.Add(myId1, (1, 2)); mySpatialMap.Add(myId2, (2, 3)); mySpatialMap.Add(myId3, (3, 4)); mySpatialMap.Add(myId4, (1, 2)); // Move the two items at (1, 2) to (3, 4) (already occupied location) var list = mySpatialMap.MoveValid((1, 2), (3, 4)); Assert.Equal(2, list.Count); Assert.Contains(myId1, list); Assert.Contains(myId4, list); Assert.Equal(new Point(3, 4), mySpatialMap.GetPositionOf(myId1)); Assert.Equal(new Point(3, 4), mySpatialMap.GetPositionOf(myId4)); Assert.Equal(3, mySpatialMap.GetItemsAt((3, 4)).Count()); var retVal = mySpatialMap.Contains((3, 4)); Assert.True(retVal); retVal = mySpatialMap.Contains((1, 2)); Assert.False(retVal); retVal = mySpatialMap.Contains((2, 3)); Assert.True(retVal); // Move the one item at (2, 3) to (6, 7) (unoccupied location) list = mySpatialMap.MoveValid((2, 3), (6, 7)); Assert.Contains(myId2, list); Assert.Single(list); Assert.False(mySpatialMap.Contains((2, 3))); Assert.True(mySpatialMap.Contains((6, 7))); Assert.Single(mySpatialMap.GetItemsAt((6, 7))); }