コード例 #1
0
        public Task ExecuteAsync(
            ControllerActionDescriptor action,
            Utf8JsonWriter writer,
            JsonSerializerOptions options)
        {
            var namingPolicy = options.PropertyNamingPolicy;

            writer.WriteStartObject();
            writer.WriteString(namingPolicy.ConvertName("type"), "object");
            writer.WriteStartObject(namingPolicy.ConvertName("properties"));

            writer.WriteStartObject(namingPolicy.ConvertName("api"));
            writer.WriteString(namingPolicy.ConvertName("type"), "object");
            writer.WriteStartObject(namingPolicy.ConvertName("properties"));
            writer.WriteStartObject(namingPolicy.ConvertName("title"));
            writer.WriteString(namingPolicy.ConvertName("type"), "string");
            writer.WriteEndObject();
            writer.WriteEndObject();
            writer.WriteEndObject();

            writer.WriteStartObject(namingPolicy.ConvertName("resources"));
            writer.WriteString(namingPolicy.ConvertName("type"), "object");
            writer.WriteBoolean(namingPolicy.ConvertName("additionalProperties"), false);
            writer.WriteEndObject();
            writer.WriteEndObject();

            var returnType = action.MethodInfo.GetCustomAttribute <ReturnsAttribute>()?.ReturnType ?? typeof(object);
            var links      = Links.ForType(FSharpFunc <Type, InputJsonSchema> .FromConverter(SchemaGenerator.getInputSchema), returnType);

            SchemaSerializer.writeLinks(links).Invoke(Tuple.Create(writer, options));

            writer.WriteEndObject();

            return(Task.CompletedTask);
        }
コード例 #2
0
        public static FSharpFunc <T1, FSharpFunc <T2, TResult> > Create <T1, T2, TResult>(Func <T1, T2, TResult> func)
        {
            Converter <T1, FSharpFunc <T2, TResult> > conv =
                value1 => { return(Create <T2, TResult>(value2 => func(value1, value2))); };

            return(FSharpFunc <T1, FSharpFunc <T2, TResult> > .FromConverter(conv));
        }
コード例 #3
0
        public static TimeWarpStateCalculator GetTimeWarpStateCalculator()
        {
            Func <TimeWarpState, TimeSpan> csFunc = i =>
            {
                switch (i)
                {
                case (TimeWarpState.None):
                    return(TimeSpan.Zero);

                case (TimeWarpState.Resting):
                    return(TimeSpan.FromMilliseconds(100));

                case (TimeWarpState.Working):
                    return(TimeSpan.FromMilliseconds(200));

                default:
                    throw new InvalidEnumArgumentException("i", (int)i, typeof(TimeWarpState));
                }
            };


            var fsharpFunc = FSharpFunc <TimeWarpState, TimeSpan> .FromConverter(
                new Converter <TimeWarpState, TimeSpan>(csFunc));

            var timeWarpStateCalculator = new TimeWarpStateCalculator(fsharpFunc);

            return(timeWarpStateCalculator);
        }
コード例 #4
0
 public static FSharpOption <T2> Map <T1, T2>(this FSharpOption <T1> opt, Func <T1, T2> f)
 {
     return(OptionModule.Map(
                FSharpFunc <T1, T2> .FromConverter(a => f(a)),
                opt
                ));
 }
コード例 #5
0
        public void Filter()
        {
            var arbInt      = Arb.Default.Int32();
            var arbFiltered = Arb.filter(FSharpFunc <int, bool> .FromConverter(i => i > 10 && i < 20), arbInt);

            Check.VerboseThrowOnFailure(Prop.forAll(arbFiltered, FSharpFunc <int, bool> .FromConverter(i => true)));
        }
コード例 #6
0
        public void ToArbitrary()
        {
            var genInt = Any.OfType <int>();
            var arb    = genInt.ToArbitrary();

            Check.VerboseThrowOnFailure(Prop.forAll(arb, FSharpFunc <int, bool> .FromConverter(i => true)));
        }
コード例 #7
0
        public void GenSuchThatOption()
        {
            var genInt            = Arb.generate <int>();
            var genSuchThatOption = Gen.suchThatOption(FSharpFunc <int, bool> .FromConverter(i => i > 10 && i < 20), genInt);

            genSuchThatOption.DumpSamples();
        }
コード例 #8
0
        public void GenSized()
        {
            var genInt   = Arb.generate <int>();
            var genSized = Gen.sized(FSharpFunc <int, Gen <int[]> > .FromConverter(size => Gen.arrayOfLength(size, genInt)));

            genSized.DumpSamples(Formatters.FormatCollection);
        }
コード例 #9
0
ファイル: DocTest.cs プロジェクト: mohammedovich/FsCheck
            public static Arbitrary <Doc> Doc()
            {
                //TODO: add Gen.sized which accepts Func<int, Gen<T>> - ??
                var func = FSharpFunc <int, Gen <Doc> > .FromConverter(new Converter <int, Gen <Doc> >(DocGenenerator.Generator));

                return(Arb.fromGen(Gen.sized(func)));
            }
コード例 #10
0
 public void Test()
 {
     Check.QuickThrowOnFailure(Prop.forAll(Arb.from <int>(), FSharpFunc <int, Property> .FromConverter(n =>
     {
         return(Prop.throws <DivideByZeroException, int>(new Lazy <int>(() => n / (n - n))));
     })));
 }
コード例 #11
0
        public void Test()
        {
            var g        = Gen.choose(-2, 5);
            var property = Prop.forAll(Arb.fromGen(g), FSharpFunc <int, bool> .FromConverter(n => n >= -2 && n <= 5));

            Check.One(Config, property);
        }
コード例 #12
0
        }; //TODO


        public static bool Execute(out Types.Transaction transaction, ContractArgs contractArgs, bool isWitness)
        {
            try
            {
                var fileName     = HttpServerUtility.UrlTokenEncode(contractArgs.ContractHash);
                var contractCode = File.ReadAllText(Path.Combine(_OutputPath, Path.ChangeExtension(fileName, ".fs")));
                var func         = ContractExamples.Execution.compileQuotedContract(contractCode);

                var result = func.Invoke(new Tuple <byte[], byte[], FSharpFunc <Types.Outpoint, FSharpOption <Types.Output> > >(
                                             contractArgs.Message,
                                             contractArgs.ContractHash,
                                             FSharpFunc <Types.Outpoint, FSharpOption <Types.Output> > .FromConverter(t => contractArgs.tryFindUTXOFunc(t))));

                var txSkeleton = result as Tuple <FSharpList <Types.Outpoint>, FSharpList <Types.Output>, byte[]>;

                transaction = txSkeleton == null || txSkeleton.Item2.Count() == 0 ? null :
                              new Types.Transaction(
                    Tests.tx.version,
                    txSkeleton.Item1,
                    ListModule.OfSeq <byte[]>(isWitness ? new byte[][] { contractArgs.Message } : new byte[][] { }),
                    txSkeleton.Item2,
                    FSharpOption <Types.ExtendedContract> .None                           //TODO: get from txSkeleton.Item3
                    );

                return(true);
            }
            catch (Exception e)
            {
                BlockChainTrace.Error("Error executing contract", e);
            }

            transaction = null;

            return(false);
        }
コード例 #13
0
        public void FrequencyTest()
        {
            var evenNumbersGen = from n in Gen.choose(2, 100000) select 2 * n;
            var oddNumbersGen  = from n in Gen.choose(0, 100000) select 2 * n + 1;
            var numberGen      = Gen.frequency(new[]
            {
                Tuple.Create(1, oddNumbersGen),
                Tuple.Create(2, evenNumbersGen),
                Tuple.Create(4, Gen.constant(0))
            });

            var property = Prop.forAll(Arb.fromGen(numberGen), FSharpFunc <int, Property> .FromConverter(n =>
            {
                string l;
                if (n == 0)
                {
                    l = "one";
                }
                else if (n % 2 == 0)
                {
                    l = "even";
                }
                else
                {
                    l = "odd";
                }
                return(Prop.collect <string, bool>(l).Invoke(true));
            }));

            Check.One(Config, property);
            Check.One(Config.WithMaxTest(1000), property);
            Check.One(Config.WithMaxTest(10000), property);
        }
コード例 #14
0
ファイル: Converters.cs プロジェクト: Sean-Nguyen/Dynamo
 internal static FScheme.Value convertPyFunction(Func <IList <dynamic>, dynamic> pyf)
 {
     return(FScheme.Value.NewFunction(
                FSharpFunc <FSharpList <FScheme.Value>, FScheme.Value> .FromConverter(
                    args =>
                    convertToValue(
                        pyf(args.Select(ex => convertFromValue(ex)).ToList())))));
 }
コード例 #15
0
 private static Gen <Tree <T> > GenNode <T>(Gen <T> genT)
 {
     return(Gen.sized(FSharpFunc <int, Gen <Tree <T> > > .FromConverter(size =>
                                                                        from s in Gen.choose(0, size)
                                                                        let g = Gen.resize(size / (s + 1), GenTree(genT))
                                                                                from children in g.MakeListOfLength(s)
                                                                                select new Node <T>(children) as Tree <T>)));
 }
コード例 #16
0
 public void Where()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var x = xs.AsCloudFlow().Where(i => i % 2 == 0).ToArray();
         var y = xs.AsParallel().Where(i => i % 2 == 0).ToArray();
         return(this.Run(x).SequenceEqual(y));
     }).QuickThrowOnFail(this.MaxNumberOfTests);
 }
コード例 #17
0
 public void Count()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var x = CloudFlow.OfArray(xs).Where(v => v % 2 == 0).Count();
         var y = xs.Where(v => v % 2 == 0).Count();
         return(this.Run(x) == y);
     }).QuickThrowOnFail(this.FsCheckMaxNumberOfTests, shrink: false);
 }
コード例 #18
0
 public void OfArray()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var x = xs.AsCloudFlow().Select(i => i + 1).ToArray();
         var y = xs.Select(i => i + 1).ToArray();
         return(this.Run(x).SequenceEqual(y));
     }).QuickThrowOnFail(this.MaxNumberOfTests);
 }
コード例 #19
0
 public void Count()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var x = xs.AsCloudFlow().Select(i => i + 1).Count();
         var y = xs.AsParallel().Select(i => i + 1).Count();
         return(this.Run(x) == y);
     }).QuickThrowOnFail(this.MaxNumberOfTests);
 }
コード例 #20
0
 public void SelectMany()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var x = xs.AsCloudFlow().SelectMany <int, int>(i => xs.AsStream()).ToArray();
         var y = xs.AsParallel().SelectMany(i => xs).ToArray();
         return(this.Run(x).SequenceEqual(y));
     }).QuickThrowOnFail(this.MaxNumberOfTests);
 }
コード例 #21
0
        public void OpLessBangGreater()
        {
            var genPositiveInt = Arb.Default.PositiveInt().Generator;
            var func           = FSharpFunc <PositiveInt, string> .FromConverter(pi => new string('X', pi.Get));

            var genString = GenOperators.op_LessBangGreater(func, genPositiveInt);

            genString.DumpSamples();
        }
コード例 #22
0
 public void Sum()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var x = CloudFlow.OfArray(xs).Select(v => v * 2).Sum();
         var y = xs.Select(v => v * 2).Sum();
         return(this.Run(x) == y);
     }).QuickThrowOnFail(this.FsCheckMaxNumberOfTests, shrink: false);
 }
コード例 #23
0
 public void Aggregate()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var x = xs.AsCloudFlow().Select(i => i + 1).Aggregate(() => 0, (acc, i) => acc + i, (left, right) => left + right);
         var y = xs.AsParallel().Select(i => i + 1).Aggregate(() => 0, (acc, i) => acc + i, (left, right) => left + right, i => i);
         return(this.Run(x) == y);
     }).QuickThrowOnFail(this.MaxNumberOfTests);
 }
コード例 #24
0
        public static FSharpFunc <T1, TResult> ToFSharpFunc <T1, TResult>(this Func <T1, TResult> func)
        {
            Converter <T1, TResult> conv = value1 =>
            {
                return(func(value1));
            };

            return(FSharpFunc <T1, TResult> .FromConverter(conv));
        }
コード例 #25
0
 public void AnonymousType()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var x = xs.AsCloudFlow().Select(i => new { Value = i }).ToArray();
         var y = xs.AsParallel().Select(i => new { Value = i }).ToArray();
         return(this.Run(x).SequenceEqual(y));
     }).QuickThrowOnFail(this.MaxNumberOfTests);
 }
コード例 #26
0
 public void OfArray_ToArray()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var x = CloudFlow.OfArray(xs).ToArray();
         var y = xs.ToArray();
         return(this.Run(x).SequenceEqual(y));
     }).QuickThrowOnFail(this.FsCheckMaxNumberOfTests, shrink: false);
 }
コード例 #27
0
 public void CountBy()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var x = CloudFlow.OfArray(xs).CountBy(v => v).ToArray();
         var y = xs.GroupBy(v => v).Select(v => Tuple.Create(v.Key, (long)v.Count())).ToArray();
         return(new HashSet <Tuple <int, long> >(this.Run(x)).SetEquals(new HashSet <Tuple <int, long> >(y)));
     }).QuickThrowOnFail(this.FsCheckMaxNumberOfTests, shrink: false);
 }
コード例 #28
0
 public void SelectMany()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var x = CloudFlow.OfArray(xs).SelectMany(v => Enumerable.Range(1, 1000)).ToArray();
         var y = xs.SelectMany(v => Enumerable.Range(1, 1000)).ToArray();
         return(this.Run(x).SequenceEqual(y));
     }).QuickThrowOnFail(this.FsCheckMaxNumberOfTests, shrink: false);
 }
コード例 #29
0
 public void Distinct()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var expected = xs.Distinct();
         var actual   = this.Run(CloudFlow.OfArray(xs).Distinct().ToArray());
         return(actual.SequenceEqual(expected));
     });
 }
コード例 #30
0
 public void Aggregate()
 {
     FSharpFunc <int[], bool> .FromConverter(xs =>
     {
         var x = CloudFlow.OfArray(xs).Select(v => v * 2).Aggregate(() => 0, (acc, v) => acc + v, (l, r) => l + r);
         var y = xs.Select(v => v * 2).Aggregate(0, (acc, v) => acc + v);
         return(this.Run(x) == y);
     }).QuickThrowOnFail(this.FsCheckMaxNumberOfTests, shrink: false);
 }