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); }
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)); }
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); }
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 )); }
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))); }
public void ToArbitrary() { var genInt = Any.OfType <int>(); var arb = genInt.ToArbitrary(); Check.VerboseThrowOnFailure(Prop.forAll(arb, FSharpFunc <int, bool> .FromConverter(i => true))); }
public void GenSuchThatOption() { var genInt = Arb.generate <int>(); var genSuchThatOption = Gen.suchThatOption(FSharpFunc <int, bool> .FromConverter(i => i > 10 && i < 20), genInt); genSuchThatOption.DumpSamples(); }
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); }
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))); }
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)))); }))); }
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); }
}; //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); }
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); }
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()))))); }
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>))); }
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); }
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); }
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); }
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); }
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); }
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(); }
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); }
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); }
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)); }
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); }
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); }
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); }
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); }
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)); }); }
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); }