Exemplo n.º 1
0
        public void CheckNearestNeighbour <V, T> (Func <V, V, float> distance, string distDesc)
            where V : struct, IVec <V, float>
        {
            var prop =
                from tree in Prop.ForAll(ArbitraryKdTree <V, T> ())
                from pos in Prop.ForAll(Arbitrary.Get <V> ())
                from num in Prop.ForAll(Gen.ChooseInt(1, 4))
                let nearest = tree.NearestNeighbours(pos, num, distance).AsPrintable()
                              let lastBest = nearest.None() ?
                                             float.PositiveInfinity :
                                             distance(nearest.Last().Key, pos)
                                             select new { tree, pos, num, nearest, lastBest };

            prop.Label("Not neighbours have longer distance: {0}, {1}", typeof(V).Name, distDesc)
            .Check(p => p.tree.Count == 0 || p.tree.All(pair =>
                                                        p.nearest.Contains(pair) || p.lastBest <= distance(pair.Key, p.pos)));
            prop.Label("Neighbours in right order: {0}, {1}", typeof(V).Name, distDesc)
            .Check(p => p.nearest.Zip(p.nearest.Skip(1),
                                      (p1, p2) => distance(p1.Key, p.pos) <= distance(p2.Key, p.pos))
                   .All(Fun.Identity));
//			prop.Label ("Visualize").Check (p =>
//			{
//				TestProgram.VConsole.ShowVisual (p.tree.ToVisual ());
//				return true;
//			});
        }
Exemplo n.º 2
0
        public static Arbitrary <Q> ArbitraryQuat <Q, T> ()
            where Q : struct, IQuat <Q, T>
            where T : struct, IEquatable <T>
        {
            var arb  = Arbitrary.Get <T> ();
            var quat = default(Q);

            return(new Arbitrary <Q> (
                       from a in arb.Generate.FixedArrayOf(4)
                       select quat.FromAxisAngle(a[0], a[1], a[2], a[3])));
        }
Exemplo n.º 3
0
        public static Arbitrary <V> ArbitraryVec <V, T> (int size)
            where V : struct, IVec <V, T>
            where T : struct, IEquatable <T>
        {
            var arb = Arbitrary.Get <T> ();

            return(new Arbitrary <V> (
                       from a in arb.Generate.FixedArrayOf(size)
                       select Vec.FromArray <V, T> (a),
                       v => from a in v.ToArray <V, T> ().Map(arb.Shrink).Combinations()
                       select Vec.FromArray <V, T> (a)));
        }
Exemplo n.º 4
0
        public static Arbitrary <M> ArbitraryMat <M, T> (int cols, int rows)
            where M : struct, IMat <M, T>
            where T : struct, IEquatable <T>
        {
            var arb = Arbitrary.Get <T> ();

            return(new Arbitrary <M> (
                       from a in arb.Generate.FixedArrayOf(rows * cols)
                       select Mat.FromArray <M, T> (a),
                       m => from a in Mat.ToArray <M, T> (m).Map(arb.Shrink).Combinations()
                       select Mat.FromArray <M, T> (a)));
        }
Exemplo n.º 5
0
        public static Arbitrary <KdTree <V, T> > ArbitraryKdTree <V, T> ()
            where V : struct, IVec <V, float>
        {
            var arb = Arbitrary.Get <KeyValuePair <V, T> > ();

            return(new Arbitrary <KdTree <V, T> > (
                       from pairs in arb.Generate.EnumerableOf()
                       select new KdTree <V, T> (pairs),
                       tree =>
                       from pairs in tree.ShrinkEnumerable()
                       select new KdTree <V, T> (pairs)));
        }
Exemplo n.º 6
0
        public static Arbitrary <KeyValuePair <K, V> > ArbitraryKeyValuePair <K, V> ()
        {
            var arbKey   = Arbitrary.Get <K> ();
            var arbValue = Arbitrary.Get <V> ();

            return(new Arbitrary <KeyValuePair <K, V> > (
                       from key in arbKey.Generate
                       from value in arbValue.Generate
                       select new KeyValuePair <K, V> (key, value),
                       pair =>
                       from key in arbKey.Shrink(pair.Key)
                       select new KeyValuePair <K, V> (key, pair.Value)));
        }
Exemplo n.º 7
0
        public static Arbitrary <Aabb <V> > ArbitraryAabb <V> ()
            where V : struct, IVec <V, float>
        {
            var arb = Arbitrary.Get <V> ();

            return(new Arbitrary <Aabb <V> > (
                       from pos1 in arb.Generate
                       from pos2 in arb.Generate
                       select new Aabb <V> (pos1, pos2),
                       bbox =>
                       from min in arb.Shrink(bbox.Min)
                       from max in arb.Shrink(bbox.Max)
                       select new Aabb <V> (min, max)));
        }
Exemplo n.º 8
0
        public void CheckAdding <V, T> ()
            where V : struct, IVec <V, float>
        {
            var prop =
                from tree in Prop.ForAll(ArbitraryKdTree <V, T> ())
                let cnt = tree.Count
                          from key in Prop.ForAll(Arbitrary.Get <V> ().Generate)
                          from val in Prop.ForAll(Arbitrary.Get <T> ().Generate)
                          let added = tree.TryAdd(key, val)
                                      select new { tree, cnt, key, val, added };

            prop.Label("Count is correct").Check(p => !p.added || p.cnt + 1 == p.tree.Count());
            prop.Label("New value added").Check(p => !p.added || p.tree[p.key].Equals(p.val));
        }