Exemplo n.º 1
0
        public void IntersectTest()
        {
            var setA = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList <UniqueIdentificationSet.Segment>().With(x => {
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 1, high = 5
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 10, high = 16
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 18, high = 22
                });
            })));
            var setB = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList <UniqueIdentificationSet.Segment>().With(x => {
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 1, high = 2
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 4, high = 6
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 9, high = 12
                });
                x.AddLast(new UniqueIdentificationSet.Segment {
                    low = 15, high = 20
                });
            })));

            AssertEquals("[1, 2][4, 5][10, 12][15, 16][18, 20]", setA.Intersect(setB).ToString());
        }
Exemplo 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));
                    }
                }
            }
        }
      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 IntersectTest() {
    var setA = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList<UniqueIdentificationSet.Segment>().With(x => {
       x.AddLast(new UniqueIdentificationSet.Segment { low = 1, high = 5 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 10, high = 16 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 18, high = 22 });
    })));
    var setB = new UniqueIdentificationSet(false).With(set => set.__Assign(new LinkedList<UniqueIdentificationSet.Segment>().With(x => {
       x.AddLast(new UniqueIdentificationSet.Segment { low = 1, high = 2 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 4, high = 6 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 9, high = 12 });
       x.AddLast(new UniqueIdentificationSet.Segment { low = 15, high = 20 });
    })));
    AssertEquals("[1, 2][4, 5][10, 12][15, 16][18, 20]", setA.Intersect(setB).ToString());
 }