Ejemplo n.º 1
0
        public void MultiSpatialMapAdd()
        {
            var mySpatialMap = new MultiSpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);

            mySpatialMap.Add(myId1, (1, 2));
            Assert.Equal(1, mySpatialMap.Count);

            var retVal = mySpatialMap.Contains((1, 2));

            Assert.True(retVal);

            retVal = mySpatialMap.Contains(myId1);
            Assert.True(retVal);

            retVal = mySpatialMap.Contains((2, 3));
            Assert.False(retVal);

            retVal = mySpatialMap.Contains(myId2);
            Assert.False(retVal);

            var count = mySpatialMap.GetItemsAt((1, 2)).Count();

            Assert.Equal(1, count);

            count = mySpatialMap.GetItemsAt((2, 3)).Count();
            Assert.Equal(0, count);

            mySpatialMap.Add(myId2, (1, 2));

            count = mySpatialMap.GetItemsAt((1, 2)).Count();
            Assert.Equal(2, count);
        }
Ejemplo n.º 2
0
        public void MultiSpatialMapAdd()
        {
            var mySpatialMap = new MultiSpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);
            var myId3 = new MyIDImpl(2);

            mySpatialMap.Add(myId1, (1, 2));
            Assert.AreEqual(1, mySpatialMap.Count);

            bool retVal = mySpatialMap.Contains((1, 2));

            Assert.AreEqual(true, retVal);

            retVal = mySpatialMap.Contains(myId1);
            Assert.AreEqual(true, retVal);

            retVal = mySpatialMap.Contains((2, 3));
            Assert.AreEqual(false, retVal);

            retVal = mySpatialMap.Contains(myId2);
            Assert.AreEqual(false, retVal);

            int count = 0;

            foreach (var item in mySpatialMap.GetItems((1, 2)))
            {
                count++;
            }
            Assert.AreEqual(1, count);

            count = 0;
            foreach (var item in mySpatialMap.GetItems((2, 3)))
            {
                count++;
            }
            Assert.AreEqual(0, count);

            retVal = mySpatialMap.Add(myId2, (1, 2));
            Assert.AreEqual(true, retVal);

            count = 0;
            foreach (var item in mySpatialMap.GetItems((1, 2)))
            {
                count++;
            }
            Assert.AreEqual(2, count);
        }
Ejemplo n.º 3
0
        public void MultiSpatialMapRemove()
        {
            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));

            bool retVal = mySpatialMap.Remove(myId1);

            Assert.AreEqual(true, retVal);

            retVal = mySpatialMap.Contains(myId1);
            Assert.AreEqual(false, retVal);

            retVal = mySpatialMap.Contains((1, 2));
            Assert.AreEqual(true, retVal);

            int count = 0;

            foreach (var i in mySpatialMap.Remove((2, 3)))
            {
                count++;
            }

            Assert.AreEqual(1, count);

            Assert.AreEqual(false, mySpatialMap.Contains((2, 3)));
            Assert.AreEqual(false, mySpatialMap.Contains(myId2));

            retVal = mySpatialMap.Remove(myId1);
            Assert.AreEqual(false, retVal);

            count = 0;
            foreach (var i in mySpatialMap.Remove((5, 6)))
            {
                count++;
            }
            Assert.AreEqual(0, count);
        }
Ejemplo n.º 4
0
        public void MultiSpatialMapMove()
        {
            var mySpatialMap = new MultiSpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);

            mySpatialMap.Add(myId1, Coord.Get(1, 2));
            mySpatialMap.Add(myId2, Coord.Get(2, 3));

            bool retVal = mySpatialMap.Move(myId1, Coord.Get(5, 6));

            Assert.AreEqual(true, retVal);
            Assert.AreEqual(Coord.Get(5, 6), mySpatialMap.GetPosition(myId1));

            retVal = mySpatialMap.Contains(Coord.Get(5, 6));
            Assert.AreEqual(true, retVal);

            retVal = mySpatialMap.Contains(Coord.Get(1, 2));
            Assert.AreEqual(false, retVal);

            retVal = mySpatialMap.Contains(Coord.Get(2, 3));
            Assert.AreEqual(true, retVal);

            retVal = mySpatialMap.Move(myId2, Coord.Get(5, 6));
            Assert.AreEqual(true, retVal);

            Assert.AreEqual(false, mySpatialMap.Contains(Coord.Get(2, 3)));
            Assert.AreEqual(true, mySpatialMap.Contains(Coord.Get(5, 6)));

            int count = 0;

            foreach (var i in mySpatialMap.GetItems(Coord.Get(5, 6)))
            {
                count++;
            }
            Assert.AreEqual(2, count);
        }
Ejemplo n.º 5
0
        public void MultiSpatialMapRemove()
        {
            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));

            mySpatialMap.Remove(myId1);


            var retVal = mySpatialMap.Contains(myId1);

            Assert.False(retVal);

            retVal = mySpatialMap.Contains((1, 2));
            Assert.True(retVal);



            Assert.Single(mySpatialMap.Remove((2, 3)));

            Assert.False(mySpatialMap.Contains((2, 3)));
            Assert.False(mySpatialMap.Contains(myId2));

            Assert.Throws <ArgumentException>(() => mySpatialMap.Remove(myId1));


            Assert.Empty(mySpatialMap.Remove((5, 6)));
        }