Exemplo n.º 1
0
        public static void Run()
        {
            PBTHelpers.Check((Func <int[], bool>)GenericTests.Prop_SelectIdentity, 7);

            PBTHelpers.Check(Prop_UnspecSumEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecSumSquaresEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecSumOddEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecSumSquaredOddEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecSumOddSquaresEqualIntArray, 7);

            PBTHelpers.Check(Prop_UnspecAverageEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecCountSquaresEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecCountOddEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecCountSquaredOddEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecCountOddSquaresEqualIntArray, 7);

            PBTHelpers.Check(Prop_UnspecAverageEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecAverageSquaresEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecAverageOddEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecAverageSquaredOddEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecAverageOddSquaresEqualIntArray, 7);

            PBTHelpers.Check(Prop_UnspecCartesianProductsEqualIntArray, 7);
            PBTHelpers.Check(Prop_UnspecCartesianMultiplicationEqualIntArray, 5);

            // TODO: move elsewhere
            PBTHelpers.Check(Prop_Range_Sum, 20);
            PBTHelpers.Check(Prop_Range_Count, 20);

            PBTHelpers.Check(Prop_PythagoreanTriples_Sum, 20);
            PBTHelpers.Check(Prop_PythagoreanTriples_Count, 20);
        }
Exemplo n.º 2
0
        public static void Run()
        {
            PBTHelpers.Check((Func <int[], bool>)GenericTests.Prop_SelectIdentity, 7);

            PBTHelpers.Check(Prop_SumEqualIntArray, 7);
            PBTHelpers.Check(Prop_SumSquaresEqualIntArray, 7);
            PBTHelpers.Check(Prop_SumOddEqualIntArray, 7);
            PBTHelpers.Check(Prop_SumSquaredOddEqualIntArray, 7);
            PBTHelpers.Check(Prop_SumOddSquaresEqualIntArray, 7);

            PBTHelpers.Check(Prop_AverageEqualIntArray, 7);
            PBTHelpers.Check(Prop_CountSquaresEqualIntArray, 7);
            PBTHelpers.Check(Prop_CountOddEqualIntArray, 7);
            PBTHelpers.Check(Prop_CountSquaredOddEqualIntArray, 7);
            PBTHelpers.Check(Prop_CountOddSquaresEqualIntArray, 7);

            PBTHelpers.Check(Prop_AverageEqualIntArray, 7);
            PBTHelpers.Check(Prop_AverageSquaresEqualIntArray, 7);
            PBTHelpers.Check(Prop_AverageOddEqualIntArray, 7);
            PBTHelpers.Check(Prop_AverageSquaredOddEqualIntArray, 7);
            PBTHelpers.Check(Prop_AverageOddSquaresEqualIntArray, 7);

            PBTHelpers.Check(Prop_CartesianProductsEqualIntArray, 7);
            PBTHelpers.Check(Prop_CartesianMultiplicationEqualIntArray, 5);
        }
Exemplo n.º 3
0
 private static Imp <bool, Func <bool> > Prop_PythagoreanTriples_Count(int max)
 => PBTHelpers.Implies(
     0 < max,
     (Func <bool>)(() =>
 {
     var lcount =
         Enumerable.Count(
             Enumerable.Select(
                 Enumerable.Where(
                     Enumerable.SelectMany(
                         Enumerable.SelectMany(
                             Enumerable.Range(1, max + 1),
                             a => Enumerable.Range(a, max + 1 - a),
                             (a, b) => new { a, b }),
                         z => Enumerable.Range(z.b, max + 1 - z.b),
                         (z, c) => new { z, c }),
                     y => y.z.a * y.z.a + y.z.b * y.z.b == y.c * y.c),
                 y => true));
     var tlcount =
         (from a in new Range <int> {
         start = 1, count = max + 1
     }
          from b in new Range <int> {
         start = a, count = max + 1 - a
     }
          from c in new Range <int> {
         start = b, count = max + 1 - b
     }
          where a * a + b * b == c * c
          select true).Count();
     return(lcount == tlcount);
 }
                   ));
Exemplo n.º 4
0
 private static Imp <bool, Func <bool> > Prop_Range_Count(int start, int count)
 => PBTHelpers.Implies(
     0 < count,
     (Func <bool>)(() =>
 {
     var lcount = Enumerable.Count(Enumerable.Range(start, count));
     var rcount = new Range <int> {
         start = start, count = count
     }.Count();
     return(lcount == rcount);
 }
                   ));
Exemplo n.º 5
0
 public static Imp <bool, Func <bool> > PythagoreanTinyLinq(int max) =>
 PBTHelpers.Implies(
     0 < max,
     (Func <bool>)(() => {
     var lcount = LinqOracles.PythagoreanTripleCount(max);
     var tcount =
         (from a in System.Linq.Enumerable.Range(1, max + 1)
          from b in System.Linq.Enumerable.Range(a, max + 1 - a)
          from c in System.Linq.Enumerable.Range(b, max + 1 - b)
          where a * a + b * b == c * c
          select true).Count();
     return(lcount == tcount);
 }));
Exemplo n.º 6
0
        /// <summary>
        /// LINQ and TinyLINQ agree on the average of all odd squares
        /// of an array.
        /// </summary>
        /// <param name="toAverage">The array to test against.</param>
        /// <returns>Whether LINQ and TinyLINQ agree.</returns>

        private static Imp <bool, Func <bool> > Prop_UnspecAverageOddSquaresEqualIntArray(int[] toAverage)
        => PBTHelpers.Implies(
            0 < Enumerable.Count(toAverage.Select <int, int>(x => x * x).Where <int>(x => x % 2 == 1)),
            (Func <bool>)(() => Enumerable.Average(toAverage.Select <int, int>(x => x * x).Where <int>(x => x % 2 == 1)) ==
                          toAverage.Select(x => x * x).Where(x => x % 2 == 1).Average()));
Exemplo n.º 7
0
        /// <summary>
        /// LINQ and TinyLINQ agree on the average of all odd numbers of an array.
        /// </summary>
        /// <param name="toAverage">The array to test against.</param>
        /// <returns>Whether LINQ and TinyLINQ agree.</returns>

        private static Imp <bool, Func <bool> > Prop_UnspecAverageOddEqualIntArray(int[] toAverage)
        => PBTHelpers.Implies(
            0 < toAverage.Where <int>(x => x % 2 == 1).Count(),
            (Func <bool>)(() => Enumerable.Average(toAverage.Where <int>(x => x % 2 == 1)) ==
                          toAverage.Where(x => x % 2 == 1).Average()));
Exemplo n.º 8
0
        /// <summary>
        /// LINQ and TinyLINQ agree on the average of all squares of an array.
        /// </summary>
        /// <param name="toAverage">The array to test against.</param>
        /// <returns>Whether LINQ and TinyLINQ agree.</returns>

        private static Imp <bool, Func <bool> > Prop_UnspecAverageSquaresEqualIntArray(int[] toAverage)
        => PBTHelpers.Implies(
            0 < toAverage.Length,
            (Func <bool>)(() => Enumerable.Average(toAverage.Select <int, int>(x => x * x)) == toAverage.Select(x => x * x).Average()));
Exemplo n.º 9
0
 /// <summary>
 /// LINQ and TinyLINQ agree on the average of an array.
 /// </summary>
 /// <param name="toCount">The array to test against.</param>
 /// <returns>Whether LINQ and TinyLINQ agree.</returns>
 private static Imp <bool, Func <bool> > Prop_UnspecAverageEqualIntArray(int[] toAverage)
 => PBTHelpers.Implies(
     0 < toAverage.Length,
     (Func <bool>)(() => Enumerable.Average(toAverage) == toAverage.Average()));
Exemplo n.º 10
0
 public static void Run()
 {
     PBTHelpers.Check(PythagoreanTinyLinq, 10);
     PBTHelpers.Check((Func <Range <int>, bool>)GenericTests.Prop_SelectIdentity, 7);
 }