Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void TakeRangeStartTest()
        {
            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.TakeRange(3, 11);
            AssertEquals("[1, 2][12, 15][30, 50][52, 100][150, 200]", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.TakeRange(0, 300);
            AssertEquals("", uidSet.ToString());

            uidSet.__Assign(hardList);
            uidSet.TakeRange(1, 3);
            AssertEquals("[4, 5][12, 15][30, 50][52, 100][150, 200]", uidSet.ToString());

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

            uidSet.__Assign(hardList);
            uidSet.TakeRange(150, 200);
            AssertEquals("[1, 5][12, 15][30, 50][52, 100]", uidSet.ToString());
        }
Ejemplo n.º 4
0
        public IUniqueIdentificationSet Except(IUniqueIdentificationSet removedSetInput)
        {
            var result     = new UniqueIdentificationSet(false).With(x => this.__Access(x.__Assign));
            var removedSet = new UniqueIdentificationSet(false).With(x => removedSetInput.__Access(x.__Assign));

            removedSet.__Access(removedSegments => {
                foreach (var segment in removedSegments)
                {
                    result.TakeRange(segment.low, segment.high);
                }
            });
            return(result);
        }
Ejemplo n.º 5
0
 public IUniqueIdentificationSet Except(IUniqueIdentificationSet removedSetInput) {
    var result = new UniqueIdentificationSet(false).With(x => this.__Access(x.__Assign));
    var removedSet = new UniqueIdentificationSet(false).With(x => removedSetInput.__Access(x.__Assign));
    removedSet.__Access(removedSegments => {
       foreach (var segment in removedSegments) {
          result.TakeRange(segment.low, segment.high);
       }
    });
    return result;
 }
      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 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));
               }
            }
         }
      }
      public void TakeRangeStartTest() {
         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.TakeRange(3, 11);
         AssertEquals("[1, 2][12, 15][30, 50][52, 100][150, 200]", uidSet.ToString());

         uidSet.__Assign(hardList);
         uidSet.TakeRange(0, 300);
         AssertEquals("", uidSet.ToString());
       
         uidSet.__Assign(hardList);
         uidSet.TakeRange(1, 3);
         AssertEquals("[4, 5][12, 15][30, 50][52, 100][150, 200]", uidSet.ToString()); 

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

         uidSet.__Assign(hardList);
         uidSet.TakeRange(150, 200);
         AssertEquals("[1, 5][12, 15][30, 50][52, 100]", uidSet.ToString()); 
      }