File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ append : Int -> RandomRun -> RandomRun
7070append n run =
7171 { run
7272 | length = run. length + 1
73- , data = Queue . enqueue n run. data
73+ , data = Queue . enqueue ( max 0 n ) run. data
7474 }
7575
7676
@@ -177,11 +177,7 @@ replaceInList values len list =
177177 , data =
178178 List . foldl
179179 ( \ ( index, newValue ) accList ->
180- if newValue < 0 then
181- accList
182-
183- else
184- List . setAt index newValue len accList
180+ List . setAt index ( max 0 newValue) len accList
185181 )
186182 list
187183 values
@@ -272,7 +268,7 @@ set index value run =
272268 | data =
273269 run. data
274270 |> Queue . toList
275- |> List . setAt index value run. length
271+ |> List . setAt index ( max 0 value) run. length
276272 |> Queue . fromList
277273 }
278274
Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ import Test exposing (Test)
1010all : Test
1111all =
1212 Test . describe " RandomRun"
13- [ Test . describe " Properties"
13+ [ negativeValuesTests
14+ , Test . describe " Properties"
1415 [ isEmptyTests
1516 , lengthTests
1617 , compareTests
3132 ]
3233
3334
35+ negativeValuesTests : Test
36+ negativeValuesTests =
37+ Test . describe " behaviour of negative values"
38+ [ Test . test " append -1" <|
39+ \ () ->
40+ RandomRun . empty
41+ |> RandomRun . append - 1
42+ |> RandomRun . get 0
43+ |> Expect . equal ( Just 0 )
44+ , Test . test " set -1" <|
45+ \ () ->
46+ RandomRun . empty
47+ |> RandomRun . append 0
48+ |> RandomRun . set 0 - 1
49+ |> RandomRun . get 0
50+ |> Expect . equal ( Just 0 )
51+ , Test . test " update (\\ _ -> -1)" <|
52+ \ () ->
53+ RandomRun . empty
54+ |> RandomRun . append 0
55+ |> RandomRun . update 0 ( \ _ -> - 1 )
56+ |> RandomRun . get 0
57+ |> Expect . equal ( Just 0 )
58+ , Test . test " replace [(0,-1)]" <|
59+ \ () ->
60+ RandomRun . empty
61+ |> RandomRun . append 0
62+ |> RandomRun . replace [ ( 0 , - 1 ) ]
63+ |> RandomRun . get 0
64+ |> Expect . equal ( Just 0 )
65+ ]
66+
67+
3468isEmptyTests : Test
3569isEmptyTests =
3670 Test . describe " isEmpty"
You can’t perform that action at this time.
0 commit comments