Example #1
0
        public void TestRemoving()
        {
            var prop =
                from it in Prop.ForAll(ArbitraryIntervalTree(0f, 100f, 100f))
                let cnt = it.Count
                          where cnt > 0
                          from index in Prop.ForAll(Gen.ChooseInt(0, cnt))
                          let rem = it.Skip(index).First()
                                    let newCnt = it.Remove(rem)
                                                 let midpoints = (from ival in it
                                                                  select(ival.Low + ival.High) / 2f).AsPrintable()
                                                                 select new { it, cnt, index, rem, newCnt, midpoints };

            prop.Label("Count is correct").Check(p =>
                                                 p.newCnt == p.cnt - 1 && p.newCnt == p.it.Count());
            prop.Label("No overlap above or below").Check(p =>
                                                          p.it.Overlap(-100f, 0f).None() && p.it.Overlap(200f, 300f).None());
            prop.Label("Removed interval not found").Check(p =>
                                                           p.it.All(ival => ival != p.rem));
            prop.Label("Not removed intervals found").Check(p =>
                                                            p.midpoints.All(low => !p.it.Overlap(low, low + 1f).None()));
        }