Results / elm-random /
RandomIssue21FloatSwappedBoundsTest
Tags:elm19-bug
Issue: elm/random#21
`Random.float` with its bounds swapped generates values outside them. <https://github.com/elm/random/issues/21> `Random.int 100 -100` sorts its bounds and stays within [-100, 100]. Elm 0.19.1 (elm/random 1.0.0) does not do that for `Random.float`: `Random.float 100 -100` produces values in [100, 300]. Values must lie between the two bounds.
Results
elm-0.19.1
failran in 31 msMissing pattern: float within bounds: True --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. int within bounds: True float within bounds: False
elm-0.19.2
failran in 28 msMissing pattern: float within bounds: True --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. int within bounds: True float within bounds: False
elm-0.19.3
failran in 30 msMissing pattern: float within bounds: True --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. int within bounds: True float within bounds: False
lamdera-1.5.0
failran in 31 msMissing pattern: float within bounds: True --- output --- int within bounds: True float within bounds: False
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-random/RandomIssue21FloatSwappedBoundsTest] in its title.
Source
The -- CHECK: lines give the expected output.
module RandomIssue21FloatSwappedBoundsTest exposing (main)
{-| `Random.float` with its bounds swapped generates values outside them.
<https://github.com/elm/random/issues/21>
`Random.int 100 -100` sorts its bounds and stays within [-100, 100]. Elm 0.19.1 (elm/random 1.0.0)
does not do that for `Random.float`: `Random.float 100 -100` produces values in [100, 300].
Values must lie between the two bounds.
-}
-- TAGS: elm19-bug
-- CHECK: int within bounds: True
-- CHECK: float within bounds: True
import Html exposing (text)
import Random
{-| Returns 200 values drawn from `gen`, starting from a fixed seed.
-}
sample : Random.Generator a -> List a
sample gen =
Tuple.first (Random.step (Random.list 200 gen) (Random.initialSeed 42))
main =
let
_ =
Debug.log "int within bounds" (List.all (\x -> x >= -100 && x <= 100) (sample (Random.int 100 -100)))
_ =
Debug.log "float within bounds" (List.all (\x -> x >= -100 && x <= 100) (sample (Random.float 100 -100)))
in
text "done"