MaybeSelectListTests.elm 3.82 KB
Newer Older
1 2 3 4 5
module MaybeSelectListTests exposing (..)

import Expect exposing (Expectation)
import Fuzz exposing (Fuzzer, int, intRange, list, string)
import Test exposing (..)
6
import Common.MaybeSelectList exposing (..)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95


-- FUZZERS --
-- TESTS --


afterTests : Test
afterTests =
    describe "after"
        [ fuzz (list int) "must return an empty list when nothing is selected" <|
            \lst ->
                after (fromList lst)
                    |> Expect.equal []
        ]


beforeTests : Test
beforeTests =
    describe "before"
        [ fuzz (list int) "must return the whole list when nothing is selected" <|
            \lst ->
                before (fromList lst)
                    |> Expect.equal lst
        ]


lengthTests : Test
lengthTests =
    describe "length"
        [ fuzz (list int) "must be preserved by fromList" <|
            \lst ->
                length (fromList lst)
                    |> Expect.equal (List.length lst)
        , test "of an empty list must be 0" <|
            \_ ->
                length (fromList [])
                    |> Expect.equal 0
        ]


toListTests : Test
toListTests =
    describe "toList"
        [ fuzz (list int) "must reverse fromList" <|
            \lst ->
                fromList lst
                    |> toList
                    |> Expect.equal lst
        , test "must map an empty MaybeSelectList to an empty list" <|
            \_ ->
                fromList []
                    |> toList
                    |> Expect.equal []
        ]


selectTests : Test
selectTests =
    describe "select"
        [ test "must be identity if the new selection is not in the list" <|
            \_ ->
                let
                    lst =
                        fromList [ 1, 2, 3 ]
                in
                    select 4 lst
                        |> Expect.equal lst
        , fuzz2 (list (intRange 0 20)) (intRange 0 20) "must be idempotent" <|
            \l n ->
                let
                    lst =
                        fromList l
                in
                    lst
                        |> select n
                        |> select n
                        |> Expect.equal (select n lst)
        , fuzz2 (list (intRange 0 20)) (intRange 0 20) "must preserve length" <|
            \lst n ->
                fromList lst
                    |> select n
                    |> length
                    |> Expect.equal (List.length lst)
        , fuzz2 (list (intRange 0 20)) (intRange 0 20) "must preserve the underlying list" <|
            \lst n ->
                fromList lst
                    |> select n
                    |> toList
                    |> Expect.equal lst
96 97 98 99 100 101 102
        , test "called twice must preserve the underlying list" <|
            \_ ->
                fromList [ 1, 2, 3, 4, 5, 6 ]
                    |> select 1
                    |> select 6
                    |> toList
                    |> Expect.equal [ 1, 2, 3, 4, 5, 6 ]
103
        ]
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133


unselectTests =
    describe "unselect"
        [ fuzz (list int) "must be identity if nothing is selected" <|
            (\l ->
                let
                    lst =
                        fromList l
                in
                    unselect lst
                        |> Expect.equal lst
            )
        , fuzz2 (list (intRange 0 20)) (intRange 0 20) "must preserve length" <|
            (\l n ->
                fromList l
                    |> select n
                    |> unselect
                    |> length
                    |> Expect.equal (List.length l)
            )
        , fuzz2 (list (intRange 0 20)) (intRange 0 20) "must preserve underlying list" <|
            (\l n ->
                fromList l
                    |> select n
                    |> unselect
                    |> toList
                    |> Expect.equal l
            )
        ]