コード例 #1
0
ファイル: DefaultArbitrary.cs プロジェクト: johtela/Compose3D
        internal static void Register()
        {
            Arbitrary.Register(new Arbitrary <char> (
                                   Gen.Elements(CharCandidates().ToArray()),
                                   ShrinkChar));

            Arbitrary.Register(new Arbitrary <int> (
                                   Gen.ChooseInt(),
                                   x => ShrinkInteger(x).Distinct()));

            Arbitrary.Register(new Arbitrary <long> (
                                   Gen.ChooseInt().ToLong(),
                                   x => ShrinkInteger((int)x).Distinct().Select(i => (long)i)));

            Arbitrary.Register(new Arbitrary <float> (
                                   Gen.ChooseDouble().ToFloat(),
                                   x => ShrinkDouble(x).Select(d => (float)d)));

            Arbitrary.Register(new Arbitrary <double> (
                                   Gen.ChooseDouble(),
                                   ShrinkDouble));

            Arbitrary.Register(new Arbitrary <string> (
                                   from a in Arbitrary.Gen <char> ().ArrayOf()
                                   select new string (a),
                                   x => ShrinkEnumerable(x).Select(cs => new string (cs.ToArray()))));

            Arbitrary.Register(typeof(Enumerable <>));
            Arbitrary.Register(typeof(Array <>));
            Arbitrary.Register(typeof(AList <>));
        }
コード例 #2
0
ファイル: DefaultArbitrary.cs プロジェクト: johtela/LinqCheck
        /*
        ## Registering Default Arbitrary Types
        ## All of the default arbitrary types are registered automatically in the
        ## static constructor. Most of these types rely on the helper methods,
        ## which are introduced below. We will discuss the details of each type
        ## in context of the helper methods.
        */
        internal static void Register()
        {
            /*
             ### Character Type
             ###Characters are randomly selected from a predefined set. This
             ###produces simpler and more readable characters than randomly
             ###generating ASCII codes.
             */
            Arbitrary.Register(new Arbitrary <char> (
                                   Gen.ChooseFrom(CharCandidates().ToArray()),
                                   ShrinkChar));

            /*
             ### Integral Types
             ###Integral types `int` and `long` use the same helpers to generate
             ###and shrink the values. The maximum number generated depends on the
             ###size parameter used by the generators.
             */
            Arbitrary.Register(new Arbitrary <int> (
                                   Gen.ChooseInt(),
                                   x => ShrinkInteger(x).Distinct()));

            Arbitrary.Register(new Arbitrary <long> (
                                   Gen.ChooseInt().ToLong(),
                                   x => ShrinkInteger((int)x).Distinct().Select(i => (long)i)));

            /*
             ### Floating Point Types
             ###`float` and `double` types are generated and shrunk with the same
             ###methods. The results are casted to lower precision when necessary.
             */
            Arbitrary.Register(new Arbitrary <float> (
                                   Gen.ChooseDouble().ToFloat(),
                                   x => ShrinkDouble(x).Select(d => (float)d)));

            Arbitrary.Register(new Arbitrary <double> (
                                   Gen.ChooseDouble(),
                                   ShrinkDouble));

            /*
             ### Strings
             ###Strings are arrays of characters, so they can be composed from
             ###arbitrary characters with appropriate combinators.
             */
            Arbitrary.Register(new Arbitrary <string> (
                                   from a in Arbitrary.Gen <char> ().ArrayOf()
                                   select new string (a),
                                   x => ShrinkEnumerable(x).Select(cs => new string (cs.ToArray()))));

            /*
             ### Collection Types
             ###The arbitrary implementations for collections are generic.
             ###Therefore, they work with any item type. Their implementation is
             ###discussed below.
             */
            Arbitrary.Register(typeof(Enumerable <>));
            Arbitrary.Register(typeof(Array <>));
            Arbitrary.Register(typeof(AList <>));
        }