File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed
Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -66,18 +66,19 @@ module Shrink =
6666
6767 /// Shrink an integral number by edging towards a destination.
6868 let inline towards ( destination : ^a ) ( x : ^a ) : seq < 'a > =
69- let one : ^a = LanguagePrimitives.GenericOne
70- let two : ^a = one + one
7169 if destination = x then
7270 Seq.empty
73- elif destination = x - one then
74- Seq.singleton destination
7571 else
72+ let one : ^a = LanguagePrimitives.GenericOne
73+ let two : ^a = one + one
74+
7675 /// We need to halve our operands before subtracting them as they may be using
7776 /// the full range of the type (i.e. 'MinValue' and 'MaxValue' for 'Int32')
7877 let diff : ^a = ( x / two) - ( destination / two)
78+
7979 halves diff
8080 |> Seq.map ( fun y -> x - y)
81+ |> Seq.consNub destination
8182
8283 /// Shrink a floating-point number by edging towards a destination.
8384 /// Note we always try the destination first, as that is the optimal shrink.
Original file line number Diff line number Diff line change @@ -73,19 +73,19 @@ let shrinkTests = testList "Shrink tests" [
7373 let actual =
7474 Shrink.towards 0 100
7575 |> Seq.toList
76- [ 50 ; 75 ; 88 ; 94 ; 97 ; 99 ] =! actual
76+ [ 0 ; 50 ; 75 ; 88 ; 94 ; 97 ; 99 ] =! actual
7777
7878 testCase " towards correct on input 500, 1000" <| fun _ ->
7979 let actual =
8080 Shrink.towards 500 1000
8181 |> Seq.toList
82- [ 750 ; 875 ; 938 ; 969 ; 985 ; 993 ; 997 ; 999 ] =! actual
82+ [ 500 ; 750 ; 875 ; 938 ; 969 ; 985 ; 993 ; 997 ; 999 ] =! actual
8383
8484 testCase " towards correct on input -50, -26" <| fun _ ->
8585 let actual =
8686 Shrink.towards - 50 - 26
8787 |> Seq.toList
88- [- 38 ; - 32 ; - 29 ; - 27 ] =! actual
88+ [- 50 ; - 38 ; - 32 ; - 29 ; - 27 ] =! actual
8989
9090 testCase " towards correct on input 4, 5" <| fun _ ->
9191 let actual =
You can’t perform that action at this time.
0 commit comments