ArrayAppendCanonicalTest
Tags:elm-unspecced
`Array.append` of two halves gives an array equal under `==` to `Array.initialize` of the whole, for lengths 32, 64, 96, 128, 160 and 256. The first half holds `0` to `n // 2 - 1` and the second `n // 2` to `n - 1`, so both sides hold the same elements in the same order and each line should log `True`. Lengths 96 and 160 are multiples of 32 that are not powers of two. Tagged `elm-unspecced`: `Array.initialize` and `Array.append` are library functions of `Array`, which A Standard Definition of Elm? puts outside the definition (Appendix C, Library functions). Within the definition an array reaches a program only through a port or its flags, and equality of arrays is checked by `ArrayEqualityFlagsTest`; this test checks that elm/core's arrays compare equal whatever their internal shape.
Results
elm-0.19.1
passran in 47 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. append32: True append64: True append96: True append128: True append160: True append256: True
elm-0.19.2
passran in 45 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. append32: True append64: True append96: True append128: True append160: True append256: True
elm-0.19.3
passran in 60 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. append32: True append64: True append96: True append128: True append160: True append256: True
lamdera-1.5.0
passran in 66 msOutput
append32: True append64: True append96: True append128: True append160: True append256: True
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/ArrayAppendCanonicalTest] in its title.
Source
The -- CHECK: lines give the expected output.
module ArrayAppendCanonicalTest exposing (main)
{-| `Array.append` of two halves gives an array equal under `==` to `Array.initialize` of
the whole, for lengths 32, 64, 96, 128, 160 and 256.
The first half holds `0` to `n // 2 - 1` and the second `n // 2` to `n - 1`, so both sides
hold the same elements in the same order and each line should log `True`. Lengths 96 and 160
are multiples of 32 that are not powers of two.
Tagged `elm-unspecced`: `Array.initialize` and `Array.append` are library functions of `Array`,
which A Standard Definition of Elm? puts outside the definition (Appendix C, Library functions).
Within the definition an array reaches a program only through a port or its flags, and equality
of arrays is checked by `ArrayEqualityFlagsTest`; this test checks that elm/core's arrays compare
equal whatever their internal shape.
-}
-- TAGS: elm-unspecced
-- CHECK: append32: True
-- CHECK: append64: True
-- CHECK: append96: True
-- CHECK: append128: True
-- CHECK: append160: True
-- CHECK: append256: True
import Array
import Html exposing (text)
check : Int -> Bool
check n =
let
half =
n // 2
in
Array.initialize n identity
== Array.append
(Array.initialize half identity)
(Array.initialize half (\i -> i + half))
main =
let
_ = Debug.log "append32" (check 32)
_ = Debug.log "append64" (check 64)
_ = Debug.log "append96" (check 96)
_ = Debug.log "append128" (check 128)
_ = Debug.log "append160" (check 160)
_ = Debug.log "append256" (check 256)
in
text "done"