on master help sign in
Merge pull request #650 from Xashili/patch-2
0bc1f4bEvan Czaplicki
libraries/Native/Array.js+5−3
@@ -357,9 +357,11 @@ Elm.Native.Array.make = function(elm) {
357 // TODO: Add support for appending trees of different sizes. Current
357 // TODO: Add support for appending trees of different sizes. Current
358 // behavior will just rise the lower tree and then append them.
358 // behavior will just rise the lower tree and then append them.
359 function append(a,b) {
359 function append(a,b) {
360+ if (a.table.length == 0) return b;
361+ if (b.table.length == 0) return a;
360− if (b.height > a.height) { return append(parentise(a, b.height), b); }
362+ if (b.height > a.height) return append(parentise(a, b.height), b);
361− if (a.height > b.height) { return append(a, parentise(b, a.height)); }
363+ if (a.height > b.height) return append(a, parentise(b, a.height));
362− if (a.height == 0) { return append(parentise(a, 1), parentise(b, 1)); }
364+ if (a.height == 0) return append(parentise(a, 1), parentise(b, 1));
363
365
364 var c = append_(a, b);
366 var c = append_(a, b);
365 if (c[1].table.length > 0) {
367 if (c[1].table.length > 0) {
tests/libraries/Test/Array.elm+2
@@ -26,6 +26,8 @@ tests =
26 , test "length - Long" <| assertEqual 10000 (Array.length (Array.repeat 10000 0))
26 , test "length - Long" <| assertEqual 10000 (Array.length (Array.repeat 10000 0))
27 , test "push" <| assertEqual (Array.fromList [1,2,3]) (Array.push 3 (Array.fromList [1,2]))
27 , test "push" <| assertEqual (Array.fromList [1,2,3]) (Array.push 3 (Array.fromList [1,2]))
28 , test "append" <| assertEqual [42,42,81,81,81] (Array.toList (Array.append (Array.repeat 2 42) (Array.repeat 3 81)))
28 , test "append" <| assertEqual [42,42,81,81,81] (Array.toList (Array.append (Array.repeat 2 42) (Array.repeat 3 81)))
29+ , test "appendEmpty 1" <| assertEqual [1..33] (Array.toList (Array.append Array.empty (Array.fromList [1..33])))
30+ , test "appendEmpty 2" <| assertEqual [1..33] (Array.toList (Array.append (Array.fromList [1..33]) Array.empty))
29 ]
31 ]
30 getAndSetTests = suite "Get and Set"
32 getAndSetTests = suite "Get and Set"
31 [ test "get" <| assertEqual (Just 2) (Array.get 1 (Array.fromList [3,2,1]))
33 [ test "get" <| assertEqual (Just 2) (Array.get 1 (Array.fromList [3,2,1]))