From 6c22e89b1d07f7977cf05bcc51382c500afb0879 Mon Sep 17 00:00:00 2001 From: Mauricio Scheffer Date: Sat, 3 Oct 2020 22:13:55 +0100 Subject: [PATCH] Minor LINQ improvements (#220) * Test LINQ on Gen * Support LINQ Select for Range * Housekeeping Co-authored-by: Nikos Baxevanis --- src/Hedgehog/LinqSupport.fs | 8 ++++++ tests/Hedgehog.CSharp.Tests/LinqTests.cs | 34 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/Hedgehog/LinqSupport.fs b/src/Hedgehog/LinqSupport.fs index 062c7c07..5e653168 100644 --- a/src/Hedgehog/LinqSupport.fs +++ b/src/Hedgehog/LinqSupport.fs @@ -62,3 +62,11 @@ module PropertyLinqSupport = let bind2Unit (pa : Property<'a>) (f : Func<'a, Property<'b>>) (proj : Action<'a, 'b>) : Property = Property.bind pa (fun a -> Property.bind (f.Invoke a) (fun b -> Property.fromThrowing proj.Invoke (a, b))) + +[] +module RangeLinqSupport = + + [] + [] + let select (r : Range<'a>) (f : Func<'a, 'b>) : Range<'b> = + Range.map (fun x -> f.Invoke x) r diff --git a/tests/Hedgehog.CSharp.Tests/LinqTests.cs b/tests/Hedgehog.CSharp.Tests/LinqTests.cs index a7d4909c..5382bd3a 100644 --- a/tests/Hedgehog.CSharp.Tests/LinqTests.cs +++ b/tests/Hedgehog.CSharp.Tests/LinqTests.cs @@ -104,5 +104,39 @@ from i in ForAll(Gen.Int32(Range.Constant(1, 10))) from j in ForAll(Gen.Int32(Range.Constant(1, i))) select j <= i); } + + [Fact] + public void CanUseSelectWithGen() + { + Gen a = + from i in Gen.Bool + select !i; + } + + [Fact] + public void CanUseWhereWithGen() + { + Gen a = + from i in Gen.Bool + where i + select !i; + } + + [Fact] + public void CanUseSelectManyWithGen() + { + Gen a = + from i in Gen.Bool + from j in Gen.Bool + select !i; + } + + [Fact] + public void CanUseSelectWithRange() + { + Range a = + from i in Range.Constant(1, 10) + select i + 10; + } } }