Elm Exactly
Results / elm-bytes /

RoundtripUnsignedInt32Test

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
Integers survive an `unsignedInt32` encode and decode with elm/bytes in both byte orders.

The values 0 and 0x12345678 are each round-tripped big-endian and then
little-endian, and the program logs `True` only if all four come back unchanged.

Among what is not tested: values at or above 2^31.

Results

elm-0.19.1

passran in 53 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
RoundtripUnsignedInt32Test: True

elm-0.19.2

passran in 51 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
RoundtripUnsignedInt32Test: True

elm-0.19.3

passran in 46 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
RoundtripUnsignedInt32Test: True

lamdera-1.5.0

passran in 49 ms
Output
RoundtripUnsignedInt32Test: True

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-bytes/RoundtripUnsignedInt32Test] in its title.

Source

The -- CHECK: lines give the expected output.

module RoundtripUnsignedInt32Test exposing (main)
{-| Integers survive an `unsignedInt32` encode and decode with elm/bytes in both byte orders.
The values 0 and 0x12345678 are each round-tripped big-endian and then
little-endian, and the program logs `True` only if all four come back unchanged.
Among what is not tested: values at or above 2^31.
-}
-- CHECK: RoundtripUnsignedInt32Test: True
import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
roundtripBE : Int -> Bool
roundtripBE n =
D.decode (D.unsignedInt32 BE) (E.encode (E.unsignedInt32 BE n)) == Just n
roundtripLE : Int -> Bool
roundtripLE n =
D.decode (D.unsignedInt32 LE) (E.encode (E.unsignedInt32 LE n)) == Just n
main =
let
allPass =
roundtripBE 0
&& roundtripBE 0x12345678
&& roundtripLE 0
&& roundtripLE 0x12345678
_ =
Debug.log "RoundtripUnsignedInt32Test" allPass
in
text (if allPass then "True" else "False")