public void GiveRange_MergeAfterFirstTest() {
    IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);
    uidSet.GiveRange(1, 5);
    uidSet.GiveRange(10, 12);
    uidSet.GiveRange(8, 9);
    AssertEquals("[1, 5][8, 12]", uidSet.ToString());
 }
      public void GiveRange_MergeMultipleTest() {
         var hardList = new LinkedList<UniqueIdentificationSet.Segment>().With(list => {
            list.AddLast(new UniqueIdentificationSet.Segment { low = 1, high = 5 });
            list.AddLast(new UniqueIdentificationSet.Segment { low = 12, high = 15 });
            list.AddLast(new UniqueIdentificationSet.Segment { low = 30, high = 50 });
            list.AddLast(new UniqueIdentificationSet.Segment { low = 52, high = 100 });
            list.AddLast(new UniqueIdentificationSet.Segment { low = 150, high = 200 });
         });
         IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);
         uidSet.__Assign(hardList);
         uidSet.GiveRange(0, 16);
         AssertEquals("[0, 16][30, 50][52, 100][150, 200]", uidSet.ToString());

         uidSet.__Assign(hardList);
         uidSet.GiveRange(15, 51);
         AssertEquals("[1, 5][12, 100][150, 200]", uidSet.ToString());

         uidSet.__Assign(hardList);
         uidSet.GiveRange(15, UInt32.MaxValue);
         AssertEquals("[1, 5][12, " + UInt32.MaxValue + "]", uidSet.ToString());

         uidSet.__Assign(hardList);
         uidSet.GiveRange(0, UInt32.MaxValue);
         AssertEquals("[0, " + UInt32.MaxValue + "]", uidSet.ToString());

         uidSet.__Assign(hardList);
         uidSet.GiveRange(201, 1000);
         AssertEquals("[1, 5][12, 15][30, 50][52, 100][150, 1000]", uidSet.ToString());

         uidSet.__Assign(hardList);
         uidSet.GiveRange(0, 0);
         AssertEquals("[0, 5][12, 15][30, 50][52, 100][150, 200]", uidSet.ToString());
      }
 public void GiveRange_AppendInMiddleTest() {
    IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);
    uidSet.GiveRange(12, 15);
    uidSet.GiveRange(18, 20);
    uidSet.GiveRange(1, 5);
    uidSet.GiveRange(7, 10);
    AssertEquals("[1, 5][7, 10][12, 15][18, 20]", uidSet.ToString());
 }
Пример #4
0
        public void GiveRange_MergeAfterFirstTest()
        {
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);

            uidSet.GiveRange(1, 5);
            uidSet.GiveRange(10, 12);
            uidSet.GiveRange(8, 9);
            AssertEquals("[1, 5][8, 12]", uidSet.ToString());
        }
 public void GiveRange_PrependToFrontTest() {
    IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);
    uidSet.Clear();
    uidSet.GiveRange(18, 20);
    uidSet.GiveRange(12, 15);
    uidSet.GiveRange(7, 10);
    uidSet.GiveRange(1, 5);
    AssertEquals("[1, 5][7, 10][12, 15][18, 20]", uidSet.ToString());
 }
Пример #6
0
        public void GiveRange_AppendInMiddleTest()
        {
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);

            uidSet.GiveRange(12, 15);
            uidSet.GiveRange(18, 20);
            uidSet.GiveRange(1, 5);
            uidSet.GiveRange(7, 10);
            AssertEquals("[1, 5][7, 10][12, 15][18, 20]", uidSet.ToString());
        }
Пример #7
0
        public void GiveRange_PrependToFrontTest()
        {
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);

            uidSet.Clear();
            uidSet.GiveRange(18, 20);
            uidSet.GiveRange(12, 15);
            uidSet.GiveRange(7, 10);
            uidSet.GiveRange(1, 5);
            AssertEquals("[1, 5][7, 10][12, 15][18, 20]", uidSet.ToString());
        }
Пример #8
0
        public void ContainsTest()
        {
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(1, 4);

            uidSet.GiveRange(6, 15);
            uidSet.TakeRange(10, 11);

            AssertFalse(uidSet.Contains(0));
            AssertTrue(uidSet.Contains(1));
            AssertTrue(uidSet.Contains(2));
            AssertTrue(uidSet.Contains(3));
            AssertTrue(uidSet.Contains(4));
            AssertFalse(uidSet.Contains(5));
            AssertTrue(uidSet.Contains(6));
            AssertTrue(uidSet.Contains(7));
            AssertTrue(uidSet.Contains(8));
            AssertTrue(uidSet.Contains(9));
            AssertFalse(uidSet.Contains(10));
            AssertFalse(uidSet.Contains(11));
            AssertTrue(uidSet.Contains(12));
            AssertTrue(uidSet.Contains(13));
            AssertTrue(uidSet.Contains(14));
            AssertTrue(uidSet.Contains(15));
            AssertFalse(uidSet.Contains(16));

            AssertTrue(new UniqueIdentificationSet(0, 4).Contains(0));
        }
Пример #9
0
        public void Any_ComplexTest()
        {
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(1, 2);

            uidSet.GiveRange(4, 5);

            AssertEquals(4, uidSet.Count);
        }
Пример #10
0
        public void GiveTakeMergeExceptInvertIntersectRangeRandomTest()
        {
            var random = new Random();
            var set    = new HashSet <uint>();
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);

            for (var it = 0; it < 20000; it++)
            {
                var low  = (uint)(random.NextDouble() * (long)100000);
                var high = low + (uint)(random.NextDouble() * (long)100);

                if (random.Next() % 2 == 0)
                {
                    for (var val = low; val <= high; val++)
                    {
                        AssertEquals(set.Add(val), !uidSet.Contains(val));
                    }
                    if (random.Next() % 2 == 0)
                    {
                        uidSet.GiveRange(low, high);
                    }
                    else
                    {
                        uidSet = uidSet.Merge(new UniqueIdentificationSet(low, high).Invert().Invert());
                    }
                    for (var val = low; val <= high; val++)
                    {
                        AssertTrue(uidSet.Contains(val));
                    }
                }
                else
                {
                    for (var val = low; val <= high; val++)
                    {
                        AssertEquals(set.Remove(val), uidSet.Contains(val));
                    }
                    var rand = random.Next() % 3;
                    if (rand == 0)
                    {
                        uidSet.TakeRange(low, high);
                    }
                    else if (rand == 1)
                    {
                        uidSet = uidSet.Except(new UniqueIdentificationSet(low, high).Invert().Invert());
                    }
                    else
                    {
                        uidSet = uidSet.Intersect(new UniqueIdentificationSet(low, high).Invert());
                    }
                    for (var val = low; val <= high; val++)
                    {
                        AssertFalse(uidSet.Contains(val));
                    }
                }
            }
        }
Пример #11
0
        public void GiveRange_MergeMultipleTest()
        {
            var hardList = new LinkedList <UniqueIdentificationSet.Segment>().With(list => {
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 1, high = 5
                });
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 12, high = 15
                });
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 30, high = 50
                });
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 52, high = 100
                });
                list.AddLast(new UniqueIdentificationSet.Segment {
                    low = 150, high = 200
                });
            });
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);

            uidSet.__Assign(hardList);
            uidSet.GiveRange(0, 16);
            AssertEquals("[0, 16][30, 50][52, 100][150, 200]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.GiveRange(15, 51);
            AssertEquals("[1, 5][12, 100][150, 200]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.GiveRange(15, UInt32.MaxValue);
            AssertEquals("[1, 5][12, " + UInt32.MaxValue + "]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.GiveRange(0, UInt32.MaxValue);
            AssertEquals("[0, " + UInt32.MaxValue + "]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.GiveRange(201, 1000);
            AssertEquals("[1, 5][12, 15][30, 50][52, 100][150, 1000]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.GiveRange(0, 0);
            AssertEquals("[0, 5][12, 15][30, 50][52, 100][150, 200]", uidSet.ToString());
        }
      public void ContainsTest() {
         IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(1, 4);
         uidSet.GiveRange(6, 15);
         uidSet.TakeRange(10, 11);

         AssertFalse(uidSet.Contains(0));
         AssertTrue(uidSet.Contains(1));
         AssertTrue(uidSet.Contains(2));
         AssertTrue(uidSet.Contains(3));
         AssertTrue(uidSet.Contains(4));
         AssertFalse(uidSet.Contains(5));
         AssertTrue(uidSet.Contains(6));
         AssertTrue(uidSet.Contains(7));
         AssertTrue(uidSet.Contains(8));
         AssertTrue(uidSet.Contains(9));
         AssertFalse(uidSet.Contains(10));
         AssertFalse(uidSet.Contains(11));
         AssertTrue(uidSet.Contains(12));
         AssertTrue(uidSet.Contains(13));
         AssertTrue(uidSet.Contains(14));
         AssertTrue(uidSet.Contains(15));
         AssertFalse(uidSet.Contains(16));

         AssertTrue(new UniqueIdentificationSet(0, 4).Contains(0));
      }
      public void Any_ComplexTest() {
         IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(1, 2);
         uidSet.GiveRange(4, 5);

         AssertEquals(4, uidSet.Count);
      }
      public void GiveTakeMergeExceptInvertIntersectRangeRandomTest() {
         var random = new Random();
         var set = new HashSet<uint>();
         IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(false);
         for (var it = 0; it < 20000; it++) {
            var low = (uint)(random.NextDouble() * (long)100000);
            var high = low + (uint)(random.NextDouble() * (long)100);

            if (random.Next() % 2 == 0) {
               for (var val = low; val <= high; val++) {
                  AssertEquals(set.Add(val), !uidSet.Contains(val));
               }
               if (random.Next() % 2 == 0) {
                  uidSet.GiveRange(low, high);
               } else {
                  uidSet = uidSet.Merge(new UniqueIdentificationSet(low, high).Invert().Invert());
               }
               for (var val = low; val <= high; val++) {
                  AssertTrue(uidSet.Contains(val));
               }
            } else {
               for (var val = low; val <= high; val++) {
                  AssertEquals(set.Remove(val), uidSet.Contains(val));
               }
               var rand = random.Next() % 3;
               if (rand == 0) {
                  uidSet.TakeRange(low, high);
               } else if (rand == 1) {
                  uidSet = uidSet.Except(new UniqueIdentificationSet(low, high).Invert().Invert());
               } else {
                  uidSet = uidSet.Intersect(new UniqueIdentificationSet(low, high).Invert());
               }
               for (var val = low; val <= high; val++) {
                  AssertFalse(uidSet.Contains(val));
               }
            }
         }
      }