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 IUniqueIdentificationSet ConvertToUidSet(PartitionBlockInterval[] intervals) {
         var segments = new LinkedList<UniqueIdentificationSet.Segment>();
         foreach (var interval in intervals) {
            segments.AddLast(new UniqueIdentificationSet.Segment { low = interval.StartBlockInclusive, high = interval.EndBlockExclusive - 1 });
         }

         var result = new UniqueIdentificationSet(false);
         result.__Assign(segments);
         return result;
      }
        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());
        }
 public void __HackTest() {
    IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(0, 1000);
    var list = new LinkedList<UniqueIdentificationSet.Segment>();
    list.AddFirst(new UniqueIdentificationSet.Segment { low = 2000, high = 3000 });
    list.AddLast(new UniqueIdentificationSet.Segment { low = 4000, high = 5000 });
    uidSet.__Assign(list);
    list.First.Value.low = 133337; // tests clone rather than reference copy
    uidSet.__Access(x => {
       AssertEquals(2, x.Count);
       AssertEquals(2000U, x.First.Value.low);
       AssertEquals(3000U, x.First.Value.high);
       AssertEquals(4000U, x.Last.Value.low);
       AssertEquals(5000U, x.Last.Value.high);
    });
 }
        public void __HackTest()
        {
            IUniqueIdentificationSet uidSet = new UniqueIdentificationSet(0, 1000);
            var list = new LinkedList <UniqueIdentificationSet.Segment>();

            list.AddFirst(new UniqueIdentificationSet.Segment {
                low = 2000, high = 3000
            });
            list.AddLast(new UniqueIdentificationSet.Segment {
                low = 4000, high = 5000
            });
            uidSet.__Assign(list);
            list.First.Value.low = 133337; // tests clone rather than reference copy
            uidSet.__Access(x => {
                AssertEquals(2, x.Count);
                AssertEquals(2000U, x.First.Value.low);
                AssertEquals(3000U, x.First.Value.high);
                AssertEquals(4000U, x.Last.Value.low);
                AssertEquals(5000U, x.Last.Value.high);
            });
        }
        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 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()); 
      }