public static Gen <Interval <float, int> > GenInterval(float minRange, float maxRange, float maxLen) { return(from start in Gen.ChooseDouble(minRange, maxRange).ToFloat() from len in Gen.ChooseDouble(1, maxLen).ToFloat() from data in Gen.ChooseInt(0, int.MaxValue) select new Interval <float, int> (start, start + len, data)); }
public void TestGapsNotOverlap() { var prop = from it in Prop.ForAll(ArbitraryIntervalTree(0f, 100f, 100f)) from low in Prop.ForAll(Gen.ChooseDouble(0.0, 100.0).ToFloat()) select new { it, low }; prop.Label("No tree overlap => None of the intervals overlap").Check( p => p.it.Overlap(p.low, p.low + 1).None().Implies( p.it.All(ival => !ival.Overlap(p.low, p.low + 1)))); }
public void CheckLerping <Q> (Func <Q, Q, float, Q> lerpFunc) where Q : struct, IQuat <Q, float> { (from quat1 in Prop.ForAll <Q> () from quat2 in Prop.ForAll <Q> () from alpha in Prop.Any(Gen.ChooseDouble(0.0, 1.0).ToFloat()) let lerp = lerpFunc(quat1, quat2, alpha) let len = lerp.Length select new { quat1, quat2, alpha, lerp, len }) .Check(p => p.lerp.IsNormalized, label: $"{typeof (Q).Name}: | lerp (quat1, quat2) | = 1"); }
public void CheckLerping <Q> (Func <Q, Q, float, Q> lerpFunc) where Q : struct, IQuat <Q, float> { var prop = from quat1 in Prop.Choose <Q> () from quat2 in Prop.Choose <Q> () from alpha in Prop.ForAll(Gen.ChooseDouble(0.0, 1.0).ToFloat()) let lerp = lerpFunc(quat1, quat2, alpha) let len = lerp.Length select new { quat1, quat2, alpha, lerp, len }; prop.Label("{0}: | lerp (quat1, quat2) | = 1", typeof(Q).Name) .Check(p => p.lerp.IsNormalized); }
public void TestAdding() { var prop = from it in Prop.ForAll(ArbitraryIntervalTree(0f, 100f, 100f)) let cnt = it.Count from low in Prop.ForAll(Gen.ChooseDouble(200.0).ToFloat()) from len in Prop.ForAll(Gen.ChooseDouble(1.0, 100.0).ToFloat()) let high = low + len let ival = it.Add(low, high, 0) select new { it, cnt, low, high, ival }; prop.Label("Count is correct").Check(p => p.cnt + 1 == p.it.Count()); prop.Label("New range added").Check(p => p.it.Overlap(200f, 300f).Single() == p.ival); prop.Label("No overlap above or below").Check( p => p.it.Overlap(-100f, 0f).None() && p.it.Overlap(400f, 500f).None()); prop.Label("Visualize").Check(p => { TestProgram.VConsole.ShowVisual(p.it.ToVisual()); return(true); }); }