diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 1c6afb9d..00000000 --- a/.eslintrc.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "parserOptions": { - "ecmaVersion": 6, - "sourceType": "module" - }, - "extends": "eslint:recommended", - "rules": { - "strict": [2, "global"], - "block-scoped-var": 2, - "consistent-return": 2, - "eqeqeq": [2, "smart"], - "guard-for-in": 2, - "no-caller": 2, - "no-extend-native": 2, - "no-loop-func": 2, - "no-new": 2, - "no-param-reassign": 2, - "no-return-assign": 2, - "no-unused-expressions": 2, - "no-use-before-define": 2, - "radix": [2, "always"], - "indent": [2, 2], - "quotes": [2, "double"], - "semi": [2, "always"] - } -} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c69237a6..ae28dfa8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,30 +6,32 @@ on: pull_request: branches: [master] +permissions: + contents: read + jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - uses: purescript-contrib/setup-purescript@main - with: - purescript: "unstable" - - - uses: actions/setup-node@v2 + - uses: actions/checkout@v6 + - uses: actions/setup-node@v6 with: - node-version: "14.x" + node-version: "24" - name: Install dependencies - run: | - npm install -g bower - npm install - bower install --production + run: npm install - name: Build source - run: npm run-script build + run: npm run build - name: Run tests - run: | - bower install - npm run-script test --if-present + run: npm test + + - name: Run benchmarks + run: npm run bench + + - name: Lint + run: npm run lint + + - name: Check formatting + run: npm run format:check diff --git a/.gitignore b/.gitignore index 7bb9d6d1..04908543 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ /.* !/.gitignore !/.github -!/.eslintrc.json -!/.travis.yml -package-lock.json +!/.tidyrc.json +!/.oxfmtrc.json +/package-lock.json +/spago.lock /bower_components/ /node_modules/ /output/ diff --git a/.oxfmtrc.json b/.oxfmtrc.json new file mode 100644 index 00000000..757fd64c --- /dev/null +++ b/.oxfmtrc.json @@ -0,0 +1,3 @@ +{ + "trailingComma": "es5" +} diff --git a/.tidyrc.json b/.tidyrc.json new file mode 100644 index 00000000..9e39cf11 --- /dev/null +++ b/.tidyrc.json @@ -0,0 +1,10 @@ +{ + "importSort": "ide", + "importWrap": "source", + "indent": 2, + "operatorsFile": null, + "ribbon": 1, + "typeArrowPlacement": "first", + "unicode": "never", + "width": null +} diff --git a/CHANGELOG.md b/CHANGELOG.md index a680f26c..9a7f1ff5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,13 +12,21 @@ Bugfixes: Other improvements: +## [v7.3.1](https://github.com/purescript/purescript-arrays/releases/tag/v7.3.1) - 2026-10-17 + +Other improvements: + +- Migrate from Bower/Pulp to Spago and update CI, linting and formatting (#247 by @thomashoneyman). + ## [v7.3.0](https://github.com/purescript/purescript-arrays/releases/tag/v7.3.0) - 2023-11-03 New features: + - Add `ST.clone` (#243 by @Bgbagan) Other improvements: - - Implements `ST.push` via a call to JavaScript's native `push` instead of `pushAll` (#236 by @i-am-the-slime) + +- Implements `ST.push` via a call to JavaScript's native `push` instead of `pushAll` (#236 by @i-am-the-slime) ## [v7.2.1](https://github.com/purescript/purescript-arrays/releases/tag/v7.2.1) - 2023-06-13 diff --git a/bench/spago.yaml b/bench/spago.yaml new file mode 100644 index 00000000..eeddebb5 --- /dev/null +++ b/bench/spago.yaml @@ -0,0 +1,12 @@ +package: + name: arrays-bench + build: + strict: true + pedanticPackages: true + dependencies: + - arrays: "*" + - console: ">=6.0.0 <7.0.0" + - effect: ">=4.0.0 <5.0.0" + - maybe: ">=6.0.0 <7.0.0" + - minibench: ">=4.0.0 <5.0.0" + - prelude: ">=6.0.0 <7.0.0" diff --git a/bench/Data/Array.purs b/bench/src/Bench/Data/Array.purs similarity index 79% rename from bench/Data/Array.purs rename to bench/src/Bench/Data/Array.purs index dc94c7d8..5080f257 100644 --- a/bench/Data/Array.purs +++ b/bench/src/Bench/Data/Array.purs @@ -17,9 +17,10 @@ benchArray = do where benchMapMaybe = do - let shortNats = Array.range 0 100 - longNats = Array.range 0 10000 - onlyEven x = if x `mod` 2 == 0 then Just x else Nothing + let + shortNats = Array.range 0 100 + longNats = Array.range 0 10000 + onlyEven x = if x `mod` 2 == 0 then Just x else Nothing log $ "mapMaybe (" <> show (Array.length shortNats) <> ")" benchWith 1000 \_ -> Array.mapMaybe onlyEven shortNats diff --git a/bench/Main.purs b/bench/src/Bench/Main.purs similarity index 100% rename from bench/Main.purs rename to bench/src/Bench/Main.purs diff --git a/bower.json b/bower.json deleted file mode 100644 index 19b19922..00000000 --- a/bower.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "name": "purescript-arrays", - "homepage": "https://github.com/purescript/purescript-arrays", - "license": "BSD-3-Clause", - "repository": { - "type": "git", - "url": "https://github.com/purescript/purescript-arrays.git" - }, - "ignore": [ - "**/.*", - "bower_components", - "node_modules", - "output", - "bower.json", - "package.json" - ], - "dependencies": { - "purescript-bifunctors": "^6.0.0", - "purescript-control": "^6.0.0", - "purescript-foldable-traversable": "^6.0.0", - "purescript-functions": "^6.0.0", - "purescript-maybe": "^6.0.0", - "purescript-nonempty": "^7.0.0", - "purescript-partial": "^4.0.0", - "purescript-prelude": "^6.0.0", - "purescript-safe-coerce": "^2.0.0", - "purescript-st": "^6.2.0", - "purescript-tailrec": "^6.0.0", - "purescript-tuples": "^7.0.0", - "purescript-unfoldable": "^6.0.0", - "purescript-unsafe-coerce": "^6.0.0" - }, - "devDependencies": { - "purescript-assert": "^6.0.0", - "purescript-console": "^6.0.0", - "purescript-const": "^6.0.0", - "purescript-minibench": "^4.0.0" - } -} diff --git a/package.json b/package.json index ee9cb3aa..bf4a3866 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,20 @@ { "private": true, "scripts": { - "clean": "rimraf output && rimraf .pulp-cache", - "build": "eslint src && pulp build -- --censor-lib --strict", - "test": "pulp test", - "bench:build": "pulp build --include bench -- --censor-lib --strict", - "bench:run": "node --expose-gc -e \"require('./output/Bench.Main/index.js').main()\"", - "bench": "npm run bench:build && npm run bench:run" + "build": "spago build -p arrays", + "test": "spago test -p arrays", + "bench:build": "spago build -p arrays-bench", + "bench:run": "node --expose-gc -e \"import('./output/Bench.Main/index.js').then(m => m.main())\"", + "bench": "npm run bench:build && npm run bench:run", + "lint": "oxlint --deny-warnings src test", + "format": "purs-tidy format-in-place src test bench/src && oxfmt --write .", + "format:check": "purs-tidy check src test bench/src && oxfmt --check ." }, "devDependencies": { - "eslint": "^7.15.0", - "pulp": "16.0.0-0", - "purescript-psa": "^0.8.2", - "rimraf": "^3.0.2" + "oxfmt": "^0.73.0", + "oxlint": "^1.88.0", + "purescript": "^0.15.16", + "purs-tidy": "^0.11.1", + "spago": "^1.0.5" } } diff --git a/spago.yaml b/spago.yaml new file mode 100644 index 00000000..40a09716 --- /dev/null +++ b/spago.yaml @@ -0,0 +1,38 @@ +package: + name: arrays + description: Utility functions for the Array type - JavaScript's native arrays. + build: + strict: true + pedanticPackages: true + publish: + version: 7.3.1 + license: BSD-3-Clause + location: + githubOwner: purescript + githubRepo: purescript-arrays + dependencies: + - bifunctors: ">=6.0.0 <7.0.0" + - control: ">=6.0.0 <7.0.0" + - foldable-traversable: ">=6.0.0 <7.0.0" + - functions: ">=6.0.0 <7.0.0" + - maybe: ">=6.0.0 <7.0.0" + - nonempty: ">=7.0.0 <8.0.0" + - partial: ">=4.0.0 <5.0.0" + - prelude: ">=6.0.0 <7.0.0" + - safe-coerce: ">=2.0.0 <3.0.0" + - st: ">=6.2.0 <7.0.0" + - tailrec: ">=6.0.0 <7.0.0" + - tuples: ">=7.0.0 <8.0.0" + - unfoldable: ">=6.0.0 <7.0.0" + - unsafe-coerce: ">=6.0.0 <7.0.0" + test: + main: Test.Main + strict: true + pedanticPackages: true + dependencies: + - assert: ">=6.0.0 <7.0.0" + - console: ">=6.0.0 <7.0.0" + - const: ">=6.0.0 <7.0.0" + - effect: ">=4.0.0 <5.0.0" + - orders: ">=6.0.0 <7.0.0" +workspace: {} diff --git a/src/Data/Array.js b/src/Data/Array.js index aa36c4df..272c4883 100644 --- a/src/Data/Array.js +++ b/src/Data/Array.js @@ -1,11 +1,16 @@ +// Arrays with a known size are allocated upfront and filled below. +// Initializing those slots first would do the work twice. + //------------------------------------------------------------------------------ // Array creation -------------------------------------------------------------- //------------------------------------------------------------------------------ export const rangeImpl = function (start, end) { var step = start > end ? -1 : 1; + // oxlint-disable-next-line unicorn/no-new-array var result = new Array(step * (end - start) + 1); - var i = start, n = 0; + var i = start, + n = 0; while (i !== end) { result[n++] = i; i += step; @@ -18,6 +23,7 @@ var replicateFill = function (count, value) { if (count < 1) { return []; } + // oxlint-disable-next-line unicorn/no-new-array var result = new Array(count); return result.fill(value); }; @@ -32,7 +38,8 @@ var replicatePolyfill = function (count, value) { }; // In browsers that have Array.prototype.fill we use it, as it's faster. -export const replicateImpl = typeof Array.prototype.fill === "function" ? replicateFill : replicatePolyfill; +export const replicateImpl = + typeof Array.prototype.fill === "function" ? replicateFill : replicatePolyfill; export const fromFoldableImpl = (function () { function Cons(head, tail) { @@ -84,7 +91,7 @@ export const unconsImpl = function (empty, next, xs) { //------------------------------------------------------------------------------ export const indexImpl = function (just, nothing, xs, i) { - return i < 0 || i >= xs.length ? nothing : just(xs[i]); + return i < 0 || i >= xs.length ? nothing : just(xs[i]); }; export const findMapImpl = function (nothing, isJust, f, xs) { @@ -161,13 +168,11 @@ export const filterImpl = function (f, xs) { export const partitionImpl = function (f, xs) { var yes = []; - var no = []; + var no = []; for (var i = 0; i < xs.length; i++) { var x = xs[i]; - if (f(x)) - yes.push(x); - else - no.push(x); + if (f(x)) yes.push(x); + else no.push(x); } return { yes: yes, no: no }; }; @@ -175,6 +180,7 @@ export const partitionImpl = function (f, xs) { export const scanlImpl = function (f, b, xs) { var len = xs.length; var acc = b; + // oxlint-disable-next-line unicorn/no-new-array var out = new Array(len); for (var i = 0; i < len; i++) { acc = f(acc)(xs[i]); @@ -186,6 +192,7 @@ export const scanlImpl = function (f, b, xs) { export const scanrImpl = function (f, b, xs) { var len = xs.length; var acc = b; + // oxlint-disable-next-line unicorn/no-new-array var out = new Array(len); for (var i = len - 1; i >= 0; i--) { acc = f(xs[i])(acc); @@ -222,8 +229,7 @@ export const sortByImpl = (function () { if (c > 0) { xs1[k++] = y; ++j; - } - else { + } else { xs1[k++] = x; ++i; } @@ -262,6 +268,7 @@ export const sliceImpl = function (s, e, l) { export const zipWithImpl = function (f, xs, ys) { var l = xs.length < ys.length ? xs.length : ys.length; + // oxlint-disable-next-line unicorn/no-new-array var result = new Array(l); for (var i = 0; i < l; i++) { result[i] = f(xs[i])(ys[i]); diff --git a/src/Data/Array.purs b/src/Data/Array.purs index 431f942a..e003216c 100644 --- a/src/Data/Array.purs +++ b/src/Data/Array.purs @@ -149,7 +149,7 @@ import Data.Foldable (class Foldable, traverse_) import Data.Foldable as F import Data.Function.Uncurried (Fn2, Fn3, Fn4, Fn5, runFn2, runFn3, runFn4, runFn5) import Data.FunctorWithIndex as FWI -import Data.Maybe (Maybe(..), maybe, isJust, fromJust, isNothing) +import Data.Maybe (Maybe(..), fromJust, isJust, isNothing, maybe) import Data.Traversable (sequence, traverse) import Data.Tuple (Tuple(..), fst, snd) import Data.Unfoldable (class Unfoldable, unfoldr) diff --git a/src/Data/Array/NonEmpty.purs b/src/Data/Array/NonEmpty.purs index e69a7bf1..d29caa2a 100644 --- a/src/Data/Array/NonEmpty.purs +++ b/src/Data/Array/NonEmpty.purs @@ -10,13 +10,15 @@ module Data.Array.NonEmpty , toUnfoldable , toUnfoldable1 , singleton - , (..), range + , (..) + , range , replicate , some , length - , (:), cons + , (:) + , cons , cons' , snoc , snoc' @@ -32,7 +34,8 @@ module Data.Array.NonEmpty , uncons , unsnoc - , (!!), index + , (!!) + , index , elem , notElem , elemIndex @@ -97,7 +100,8 @@ module Data.Array.NonEmpty , delete , deleteBy - , (\\), difference + , (\\) + , difference , difference' , intersect , intersect' @@ -177,7 +181,7 @@ toArray :: forall a. NonEmptyArray a -> Array a toArray (NonEmptyArray xs) = xs toNonEmpty :: forall a. NonEmptyArray a -> NonEmpty Array a -toNonEmpty = uncons >>> \{head: x, tail: xs} -> x :| xs +toNonEmpty = uncons >>> \{ head: x, tail: xs } -> x :| xs fromFoldable :: forall f a. Foldable f => f a -> Maybe (NonEmptyArray a) fromFoldable = fromArray <<< A.fromFoldable @@ -193,7 +197,7 @@ toUnfoldable1 xs = unfoldr1 f 0 where len = length xs f i = Tuple (unsafePartial unsafeIndex xs i) $ - if i < (len - 1) then Just (i + 1) else Nothing + if i < (len - 1) then Just (i + 1) else Nothing singleton :: forall a. a -> NonEmptyArray a singleton = unsafeFromArray <<< A.singleton @@ -211,7 +215,8 @@ some :: forall f a . Alternative f => Lazy (f (Array a)) - => f a -> f (NonEmptyArray a) + => f a + -> f (NonEmptyArray a) some = unsafeFromArrayF <<< A.some length :: forall a. NonEmptyArray a -> Int @@ -330,7 +335,7 @@ partition :: forall a . (a -> Boolean) -> NonEmptyArray a - -> { yes :: Array a, no :: Array a} + -> { yes :: Array a, no :: Array a } partition f = adaptAny $ A.partition f filterA @@ -396,9 +401,10 @@ intercalate = F.intercalate -- | ]) -- | ``` transpose :: forall a. NonEmptyArray (NonEmptyArray a) -> NonEmptyArray (NonEmptyArray a) -transpose = - (coerce :: (Array (Array a)) -> (NonEmptyArray (NonEmptyArray a))) - <<< A.transpose <<< coerce +transpose = + (coerce :: (Array (Array a)) -> (NonEmptyArray (NonEmptyArray a))) + <<< A.transpose + <<< coerce -- | `transpose`' is identical to `transpose` other than that the inner arrays are each -- | a standard `Array` and not a `NonEmptyArray`. However, the result is wrapped in a @@ -534,10 +540,10 @@ difference xs = adaptAny $ difference' xs difference' :: forall a. Eq a => NonEmptyArray a -> Array a -> Array a difference' xs = A.difference $ toArray xs -intersect :: forall a . Eq a => NonEmptyArray a -> NonEmptyArray a -> Array a +intersect :: forall a. Eq a => NonEmptyArray a -> NonEmptyArray a -> Array a intersect = intersectBy eq -intersect' :: forall a . Eq a => NonEmptyArray a -> Array a -> Array a +intersect' :: forall a. Eq a => NonEmptyArray a -> Array a -> Array a intersect' = intersectBy' eq intersectBy @@ -566,7 +572,6 @@ zipWith -> NonEmptyArray c zipWith f xs ys = unsafeFromArray $ A.zipWith f (toArray xs) (toArray ys) - zipWithA :: forall m a b c . Applicative m diff --git a/src/Data/Array/NonEmpty/Internal.js b/src/Data/Array/NonEmpty/Internal.js index dc06c327..e30ed360 100644 --- a/src/Data/Array/NonEmpty/Internal.js +++ b/src/Data/Array/NonEmpty/Internal.js @@ -15,7 +15,7 @@ export const foldl1Impl = function (f, xs) { return acc; }; -export const traverse1Impl = function () { +export const traverse1Impl = (function () { function Cont(fn) { this.fn = fn; } @@ -74,4 +74,4 @@ export const traverse1Impl = function () { return map(listToArray)(result); }; }; -}(); +})(); diff --git a/src/Data/Array/ST.js b/src/Data/Array/ST.js index 60f250c0..d45ef7a2 100644 --- a/src/Data/Array/ST.js +++ b/src/Data/Array/ST.js @@ -103,6 +103,8 @@ export const sortByImpl = (function () { export const toAssocArrayImpl = function (xs) { var n = xs.length; + // Each slot receives its indexed value below; preinitializing would duplicate work. + // oxlint-disable-next-line unicorn/no-new-array var as = new Array(n); for (var i = 0; i < n; i++) as[i] = { value: xs[i], index: i }; return as; diff --git a/src/Data/Array/ST.purs b/src/Data/Array/ST.purs index 158e4104..4c8fc15d 100644 --- a/src/Data/Array/ST.purs +++ b/src/Data/Array/ST.purs @@ -32,7 +32,7 @@ module Data.Array.ST import Prelude -import Control.Monad.ST (ST, Region) +import Control.Monad.ST (Region, ST) import Control.Monad.ST as ST import Control.Monad.ST.Uncurried (STFn1, STFn2, STFn3, STFn4, runSTFn1, runSTFn2, runSTFn3, runSTFn4) import Data.Maybe (Maybe(..)) diff --git a/src/Data/Array/ST/Iterator.purs b/src/Data/Array/ST/Iterator.purs index 09daf0ed..afc93326 100644 --- a/src/Data/Array/ST/Iterator.purs +++ b/src/Data/Array/ST/Iterator.purs @@ -10,13 +10,13 @@ module Data.Array.ST.Iterator ) where import Prelude + import Control.Monad.ST (ST) import Control.Monad.ST as ST import Control.Monad.ST.Ref (STRef) import Control.Monad.ST.Ref as STRef import Data.Array.ST (STArray) import Data.Array.ST as STA - import Data.Maybe (Maybe(..), isNothing) -- | This type provides a slightly easier way of iterating over an array's diff --git a/test/Test/Data/Array.purs b/test/Test/Data/Array.purs index e2d7b0fe..e272e0e4 100644 --- a/test/Test/Data/Array.purs +++ b/test/Test/Data/Array.purs @@ -2,14 +2,14 @@ module Test.Data.Array (testArray) where import Prelude -import Data.Array ((:), (\\), (!!)) +import Data.Array ((!!), (:), (\\)) import Data.Array as A import Data.Array.NonEmpty as NEA import Data.Const (Const(..)) -import Data.Foldable (for_, foldMapDefaultR, class Foldable, all, traverse_) -import Data.Traversable (scanl, scanr) -import Data.Maybe (Maybe(..), isNothing, fromJust) +import Data.Foldable (class Foldable, all, foldMapDefaultR, for_, traverse_) +import Data.Maybe (Maybe(..), fromJust, isNothing) import Data.Ord.Down (Down(..)) +import Data.Traversable (scanl, scanr) import Data.Tuple (Tuple(..), fst) import Data.Unfoldable (replicateA) import Effect (Effect) @@ -22,83 +22,83 @@ testArray :: Effect Unit testArray = do log "singleton should construct an array with a single value" - assert $ A.singleton 1 == [1] - assert $ A.singleton "foo" == ["foo"] - assert $ A.singleton nil == [[]] + assert $ A.singleton 1 == [ 1 ] + assert $ A.singleton "foo" == [ "foo" ] + assert $ A.singleton nil == [ [] ] log "range should create an inclusive array of integers for the specified start and end" - assert $ (A.range 0 5) == [0, 1, 2, 3, 4, 5] - assert $ (A.range 2 (-3)) == [2, 1, 0, -1, -2, -3] + assert $ (A.range 0 5) == [ 0, 1, 2, 3, 4, 5 ] + assert $ (A.range 2 (-3)) == [ 2, 1, 0, -1, -2, -3 ] log "replicate should produce an array containg an item a specified number of times" - assert $ A.replicate 3 true == [true, true, true] - assert $ A.replicate 1 "foo" == ["foo"] + assert $ A.replicate 3 true == [ true, true, true ] + assert $ A.replicate 1 "foo" == [ "foo" ] assert $ A.replicate 0 "foo" == [] assert $ A.replicate (-1) "foo" == [] log "replicateA should perform the monadic action the correct number of times" - assert $ replicateA 3 (Just 1) == Just [1, 1, 1] - assert $ replicateA 1 (Just 1) == Just [1] + assert $ replicateA 3 (Just 1) == Just [ 1, 1, 1 ] + assert $ replicateA 1 (Just 1) == Just [ 1 ] assert $ replicateA 0 (Just 1) == Just [] assert $ replicateA (-1) (Just 1) == Just [] log "replicateA should be stack safe" - for_ [1, 1000, 2000, 20000, 50000] \n -> do + for_ [ 1, 1000, 2000, 20000, 50000 ] \n -> do assert $ replicateA n (Just unit) == Just (A.replicate n unit :: Array Unit) -- some -- many log "null should return false for non-empty arrays" - assert $ A.null [1] == false - assert $ A.null [1, 2, 3] == false + assert $ A.null [ 1 ] == false + assert $ A.null [ 1, 2, 3 ] == false log "null should return true for an empty array" assert $ A.null nil == true log "length should return the number of items in an array" assert $ A.length nil == 0 - assert $ A.length [1] == 1 - assert $ A.length [1, 2, 3, 4, 5] == 5 + assert $ A.length [ 1 ] == 1 + assert $ A.length [ 1, 2, 3, 4, 5 ] == 5 log "cons should add an item to the start of an array" - assert $ 4 : [1, 2, 3] == [4, 1, 2, 3] - assert $ 1 : nil == [1] + assert $ 4 : [ 1, 2, 3 ] == [ 4, 1, 2, 3 ] + assert $ 1 : nil == [ 1 ] log "snoc should add an item to the end of an array" - assert $ [1, 2, 3] `A.snoc` 4 == [1, 2, 3, 4] - assert $ nil `A.snoc` 1 == [1] + assert $ [ 1, 2, 3 ] `A.snoc` 4 == [ 1, 2, 3, 4 ] + assert $ nil `A.snoc` 1 == [ 1 ] log "insert should add an item at the appropriate place in a sorted array" - assert $ A.insert 1.5 [1.0, 2.0, 3.0] == [1.0, 1.5, 2.0, 3.0] - assert $ A.insert 4 [1, 2, 3] == [1, 2, 3, 4] - assert $ A.insert 0 [1, 2, 3] == [0, 1, 2, 3] + assert $ A.insert 1.5 [ 1.0, 2.0, 3.0 ] == [ 1.0, 1.5, 2.0, 3.0 ] + assert $ A.insert 4 [ 1, 2, 3 ] == [ 1, 2, 3, 4 ] + assert $ A.insert 0 [ 1, 2, 3 ] == [ 0, 1, 2, 3 ] log "insertBy should add an item at the appropriate place in a sorted array using the specified comparison" - assert $ A.insertBy (flip compare) 1.5 [1.0, 2.0, 3.0] == [1.0, 2.0, 3.0, 1.5] - assert $ A.insertBy (flip compare) 4 [1, 2, 3] == [4, 1, 2, 3] - assert $ A.insertBy (flip compare) 0 [1, 2, 3] == [1, 2, 3, 0] + assert $ A.insertBy (flip compare) 1.5 [ 1.0, 2.0, 3.0 ] == [ 1.0, 2.0, 3.0, 1.5 ] + assert $ A.insertBy (flip compare) 4 [ 1, 2, 3 ] == [ 4, 1, 2, 3 ] + assert $ A.insertBy (flip compare) 0 [ 1, 2, 3 ] == [ 1, 2, 3, 0 ] log "head should return a Just-wrapped first value of a non-empty array" - assert $ A.head ["foo", "bar"] == Just "foo" + assert $ A.head [ "foo", "bar" ] == Just "foo" log "head should return Nothing for an empty array" assert $ A.head nil == Nothing log "last should return a Just-wrapped last value of a non-empty array" - assert $ A.last ["foo", "bar"] == Just "bar" + assert $ A.last [ "foo", "bar" ] == Just "bar" log "last should return Nothing for an empty array" assert $ A.last nil == Nothing log "tail should return a Just-wrapped array containing all the items in an array apart from the first for a non-empty array" - assert $ A.tail ["foo", "bar", "baz"] == Just ["bar", "baz"] + assert $ A.tail [ "foo", "bar", "baz" ] == Just [ "bar", "baz" ] log "tail should return Nothing for an empty array" assert $ A.tail nil == Nothing log "init should return a Just-wrapped array containing all the items in an array apart from the first for a non-empty array" - assert $ A.init ["foo", "bar", "baz"] == Just ["foo", "bar"] + assert $ A.init [ "foo", "bar", "baz" ] == Just [ "foo", "bar" ] log "init should return Nothing for an empty array" assert $ A.init nil == Nothing @@ -107,254 +107,256 @@ testArray = do assert $ isNothing (A.uncons nil) log "uncons should split an array into a head and tail record when there is at least one item" - let u1 = unsafePartial $ fromJust $ A.uncons [1] + let u1 = unsafePartial $ fromJust $ A.uncons [ 1 ] assert $ u1.head == 1 assert $ u1.tail == [] - let u2 = unsafePartial $ fromJust $ A.uncons [1, 2, 3] + let u2 = unsafePartial $ fromJust $ A.uncons [ 1, 2, 3 ] assert $ u2.head == 1 - assert $ u2.tail == [2, 3] + assert $ u2.tail == [ 2, 3 ] log "unsnoc should return nothing when used on an empty array" assert $ isNothing (A.unsnoc nil) log "unsnoc should split an array into an init and last record when there is at least one item" - let u3 = unsafePartial $ fromJust $ A.unsnoc [1] + let u3 = unsafePartial $ fromJust $ A.unsnoc [ 1 ] assert $ u3.init == [] assert $ u3.last == 1 - let u4 = unsafePartial $ fromJust $ A.unsnoc [1, 2, 3] - assert $ u4.init == [1, 2] + let u4 = unsafePartial $ fromJust $ A.unsnoc [ 1, 2, 3 ] + assert $ u4.init == [ 1, 2 ] assert $ u4.last == 3 log "(!!) should return Just x when the index is within the bounds of the array" - assert $ [1, 2, 3] !! 0 == (Just 1) - assert $ [1, 2, 3] !! 1 == (Just 2) - assert $ [1, 2, 3] !! 2 == (Just 3) + assert $ [ 1, 2, 3 ] !! 0 == (Just 1) + assert $ [ 1, 2, 3 ] !! 1 == (Just 2) + assert $ [ 1, 2, 3 ] !! 2 == (Just 3) log "(!!) should return Nothing when the index is outside of the bounds of the array" - assert $ [1, 2, 3] !! 6 == Nothing - assert $ [1, 2, 3] !! (-1) == Nothing + assert $ [ 1, 2, 3 ] !! 6 == Nothing + assert $ [ 1, 2, 3 ] !! (-1) == Nothing log "elem should return true if the array contains the given element at least once" - assert $ (A.elem 1 [1, 2, 1]) == true - assert $ (A.elem 4 [1, 2, 1]) == false + assert $ (A.elem 1 [ 1, 2, 1 ]) == true + assert $ (A.elem 4 [ 1, 2, 1 ]) == false log "notElem should return true if the array does not contain the given element" - assert $ (A.notElem 1 [1, 2, 1]) == false - assert $ (A.notElem 4 [1, 2, 1]) == true + assert $ (A.notElem 1 [ 1, 2, 1 ]) == false + assert $ (A.notElem 4 [ 1, 2, 1 ]) == true log "elemIndex should return the index of an item that a predicate returns true for in an array" - assert $ (A.elemIndex 1 [1, 2, 1]) == Just 0 - assert $ (A.elemIndex 4 [1, 2, 1]) == Nothing + assert $ (A.elemIndex 1 [ 1, 2, 1 ]) == Just 0 + assert $ (A.elemIndex 4 [ 1, 2, 1 ]) == Nothing log "elemLastIndex should return the last index of an item in an array" - assert $ (A.elemLastIndex 1 [1, 2, 1]) == Just 2 - assert $ (A.elemLastIndex 4 [1, 2, 1]) == Nothing + assert $ (A.elemLastIndex 1 [ 1, 2, 1 ]) == Just 2 + assert $ (A.elemLastIndex 4 [ 1, 2, 1 ]) == Nothing log "find should return the first element for which a predicate returns true in an array" - assert $ (A.find (_ /= 1) [1, 2, 1]) == Just 2 - assert $ (A.find (_ == 3) [1, 2, 1]) == Nothing + assert $ (A.find (_ /= 1) [ 1, 2, 1 ]) == Just 2 + assert $ (A.find (_ == 3) [ 1, 2, 1 ]) == Nothing log "findMap should return the mapping of the first element that satisfies the given predicate" - assert $ (A.findMap (\x -> if x > 3 then Just x else Nothing) [1, 2, 4]) == Just 4 - assert $ (A.findMap (\x -> if x > 3 then Just x else Nothing) [1, 2, 1]) == Nothing - assert $ (A.findMap (\x -> if x > 3 then Just x else Nothing) [4, 1, 5]) == Just 4 + assert $ (A.findMap (\x -> if x > 3 then Just x else Nothing) [ 1, 2, 4 ]) == Just 4 + assert $ (A.findMap (\x -> if x > 3 then Just x else Nothing) [ 1, 2, 1 ]) == Nothing + assert $ (A.findMap (\x -> if x > 3 then Just x else Nothing) [ 4, 1, 5 ]) == Just 4 log "findIndex should return the index of an item that a predicate returns true for in an array" - assert $ (A.findIndex (_ /= 1) [1, 2, 1]) == Just 1 - assert $ (A.findIndex (_ == 3) [1, 2, 1]) == Nothing + assert $ (A.findIndex (_ /= 1) [ 1, 2, 1 ]) == Just 1 + assert $ (A.findIndex (_ == 3) [ 1, 2, 1 ]) == Nothing log "findLastIndex should return the last index of an item in an array" - assert $ (A.findLastIndex (_ /= 1) [2, 1, 2]) == Just 2 - assert $ (A.findLastIndex (_ == 3) [2, 1, 2]) == Nothing + assert $ (A.findLastIndex (_ /= 1) [ 2, 1, 2 ]) == Just 2 + assert $ (A.findLastIndex (_ == 3) [ 2, 1, 2 ]) == Nothing log "insertAt should add an item at the specified index" - assert $ (A.insertAt 0 1 [2, 3]) == Just [1, 2, 3] - assert $ (A.insertAt 1 1 [2, 3]) == Just [2, 1, 3] - assert $ (A.insertAt 2 1 [2, 3]) == Just [2, 3, 1] + assert $ (A.insertAt 0 1 [ 2, 3 ]) == Just [ 1, 2, 3 ] + assert $ (A.insertAt 1 1 [ 2, 3 ]) == Just [ 2, 1, 3 ] + assert $ (A.insertAt 2 1 [ 2, 3 ]) == Just [ 2, 3, 1 ] log "insertAt should return Nothing if the index is out of A.range" assert $ (A.insertAt 2 1 nil) == Nothing log "deleteAt should remove an item at the specified index" - assert $ (A.deleteAt 0 [1, 2, 3]) == Just [2, 3] - assert $ (A.deleteAt 1 [1, 2, 3]) == Just [1, 3] + assert $ (A.deleteAt 0 [ 1, 2, 3 ]) == Just [ 2, 3 ] + assert $ (A.deleteAt 1 [ 1, 2, 3 ]) == Just [ 1, 3 ] log "deleteAt should return Nothing if the index is out of A.range" assert $ (A.deleteAt 1 nil) == Nothing log "updateAt should replace an item at the specified index" - assert $ (A.updateAt 0 9 [1, 2, 3]) == Just [9, 2, 3] - assert $ (A.updateAt 1 9 [1, 2, 3]) == Just [1, 9, 3] + assert $ (A.updateAt 0 9 [ 1, 2, 3 ]) == Just [ 9, 2, 3 ] + assert $ (A.updateAt 1 9 [ 1, 2, 3 ]) == Just [ 1, 9, 3 ] log "updateAt should return Nothing if the index is out of A.range" assert $ (A.updateAt 1 9 nil) == Nothing log "modifyAt should update an item at the specified index" - assert $ (A.modifyAt 0 (_ + 1) [1, 2, 3]) == Just [2, 2, 3] - assert $ (A.modifyAt 1 (_ + 1) [1, 2, 3]) == Just [1, 3, 3] + assert $ (A.modifyAt 0 (_ + 1) [ 1, 2, 3 ]) == Just [ 2, 2, 3 ] + assert $ (A.modifyAt 1 (_ + 1) [ 1, 2, 3 ]) == Just [ 1, 3, 3 ] log "modifyAt should return Nothing if the index is out of A.range" assert $ (A.modifyAt 1 (_ + 1) nil) == Nothing log "alterAt should update an item at the specified index when the function returns Just" - assert $ (A.alterAt 0 (Just <<< (_ + 1)) [1, 2, 3]) == Just [2, 2, 3] - assert $ (A.alterAt 1 (Just <<< (_ + 1)) [1, 2, 3]) == Just [1, 3, 3] + assert $ (A.alterAt 0 (Just <<< (_ + 1)) [ 1, 2, 3 ]) == Just [ 2, 2, 3 ] + assert $ (A.alterAt 1 (Just <<< (_ + 1)) [ 1, 2, 3 ]) == Just [ 1, 3, 3 ] log "alterAt should drop an item at the specified index when the function returns Nothing" - assert $ (A.alterAt 0 (const Nothing) [1, 2, 3]) == Just [2, 3] - assert $ (A.alterAt 1 (const Nothing) [1, 2, 3]) == Just [1, 3] + assert $ (A.alterAt 0 (const Nothing) [ 1, 2, 3 ]) == Just [ 2, 3 ] + assert $ (A.alterAt 1 (const Nothing) [ 1, 2, 3 ]) == Just [ 1, 3 ] log "alterAt should return Nothing if the index is out of A.range" assert $ (A.alterAt 1 (Just <<< (_ + 1)) nil) == Nothing log "intersperse should return the original array when given an array with zero or one elements" assert $ (A.intersperse " " []) == [] - assert $ (A.intersperse " " ["a"]) == ["a"] + assert $ (A.intersperse " " [ "a" ]) == [ "a" ] log "intersperse should insert the given element in-between each element in an array with two or more elements" - assert $ (A.intersperse " " ["a", "b"]) == ["a", " ", "b"] + assert $ (A.intersperse " " [ "a", "b" ]) == [ "a", " ", "b" ] assert $ (A.intersperse 0 [ 1, 2, 3, 4, 5 ]) == [ 1, 0, 2, 0, 3, 0, 4, 0, 5 ] log "reverse should reverse the order of items in an array" - assert $ (A.reverse [1, 2, 3]) == [3, 2, 1] + assert $ (A.reverse [ 1, 2, 3 ]) == [ 3, 2, 1 ] assert $ (A.reverse nil) == nil log "concat should join an array of arrays" - assert $ (A.concat [[1, 2], [3, 4]]) == [1, 2, 3, 4] - assert $ (A.concat [[1], nil]) == [1] - assert $ (A.concat [nil, nil]) == nil + assert $ (A.concat [ [ 1, 2 ], [ 3, 4 ] ]) == [ 1, 2, 3, 4 ] + assert $ (A.concat [ [ 1 ], nil ]) == [ 1 ] + assert $ (A.concat [ nil, nil ]) == nil log "concatMap should be equivalent to (concat <<< map)" - assert $ A.concatMap doubleAndOrig [1, 2, 3] == A.concat (map doubleAndOrig [1, 2, 3]) + assert $ A.concatMap doubleAndOrig [ 1, 2, 3 ] == A.concat (map doubleAndOrig [ 1, 2, 3 ]) log "filter should remove items that don't match a predicate" - assert $ A.filter odd (A.range 0 10) == [1, 3, 5, 7, 9] + assert $ A.filter odd (A.range 0 10) == [ 1, 3, 5, 7, 9 ] log "splitAt should split the array at the given number of elements" assert $ A.splitAt 2 ([] :: Array Int) == { before: [], after: [] } - assert $ A.splitAt 3 [1, 2, 3, 4, 5] == { before: [1, 2, 3], after: [4, 5] } - assert $ A.splitAt 1 [1, 2, 3] == { before: [1], after: [2, 3] } - assert $ A.splitAt 3 [1, 2, 3] == { before: [1, 2, 3], after: [] } - assert $ A.splitAt 4 [1, 2, 3] == { before: [1, 2, 3], after: [] } - assert $ A.splitAt 0 [1, 2, 3] == { before: [], after: [1, 2, 3] } - assert $ A.splitAt (-1) [1, 2, 3] == { before: [], after: [1, 2, 3] } + assert $ A.splitAt 3 [ 1, 2, 3, 4, 5 ] == { before: [ 1, 2, 3 ], after: [ 4, 5 ] } + assert $ A.splitAt 1 [ 1, 2, 3 ] == { before: [ 1 ], after: [ 2, 3 ] } + assert $ A.splitAt 3 [ 1, 2, 3 ] == { before: [ 1, 2, 3 ], after: [] } + assert $ A.splitAt 4 [ 1, 2, 3 ] == { before: [ 1, 2, 3 ], after: [] } + assert $ A.splitAt 0 [ 1, 2, 3 ] == { before: [], after: [ 1, 2, 3 ] } + assert $ A.splitAt (-1) [ 1, 2, 3 ] == { before: [], after: [ 1, 2, 3 ] } log "filterA should remove items that don't match a predicate while using an applicative behaviour" - assert $ A.filterA (Just <<< odd) (A.range 0 10) == Just [1, 3, 5, 7, 9] + assert $ A.filterA (Just <<< odd) (A.range 0 10) == Just [ 1, 3, 5, 7, 9 ] assert $ A.filterA (const Nothing) (A.range 0 10) == Nothing log "filterA should apply effects in the right order" assert $ A.filterA (Const <<< show) (A.range 1 5) == Const "12345" log "mapMaybe should transform every item in an array, throwing out Nothing values" - assert $ A.mapMaybe (\x -> if x /= 0 then Just x else Nothing) [0, 1, 0, 0, 2, 3] == [1, 2, 3] + assert $ A.mapMaybe (\x -> if x /= 0 then Just x else Nothing) [ 0, 1, 0, 0, 2, 3 ] == [ 1, 2, 3 ] log "catMaybe should take an array of Maybe values and throw out Nothings" - assert $ A.catMaybes [Nothing, Just 2, Nothing, Just 4] == [2, 4] + assert $ A.catMaybes [ Nothing, Just 2, Nothing, Just 4 ] == [ 2, 4 ] log "mapWithIndex applies a function with an index for every element" - assert $ A.mapWithIndex (\i x -> x - i) [9,8,7,6,5] == [9,7,5,3,1] + assert $ A.mapWithIndex (\i x -> x - i) [ 9, 8, 7, 6, 5 ] == [ 9, 7, 5, 3, 1 ] log "updateAtIndices changes the elements at specified indices" - assert $ A.updateAtIndices - [Tuple 0 false, Tuple 2 false, Tuple 8 false] - [true, true, true, true] == - [false, true, false, true] + assert $ + A.updateAtIndices + [ Tuple 0 false, Tuple 2 false, Tuple 8 false ] + [ true, true, true, true ] == + [ false, true, false, true ] log "modifyAtIndices modifies the elements at specified indices" - assert $ A.modifyAtIndices [0, 2, 8] not [true, true, true, true] == - [false, true, false, true] + assert $ A.modifyAtIndices [ 0, 2, 8 ] not [ true, true, true, true ] == + [ false, true, false, true ] log "transpose swaps rows and columns for a regular two-dimension array" - assert $ A.transpose [[1,2,3], [4,5,6], [7,8,9]] == - [[1,4,7], [2,5,8], [3,6,9]] - + assert $ A.transpose [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] == + [ [ 1, 4, 7 ], [ 2, 5, 8 ], [ 3, 6, 9 ] ] + log "transpose skips elements when rows don't match" - assert $ A.transpose [[10,11], [20], [30,31,32]] == - [[10,20,30], [11,31], [32]] + assert $ A.transpose [ [ 10, 11 ], [ 20 ], [ 30, 31, 32 ] ] == + [ [ 10, 20, 30 ], [ 11, 31 ], [ 32 ] ] log "transpose [] == []" assert $ A.transpose [] == ([] :: Array (Array Int)) log "transpose (singleton []) == []" - assert $ A.transpose (A.singleton []) == ([] :: Array (Array Int)) + assert $ A.transpose (A.singleton []) == ([] :: Array (Array Int)) log "scanl should return an array that stores the accumulated value at each step" - assert $ A.scanl (+) 0 [1,2,3] == [1, 3, 6] - assert $ A.scanl (-) 10 [1,2,3] == [9, 7, 4] + assert $ A.scanl (+) 0 [ 1, 2, 3 ] == [ 1, 3, 6 ] + assert $ A.scanl (-) 10 [ 1, 2, 3 ] == [ 9, 7, 4 ] log "scanl should return the same results as its Foldable counterpart" - assert $ A.scanl (+) 0 [1,2,3] == scanl (+) 0 [1,2,3] - assert $ A.scanl (-) 10 [1,2,3] == scanl (-) 10 [1,2,3] + assert $ A.scanl (+) 0 [ 1, 2, 3 ] == scanl (+) 0 [ 1, 2, 3 ] + assert $ A.scanl (-) 10 [ 1, 2, 3 ] == scanl (-) 10 [ 1, 2, 3 ] log "scanr should return an array that stores the accumulated value at each step" - assert $ A.scanr (+) 0 [1,2,3] == [6,5,3] - assert $ A.scanr (flip (-)) 10 [1,2,3] == [4,5,7] + assert $ A.scanr (+) 0 [ 1, 2, 3 ] == [ 6, 5, 3 ] + assert $ A.scanr (flip (-)) 10 [ 1, 2, 3 ] == [ 4, 5, 7 ] log "scanr should return the same results as its Foldable counterpart" - assert $ A.scanr (+) 0 [1,2,3] == scanr (+) 0 [1,2,3] - assert $ A.scanr (flip (-)) 10 [1,2,3] == scanr (flip (-)) 10 [1,2,3] + assert $ A.scanr (+) 0 [ 1, 2, 3 ] == scanr (+) 0 [ 1, 2, 3 ] + assert $ A.scanr (flip (-)) 10 [ 1, 2, 3 ] == scanr (flip (-)) 10 [ 1, 2, 3 ] log "sort should reorder a list into ascending order based on the result of compare" - assert $ A.sort [1, 3, 2, 5, 6, 4] == [1, 2, 3, 4, 5, 6] - assert $ A.sort [defined 1, undefined, defined 2] == [undefined, defined 1, defined 2] + assert $ A.sort [ 1, 3, 2, 5, 6, 4 ] == [ 1, 2, 3, 4, 5, 6 ] + assert $ A.sort [ defined 1, undefined, defined 2 ] == [ undefined, defined 1, defined 2 ] log "sortBy should reorder a list into ascending order based on the result of a comparison function" - assert $ A.sortBy (flip compare) [1, 3, 2, 5, 6, 4] == [6, 5, 4, 3, 2, 1] + assert $ A.sortBy (flip compare) [ 1, 3, 2, 5, 6, 4 ] == [ 6, 5, 4, 3, 2, 1 ] log "sortBy should not reorder elements that are equal according to a comparison function" let s1 = map (Tuple "a") (A.range 1 100) assert $ A.sortBy (comparing fst) s1 == s1 log "sortWith should reorder a list into ascending order based on the result of compare over a projection" - assert $ A.sortWith identity [1, 3, 2, 5, 6, 4] == [1, 2, 3, 4, 5, 6] + assert $ A.sortWith identity [ 1, 3, 2, 5, 6, 4 ] == [ 1, 2, 3, 4, 5, 6 ] log "sortWith should not reorder elements that are equal according to a projection" let s2 = map (Tuple "a") (A.range 1 100) assert $ A.sortWith fst s2 == s2 log "take should keep the specified number of items from the front of an array, discarding the rest" - assert $ (A.take 1 [1, 2, 3]) == [1] - assert $ (A.take 2 [1, 2, 3]) == [1, 2] + assert $ (A.take 1 [ 1, 2, 3 ]) == [ 1 ] + assert $ (A.take 2 [ 1, 2, 3 ]) == [ 1, 2 ] assert $ (A.take 1 nil) == nil log "takeWhile should keep all values that match a predicate from the front of an array" - assert $ (A.takeWhile (_ /= 2) [1, 2, 3]) == [1] - assert $ (A.takeWhile (_ /= 3) [1, 2, 3]) == [1, 2] + assert $ (A.takeWhile (_ /= 2) [ 1, 2, 3 ]) == [ 1 ] + assert $ (A.takeWhile (_ /= 3) [ 1, 2, 3 ]) == [ 1, 2 ] assert $ (A.takeWhile (_ /= 1) nil) == nil log "take should keep the specified number of items from the end of an array, discarding the rest" - assert $ (A.takeEnd 1 [1, 2, 3]) == [3] - assert $ (A.takeEnd 2 [1, 2, 3]) == [2, 3] + assert $ (A.takeEnd 1 [ 1, 2, 3 ]) == [ 3 ] + assert $ (A.takeEnd 2 [ 1, 2, 3 ]) == [ 2, 3 ] assert $ (A.takeEnd 1 nil) == nil log "drop should remove the specified number of items from the front of an array" - assert $ (A.drop 1 [1, 2, 3]) == [2, 3] - assert $ (A.drop 2 [1, 2, 3]) == [3] + assert $ (A.drop 1 [ 1, 2, 3 ]) == [ 2, 3 ] + assert $ (A.drop 2 [ 1, 2, 3 ]) == [ 3 ] assert $ (A.drop 1 nil) == nil log "dropWhile should remove all values that match a predicate from the front of an array" - assert $ (A.dropWhile (_ /= 1) [1, 2, 3]) == [1, 2, 3] - assert $ (A.dropWhile (_ /= 2) [1, 2, 3]) == [2, 3] + assert $ (A.dropWhile (_ /= 1) [ 1, 2, 3 ]) == [ 1, 2, 3 ] + assert $ (A.dropWhile (_ /= 2) [ 1, 2, 3 ]) == [ 2, 3 ] assert $ (A.dropWhile (_ /= 1) nil) == nil log "drop should remove the specified number of items from the end of an array" - assert $ (A.dropEnd 1 [1, 2, 3]) == [1, 2] - assert $ (A.dropEnd 2 [1, 2, 3]) == [1] + assert $ (A.dropEnd 1 [ 1, 2, 3 ]) == [ 1, 2 ] + assert $ (A.dropEnd 2 [ 1, 2, 3 ]) == [ 1 ] assert $ (A.dropEnd 1 nil) == nil log "take and drop should treat negative arguments as zero" - assert $ (A.take (-2) [1, 2, 3]) == nil - assert $ (A.drop (-2) [1, 2, 3]) == [1, 2, 3] + assert $ (A.take (-2) [ 1, 2, 3 ]) == nil + assert $ (A.drop (-2) [ 1, 2, 3 ]) == [ 1, 2, 3 ] log "span should split an array in two based on a predicate" - let testSpan { p, input, init_, rest_ } = do - let result = A.span p input - assert $ result.init == init_ - assert $ result.rest == rest_ + let + testSpan { p, input, init_, rest_ } = do + let result = A.span p input + assert $ result.init == init_ + assert $ result.rest == rest_ - let oneToSeven = [1, 2, 3, 4, 5, 6, 7] - testSpan { p: (_ < 4), input: oneToSeven, init_: [1, 2, 3], rest_: [4, 5, 6, 7] } + let oneToSeven = [ 1, 2, 3, 4, 5, 6, 7 ] + testSpan { p: (_ < 4), input: oneToSeven, init_: [ 1, 2, 3 ], rest_: [ 4, 5, 6, 7 ] } log "span with all elements satisfying the predicate" testSpan { p: const true, input: oneToSeven, init_: oneToSeven, rest_: [] } @@ -363,8 +365,9 @@ testArray = do testSpan { p: const false, input: oneToSeven, init_: [], rest_: oneToSeven } log "span with large inputs: 10000" - let testBigSpan n = - testSpan { p: (_ < n), input: A.range 1 n, init_: A.range 1 (n-1), rest_: [n] } + let + testBigSpan n = + testSpan { p: (_ < n), input: A.range 1 n, init_: A.range 1 (n - 1), rest_: [ n ] } testBigSpan 10000 log "span with large inputs: 40000" @@ -374,98 +377,98 @@ testArray = do testBigSpan 100000 log "group should group consecutive equal elements into arrays" - assert $ A.group [1, 2, 2, 3, 3, 3, 1] == [nea [1], nea [2, 2], nea [3, 3, 3], nea [1]] + assert $ A.group [ 1, 2, 2, 3, 3, 3, 1 ] == [ nea [ 1 ], nea [ 2, 2 ], nea [ 3, 3, 3 ], nea [ 1 ] ] log "groupAll should group equal elements into arrays" - assert $ A.groupAll [1, 2, 2, 3, 3, 3, 1] == [nea [1, 1], nea [2, 2], nea [3, 3, 3]] + assert $ A.groupAll [ 1, 2, 2, 3, 3, 3, 1 ] == [ nea [ 1, 1 ], nea [ 2, 2 ], nea [ 3, 3, 3 ] ] log "groupBy should group consecutive equal elements into arrays based on an equivalence relation" - assert $ A.groupBy (\x y -> odd x && odd y) [1, 1, 2, 2, 3, 3] == [nea [1, 1], nea [2], nea [2], nea [3, 3]] + assert $ A.groupBy (\x y -> odd x && odd y) [ 1, 1, 2, 2, 3, 3 ] == [ nea [ 1, 1 ], nea [ 2 ], nea [ 2 ], nea [ 3, 3 ] ] log "groupBy should be stable" - assert $ A.groupBy (\_ _ -> true) [1, 2, 3] == [nea [1, 2, 3]] + assert $ A.groupBy (\_ _ -> true) [ 1, 2, 3 ] == [ nea [ 1, 2, 3 ] ] log "groupAllBy should group equal elements into arrays based on the result of a comparison function" - assert $ A.groupAllBy (comparing Down) [1, 3, 2, 4, 3, 3] == [nea [4], nea [3, 3, 3], nea [2], nea [1]] + assert $ A.groupAllBy (comparing Down) [ 1, 3, 2, 4, 3, 3 ] == [ nea [ 4 ], nea [ 3, 3, 3 ], nea [ 2 ], nea [ 1 ] ] log "groupAllBy should be stable" - assert $ A.groupAllBy (\_ _ -> EQ) [1, 2, 3] == [nea [1, 2, 3]] + assert $ A.groupAllBy (\_ _ -> EQ) [ 1, 2, 3 ] == [ nea [ 1, 2, 3 ] ] log "nub should remove duplicate elements from the list, keeping the first occurence" - assert $ A.nub [1, 2, 2, 3, 4, 1] == [1, 2, 3, 4] + assert $ A.nub [ 1, 2, 2, 3, 4, 1 ] == [ 1, 2, 3, 4 ] log "nub should preserve order" - assert $ A.nub [1, 3, 4, 2, 2, 1] == [1, 3, 4, 2] + assert $ A.nub [ 1, 3, 4, 2, 2, 1 ] == [ 1, 3, 4, 2 ] log "nubEq should remove duplicate elements from the list, keeping the first occurence" - assert $ A.nubEq [1, 2, 2, 3, 4, 1] == [1, 2, 3, 4] + assert $ A.nubEq [ 1, 2, 2, 3, 4, 1 ] == [ 1, 2, 3, 4 ] log "nubEq should preserve order" - assert $ A.nubEq [1, 3, 4, 2, 2, 1] == [1, 3, 4, 2] + assert $ A.nubEq [ 1, 3, 4, 2, 2, 1 ] == [ 1, 3, 4, 2 ] log "nubBy should remove duplicate items from the list using a supplied predicate" - assert $ A.nubBy compare [1, 3, 4, 2, 2, 1] == [1, 3, 4, 2] + assert $ A.nubBy compare [ 1, 3, 4, 2, 2, 1 ] == [ 1, 3, 4, 2 ] log "nubByEq should remove duplicate items from the list using a supplied predicate" let nubPred = \x y -> if odd x then false else x == y - assert $ A.nubByEq nubPred [1, 2, 2, 3, 3, 4, 4, 1] == [1, 2, 3, 3, 4, 1] + assert $ A.nubByEq nubPred [ 1, 2, 2, 3, 3, 4, 4, 1 ] == [ 1, 2, 3, 3, 4, 1 ] log "union should produce the union of two arrays" - assert $ A.union [1, 2, 3] [2, 3, 4] == [1, 2, 3, 4] - assert $ A.union [1, 1, 2, 3] [2, 3, 4] == [1, 1, 2, 3, 4] + assert $ A.union [ 1, 2, 3 ] [ 2, 3, 4 ] == [ 1, 2, 3, 4 ] + assert $ A.union [ 1, 1, 2, 3 ] [ 2, 3, 4 ] == [ 1, 1, 2, 3, 4 ] log "unionBy should produce the union of two arrays using the specified equality relation" - assert $ A.unionBy (\_ y -> y < 5) [1, 2, 3] [2, 3, 4, 5, 6] == [1, 2, 3, 5, 6] + assert $ A.unionBy (\_ y -> y < 5) [ 1, 2, 3 ] [ 2, 3, 4, 5, 6 ] == [ 1, 2, 3, 5, 6 ] log "delete should remove the first matching item from an array" - assert $ A.delete 1 [1, 2, 1] == [2, 1] - assert $ A.delete 2 [1, 2, 1] == [1, 1] + assert $ A.delete 1 [ 1, 2, 1 ] == [ 2, 1 ] + assert $ A.delete 2 [ 1, 2, 1 ] == [ 1, 1 ] log "deleteBy should remove the first equality-relation-matching item from an array" - assert $ A.deleteBy (/=) 2 [1, 2, 1] == [2, 1] - assert $ A.deleteBy (/=) 1 [1, 2, 1] == [1, 1] + assert $ A.deleteBy (/=) 2 [ 1, 2, 1 ] == [ 2, 1 ] + assert $ A.deleteBy (/=) 1 [ 1, 2, 1 ] == [ 1, 1 ] log "(\\\\) should return the difference between two lists" - assert $ [1, 2, 3, 4, 3, 2, 1] \\ [1, 1, 2, 3] == [4, 3, 2] + assert $ [ 1, 2, 3, 4, 3, 2, 1 ] \\ [ 1, 1, 2, 3 ] == [ 4, 3, 2 ] log "intersect should return the intersection of two arrays" - assert $ A.intersect [1, 2, 3, 4, 3, 2, 1] [1, 1, 2, 3] == [1, 2, 3, 3, 2, 1] + assert $ A.intersect [ 1, 2, 3, 4, 3, 2, 1 ] [ 1, 1, 2, 3 ] == [ 1, 2, 3, 3, 2, 1 ] log "intersectBy should return the intersection of two arrays using the specified equivalence relation" - assert $ A.intersectBy (\x y -> (x * 2) == y) [1, 2, 3] [2, 6] == [1, 3] + assert $ A.intersectBy (\x y -> (x * 2) == y) [ 1, 2, 3 ] [ 2, 6 ] == [ 1, 3 ] log "zipWith should use the specified function to zip two lists together" - assert $ A.zipWith (\x y -> [show x, y]) [1, 2, 3] ["a", "b", "c"] == [["1", "a"], ["2", "b"], ["3", "c"]] + assert $ A.zipWith (\x y -> [ show x, y ]) [ 1, 2, 3 ] [ "a", "b", "c" ] == [ [ "1", "a" ], [ "2", "b" ], [ "3", "c" ] ] log "zipWithA should use the specified function to zip two lists together" - assert $ A.zipWithA (\x y -> Just $ Tuple x y) [1, 2, 3] ["a", "b", "c"] == Just [Tuple 1 "a", Tuple 2 "b", Tuple 3 "c"] + assert $ A.zipWithA (\x y -> Just $ Tuple x y) [ 1, 2, 3 ] [ "a", "b", "c" ] == Just [ Tuple 1 "a", Tuple 2 "b", Tuple 3 "c" ] log "zip should use the specified function to zip two lists together" - assert $ A.zip [1, 2, 3] ["a", "b", "c"] == [Tuple 1 "a", Tuple 2 "b", Tuple 3 "c"] + assert $ A.zip [ 1, 2, 3 ] [ "a", "b", "c" ] == [ Tuple 1 "a", Tuple 2 "b", Tuple 3 "c" ] log "unzip should deconstruct a list of tuples into a tuple of lists" - assert $ A.unzip [Tuple 1 "a", Tuple 2 "b", Tuple 3 "c"] == Tuple [1, 2, 3] ["a", "b", "c"] + assert $ A.unzip [ Tuple 1 "a", Tuple 2 "b", Tuple 3 "c" ] == Tuple [ 1, 2, 3 ] [ "a", "b", "c" ] log "any should return true if at least one array element satisfy the given predicate" assert $ not $ A.any (_ > 0) [] - assert $ A.any (_ > 0) [-1, 0, 1] - assert $ not $ A.any (_ > 0) [-1, -2, -3] + assert $ A.any (_ > 0) [ -1, 0, 1 ] + assert $ not $ A.any (_ > 0) [ -1, -2, -3 ] log "all should return true if all the array elements satisfy the given predicate" assert $ A.all (_ > 0) [] - assert $ A.all (_ > 0) [1, 2, 3] - assert $ not $ A.all (_ > 0) [-1, -2, -3] + assert $ A.all (_ > 0) [ 1, 2, 3 ] + assert $ not $ A.all (_ > 0) [ -1, -2, -3 ] log "foldM should perform a fold using a monadic step function" assert $ A.foldM (\x y -> Just (x + y)) 0 (A.range 1 10) == Just 55 assert $ A.foldM (\_ _ -> Nothing) 0 (A.range 1 10) == Nothing log "fromFoldable" - for_ [[], [1], [1,2], [1,2,3,4,5]] \xs -> do + for_ [ [], [ 1 ], [ 1, 2 ], [ 1, 2, 3, 4, 5 ] ] \xs -> do assert $ A.fromFoldable xs == xs log "fromFoldable is stack safe" - for_ [1, 1000, 10000, 20000, 50000] \n -> do + for_ [ 1, 1000, 10000, 20000, 50000 ] \n -> do let elem = 0 let arr = A.fromFoldable (Replicated n elem) assert $ A.length arr == n @@ -475,10 +478,10 @@ testArray = do let toUnfoldableId xs = A.toUnfoldable xs == xs traverse_ (assert <<< toUnfoldableId) [ [] - , [1] - , [1,2,3] - , [2,3,1] - , [4,0,0,1,25,36,458,5842,23757] + , [ 1 ] + , [ 1, 2, 3 ] + , [ 2, 3, 1 ] + , [ 4, 0, 0, 1, 25, 36, 458, 5842, 23757 ] ] nea :: Array ~> NEA.NonEmptyArray @@ -491,7 +494,7 @@ odd :: Int -> Boolean odd n = n `mod` 2 /= zero doubleAndOrig :: Int -> Array Int -doubleAndOrig x = [x * 2, x] +doubleAndOrig x = [ x * 2, x ] data Replicated a = Replicated Int a @@ -502,5 +505,5 @@ instance foldableReplicated :: Foldable Replicated where applyN :: forall a. Int -> (a -> a) -> a -> a applyN n f x - | n <= 0 = x + | n <= 0 = x | otherwise = applyN (n - 1) f (f x) diff --git a/test/Test/Data/Array/NonEmpty.purs b/test/Test/Data/Array/NonEmpty.purs index 0ee98550..0bc9e1fb 100644 --- a/test/Test/Data/Array/NonEmpty.purs +++ b/test/Test/Data/Array/NonEmpty.purs @@ -6,13 +6,13 @@ import Data.Array as A import Data.Array.NonEmpty as NEA import Data.Const (Const(..)) import Data.Foldable (for_, sum, traverse_) -import Data.Traversable (scanl, scanr) import Data.Maybe (Maybe(..), fromJust) import Data.Monoid.Additive (Additive(..)) import Data.NonEmpty ((:|)) import Data.Ord.Down (Down(..)) -import Data.Semigroup.Foldable (foldMap1, foldr1, foldl1) +import Data.Semigroup.Foldable (foldMap1, foldl1, foldr1) import Data.Semigroup.Traversable (traverse1) +import Data.Traversable (scanl, scanr) import Data.Tuple (Tuple(..)) import Data.Unfoldable1 as U1 import Effect (Effect) @@ -23,154 +23,155 @@ import Test.Data.UndefinedOr (defined, undefined) testNonEmptyArray :: Effect Unit testNonEmptyArray = do - let fromArray :: forall a. Array a -> NEA.NonEmptyArray a - fromArray = unsafePartial fromJust <<< NEA.fromArray + let + fromArray :: forall a. Array a -> NEA.NonEmptyArray a + fromArray = unsafePartial fromJust <<< NEA.fromArray - nea :: forall a. Array a -> NEA.NonEmptyArray a - nea = fromArray + nea :: forall a. Array a -> NEA.NonEmptyArray a + nea = fromArray log "singleton should construct an array with a single value" - assert $ NEA.toArray (NEA.singleton 1) == [1] - assert $ NEA.toArray (NEA.singleton "foo") == ["foo"] + assert $ NEA.toArray (NEA.singleton 1) == [ 1 ] + assert $ NEA.toArray (NEA.singleton "foo") == [ "foo" ] log "range should create an inclusive array of integers for the specified start and end" - assert $ NEA.toArray (NEA.range 0 5) == [0, 1, 2, 3, 4, 5] - assert $ NEA.toArray (NEA.range 2 (-3)) == [2, 1, 0, -1, -2, -3] - assert $ NEA.toArray (NEA.range 0 0) == [0] + assert $ NEA.toArray (NEA.range 0 5) == [ 0, 1, 2, 3, 4, 5 ] + assert $ NEA.toArray (NEA.range 2 (-3)) == [ 2, 1, 0, -1, -2, -3 ] + assert $ NEA.toArray (NEA.range 0 0) == [ 0 ] log "replicate should produce an array containg an item a specified number of times" - assert $ NEA.toArray (NEA.replicate 3 true) == [true, true, true] - assert $ NEA.toArray (NEA.replicate 1 "foo") == ["foo"] - assert $ NEA.toArray (NEA.replicate 0 "foo") == ["foo"] - assert $ NEA.toArray (NEA.replicate (-1) "foo") == ["foo"] + assert $ NEA.toArray (NEA.replicate 3 true) == [ true, true, true ] + assert $ NEA.toArray (NEA.replicate 1 "foo") == [ "foo" ] + assert $ NEA.toArray (NEA.replicate 0 "foo") == [ "foo" ] + assert $ NEA.toArray (NEA.replicate (-1) "foo") == [ "foo" ] log "length should return the number of items in an array" assert $ NEA.length (NEA.singleton 1) == 1 - assert $ NEA.length (fromArray [1, 2, 3, 4, 5]) == 5 + assert $ NEA.length (fromArray [ 1, 2, 3, 4, 5 ]) == 5 log "cons should add an item to the start of an array" - assert $ NEA.cons 4 (fromArray [1, 2, 3]) == fromArray [4, 1, 2, 3] - assert $ NEA.cons' 4 [1, 2, 3] == fromArray [4, 1, 2, 3] + assert $ NEA.cons 4 (fromArray [ 1, 2, 3 ]) == fromArray [ 4, 1, 2, 3 ] + assert $ NEA.cons' 4 [ 1, 2, 3 ] == fromArray [ 4, 1, 2, 3 ] log "snoc should add an item to the end of an array" - assert $ fromArray [1, 2, 3] `NEA.snoc` 4 == fromArray [1, 2, 3, 4] - assert $ [1, 2, 3] `NEA.snoc'` 4 == fromArray [1, 2, 3, 4] + assert $ fromArray [ 1, 2, 3 ] `NEA.snoc` 4 == fromArray [ 1, 2, 3, 4 ] + assert $ [ 1, 2, 3 ] `NEA.snoc'` 4 == fromArray [ 1, 2, 3, 4 ] log "insert should add an item at the appropriate place in a sorted array" - assert $ NEA.insert 1.5 (fromArray [1.0, 2.0, 3.0]) - == fromArray [1.0, 1.5, 2.0, 3.0] - assert $ NEA.insert 4 (fromArray [1, 2, 3]) == fromArray [1, 2, 3, 4] + assert $ NEA.insert 1.5 (fromArray [ 1.0, 2.0, 3.0 ]) + == fromArray [ 1.0, 1.5, 2.0, 3.0 ] + assert $ NEA.insert 4 (fromArray [ 1, 2, 3 ]) == fromArray [ 1, 2, 3, 4 ] log "insertBy should add an item at the appropriate place in a sorted array using the specified comparison" - assert $ NEA.insertBy (flip compare) 1.5 (fromArray [1.0, 2.0, 3.0]) - == fromArray [1.0, 2.0, 3.0, 1.5] + assert $ NEA.insertBy (flip compare) 1.5 (fromArray [ 1.0, 2.0, 3.0 ]) + == fromArray [ 1.0, 2.0, 3.0, 1.5 ] log "head should return the first value of a non-empty array" - assert $ NEA.head (fromArray ["foo", "bar"]) == "foo" + assert $ NEA.head (fromArray [ "foo", "bar" ]) == "foo" log "last should return the last value of a non-empty array" - assert $ NEA.last (fromArray ["foo", "bar"]) == "bar" + assert $ NEA.last (fromArray [ "foo", "bar" ]) == "bar" log "tail should return an array containing all the items in an array apart from the first for a non-empty array" - assert $ NEA.tail (fromArray ["foo", "bar", "baz"]) == ["bar", "baz"] + assert $ NEA.tail (fromArray [ "foo", "bar", "baz" ]) == [ "bar", "baz" ] log "init should return an array containing all the items in an array apart from the first for a non-empty array" - assert $ NEA.init (fromArray ["foo", "bar", "baz"]) == ["foo", "bar"] + assert $ NEA.init (fromArray [ "foo", "bar", "baz" ]) == [ "foo", "bar" ] log "uncons should split an array into a head and tail record" let u1 = NEA.uncons $ NEA.singleton 1 assert $ u1.head == 1 assert $ u1.tail == [] - let u2 = NEA.uncons $ fromArray [1, 2, 3] + let u2 = NEA.uncons $ fromArray [ 1, 2, 3 ] assert $ u2.head == 1 - assert $ u2.tail == [2, 3] + assert $ u2.tail == [ 2, 3 ] log "unsnoc should split an array into an init and last record" let u3 = NEA.unsnoc $ NEA.singleton 1 assert $ u3.init == [] assert $ u3.last == 1 - let u4 = NEA.unsnoc $ fromArray [1, 2, 3] - assert $ u4.init == [1, 2] + let u4 = NEA.unsnoc $ fromArray [ 1, 2, 3 ] + assert $ u4.init == [ 1, 2 ] assert $ u4.last == 3 log "index should return Just x when the index is within the bounds of the array" - assert $ NEA.index (fromArray [1, 2, 3]) 0 == Just 1 - assert $ NEA.index (fromArray [1, 2, 3]) 1 == Just 2 - assert $ NEA.index (fromArray [1, 2, 3]) 2 == Just 3 + assert $ NEA.index (fromArray [ 1, 2, 3 ]) 0 == Just 1 + assert $ NEA.index (fromArray [ 1, 2, 3 ]) 1 == Just 2 + assert $ NEA.index (fromArray [ 1, 2, 3 ]) 2 == Just 3 log "index should return Nothing when the index is outside of the bounds of the array" - assert $ NEA.index (fromArray [1, 2, 3]) 6 == Nothing - assert $ NEA.index (fromArray [1, 2, 3]) (-1) == Nothing + assert $ NEA.index (fromArray [ 1, 2, 3 ]) 6 == Nothing + assert $ NEA.index (fromArray [ 1, 2, 3 ]) (-1) == Nothing log "elem should return true if the array contains the given element at least once" - assert $ NEA.elem 1 (fromArray [1, 2, 1]) == true - assert $ NEA.elem 4 (fromArray [1, 2, 1]) == false + assert $ NEA.elem 1 (fromArray [ 1, 2, 1 ]) == true + assert $ NEA.elem 4 (fromArray [ 1, 2, 1 ]) == false log "notElem should return true if the array does not contain the given element" - assert $ NEA.notElem 1 (fromArray [1, 2, 1]) == false - assert $ NEA.notElem 4 (fromArray [1, 2, 1]) == true + assert $ NEA.notElem 1 (fromArray [ 1, 2, 1 ]) == false + assert $ NEA.notElem 4 (fromArray [ 1, 2, 1 ]) == true log "elemIndex should return the index of an item that a predicate returns true for in an array" - assert $ NEA.elemIndex 1 (fromArray [1, 2, 1]) == Just 0 - assert $ NEA.elemIndex 4 (fromArray [1, 2, 1]) == Nothing + assert $ NEA.elemIndex 1 (fromArray [ 1, 2, 1 ]) == Just 0 + assert $ NEA.elemIndex 4 (fromArray [ 1, 2, 1 ]) == Nothing log "elemLastIndex should return the last index of an item in an array" - assert $ NEA.elemLastIndex 1 (fromArray [1, 2, 1]) == Just 2 - assert $ NEA.elemLastIndex 4 (fromArray [1, 2, 1]) == Nothing + assert $ NEA.elemLastIndex 1 (fromArray [ 1, 2, 1 ]) == Just 2 + assert $ NEA.elemLastIndex 4 (fromArray [ 1, 2, 1 ]) == Nothing log "find should return the first element for which a predicate returns true in an array" - assert $ NEA.find (_ == 1) (fromArray [1, 2, 1]) == Just 1 - assert $ NEA.find (_ == 3) (fromArray [1, 2, 1]) == Nothing + assert $ NEA.find (_ == 1) (fromArray [ 1, 2, 1 ]) == Just 1 + assert $ NEA.find (_ == 3) (fromArray [ 1, 2, 1 ]) == Nothing log "findMap should return the mapping of the first element that satisfies the given predicate" - assert $ NEA.findMap (\x -> if x > 3 then Just x else Nothing) (fromArray [1, 2, 4]) == Just 4 - assert $ NEA.findMap (\x -> if x > 3 then Just x else Nothing) (fromArray [1, 2, 1]) == Nothing - assert $ NEA.findMap (\x -> if x > 3 then Just x else Nothing) (fromArray [4, 1, 5]) == Just 4 + assert $ NEA.findMap (\x -> if x > 3 then Just x else Nothing) (fromArray [ 1, 2, 4 ]) == Just 4 + assert $ NEA.findMap (\x -> if x > 3 then Just x else Nothing) (fromArray [ 1, 2, 1 ]) == Nothing + assert $ NEA.findMap (\x -> if x > 3 then Just x else Nothing) (fromArray [ 4, 1, 5 ]) == Just 4 log "findIndex should return the index of an item that a predicate returns true for in an array" - assert $ (NEA.findIndex (_ /= 1) (fromArray [1, 2, 1])) == Just 1 - assert $ (NEA.findIndex (_ == 3) (fromArray [1, 2, 1])) == Nothing + assert $ (NEA.findIndex (_ /= 1) (fromArray [ 1, 2, 1 ])) == Just 1 + assert $ (NEA.findIndex (_ == 3) (fromArray [ 1, 2, 1 ])) == Nothing log "findLastIndex should return the last index of an item in an array" - assert $ (NEA.findLastIndex (_ /= 1) (fromArray [2, 1, 2])) == Just 2 - assert $ (NEA.findLastIndex (_ == 3) (fromArray [2, 1, 2])) == Nothing + assert $ (NEA.findLastIndex (_ /= 1) (fromArray [ 2, 1, 2 ])) == Just 2 + assert $ (NEA.findLastIndex (_ == 3) (fromArray [ 2, 1, 2 ])) == Nothing log "insertAt should add an item at the specified index" - assert $ NEA.insertAt 0 1 (fromArray [2, 3]) == Just (fromArray [1, 2, 3]) - assert $ NEA.insertAt 1 1 (fromArray [2, 3]) == Just (fromArray [2, 1, 3]) - assert $ NEA.insertAt 2 1 (fromArray [2, 3]) == Just (fromArray [2, 3, 1]) + assert $ NEA.insertAt 0 1 (fromArray [ 2, 3 ]) == Just (fromArray [ 1, 2, 3 ]) + assert $ NEA.insertAt 1 1 (fromArray [ 2, 3 ]) == Just (fromArray [ 2, 1, 3 ]) + assert $ NEA.insertAt 2 1 (fromArray [ 2, 3 ]) == Just (fromArray [ 2, 3, 1 ]) log "insertAt should return Nothing if the index is out of A.range" assert $ (NEA.insertAt 2 1 (NEA.singleton 1)) == Nothing log "deleteAt should remove an item at the specified index" - assert $ (NEA.deleteAt 0 (fromArray [1, 2, 3])) == Just [2, 3] - assert $ (NEA.deleteAt 1 (fromArray [1, 2, 3])) == Just [1, 3] + assert $ (NEA.deleteAt 0 (fromArray [ 1, 2, 3 ])) == Just [ 2, 3 ] + assert $ (NEA.deleteAt 1 (fromArray [ 1, 2, 3 ])) == Just [ 1, 3 ] log "deleteAt should return Nothing if the index is out of A.range" assert $ (NEA.deleteAt 1 (NEA.singleton 1)) == Nothing log "updateAt should replace an item at the specified index" - assert $ NEA.updateAt 0 9 (fromArray [1, 2, 3]) == Just (fromArray [9, 2, 3]) - assert $ NEA.updateAt 1 9 (fromArray [1, 2, 3]) == Just (fromArray [1, 9, 3]) + assert $ NEA.updateAt 0 9 (fromArray [ 1, 2, 3 ]) == Just (fromArray [ 9, 2, 3 ]) + assert $ NEA.updateAt 1 9 (fromArray [ 1, 2, 3 ]) == Just (fromArray [ 1, 9, 3 ]) log "updateAt should return Nothing if the index is out of A.range" assert $ NEA.updateAt 1 9 (NEA.singleton 0) == Nothing log "modifyAt should update an item at the specified index" - assert $ NEA.modifyAt 0 (_ + 1) (fromArray [1, 2, 3]) == Just (fromArray [2, 2, 3]) - assert $ NEA.modifyAt 1 (_ + 1) (fromArray [1, 2, 3]) == Just (fromArray [1, 3, 3]) + assert $ NEA.modifyAt 0 (_ + 1) (fromArray [ 1, 2, 3 ]) == Just (fromArray [ 2, 2, 3 ]) + assert $ NEA.modifyAt 1 (_ + 1) (fromArray [ 1, 2, 3 ]) == Just (fromArray [ 1, 3, 3 ]) log "modifyAt should return Nothing if the index is out of A.range" assert $ NEA.modifyAt 1 (_ + 1) (NEA.singleton 0) == Nothing log "alterAt should update an item at the specified index when the function returns Just" - assert $ NEA.alterAt 0 (Just <<< (_ + 1)) (fromArray [1, 2, 3]) == Just [2, 2, 3] - assert $ NEA.alterAt 1 (Just <<< (_ + 1)) (fromArray [1, 2, 3]) == Just [1, 3, 3] + assert $ NEA.alterAt 0 (Just <<< (_ + 1)) (fromArray [ 1, 2, 3 ]) == Just [ 2, 2, 3 ] + assert $ NEA.alterAt 1 (Just <<< (_ + 1)) (fromArray [ 1, 2, 3 ]) == Just [ 1, 3, 3 ] log "alterAt should drop an item at the specified index when the function returns Nothing" - assert $ NEA.alterAt 0 (const Nothing) (fromArray [1, 2, 3]) == Just [2, 3] - assert $ NEA.alterAt 1 (const Nothing) (fromArray [1, 2, 3]) == Just [1, 3] + assert $ NEA.alterAt 0 (const Nothing) (fromArray [ 1, 2, 3 ]) == Just [ 2, 3 ] + assert $ NEA.alterAt 1 (const Nothing) (fromArray [ 1, 2, 3 ]) == Just [ 1, 3 ] log "alterAt should return Nothing if the index is out of NEA.range" assert $ NEA.alterAt 1 (Just <<< (_ + 1)) (NEA.singleton 1) == Nothing @@ -179,197 +180,200 @@ testNonEmptyArray = do assert $ NEA.intersperse " " (NEA.singleton "a") == NEA.singleton "a" log "intersperse should insert the given element in-between each element in an array with two or more elements" - assert $ NEA.intersperse " " (fromArray ["a", "b"]) == fromArray ["a", " ", "b"] + assert $ NEA.intersperse " " (fromArray [ "a", "b" ]) == fromArray [ "a", " ", "b" ] assert $ NEA.intersperse 0 (fromArray [ 1, 2, 3, 4, 5 ]) == fromArray [ 1, 0, 2, 0, 3, 0, 4, 0, 5 ] log "reverse should reverse the order of items in an array" - assert $ NEA.reverse (fromArray [1, 2, 3]) == fromArray [3, 2, 1] + assert $ NEA.reverse (fromArray [ 1, 2, 3 ]) == fromArray [ 3, 2, 1 ] assert $ NEA.reverse (NEA.singleton 0) == NEA.singleton 0 log "concat should join an array of arrays" - assert $ NEA.concat (fromArray [fromArray [1, 2], fromArray [3, 4]]) == fromArray [1, 2, 3, 4] + assert $ NEA.concat (fromArray [ fromArray [ 1, 2 ], fromArray [ 3, 4 ] ]) == fromArray [ 1, 2, 3, 4 ] log "concatMap should be equivalent to (concat <<< map)" - assert $ NEA.concatMap doubleAndOrig (fromArray [1, 2, 3]) == NEA.concat (map doubleAndOrig (fromArray [1, 2, 3])) + assert $ NEA.concatMap doubleAndOrig (fromArray [ 1, 2, 3 ]) == NEA.concat (map doubleAndOrig (fromArray [ 1, 2, 3 ])) log "filter should remove items that don't match a predicate" - assert $ NEA.filter odd (NEA.range 0 10) == [1, 3, 5, 7, 9] + assert $ NEA.filter odd (NEA.range 0 10) == [ 1, 3, 5, 7, 9 ] log "splitAt should split the array at the given number of elements" - assert $ NEA.splitAt 3 (fromArray [1, 2, 3, 4, 5]) == { before: [1, 2, 3], after: [4, 5] } - assert $ NEA.splitAt 1 (fromArray [1, 2, 3]) == { before: [1], after: [2, 3] } - assert $ NEA.splitAt 3 (fromArray [1, 2, 3]) == { before: [1, 2, 3], after: [] } - assert $ NEA.splitAt 4 (fromArray [1, 2, 3]) == { before: [1, 2, 3], after: [] } - assert $ NEA.splitAt 0 (fromArray [1, 2, 3]) == { before: [], after: [1, 2, 3] } - assert $ NEA.splitAt (-1) (fromArray [1, 2, 3]) == { before: [], after: [1, 2, 3] } + assert $ NEA.splitAt 3 (fromArray [ 1, 2, 3, 4, 5 ]) == { before: [ 1, 2, 3 ], after: [ 4, 5 ] } + assert $ NEA.splitAt 1 (fromArray [ 1, 2, 3 ]) == { before: [ 1 ], after: [ 2, 3 ] } + assert $ NEA.splitAt 3 (fromArray [ 1, 2, 3 ]) == { before: [ 1, 2, 3 ], after: [] } + assert $ NEA.splitAt 4 (fromArray [ 1, 2, 3 ]) == { before: [ 1, 2, 3 ], after: [] } + assert $ NEA.splitAt 0 (fromArray [ 1, 2, 3 ]) == { before: [], after: [ 1, 2, 3 ] } + assert $ NEA.splitAt (-1) (fromArray [ 1, 2, 3 ]) == { before: [], after: [ 1, 2, 3 ] } log "filterA should remove items that don't match a predicate while using an applicative behaviour" - assert $ NEA.filterA (Just <<< odd) (NEA.range 0 10) == Just [1, 3, 5, 7, 9] + assert $ NEA.filterA (Just <<< odd) (NEA.range 0 10) == Just [ 1, 3, 5, 7, 9 ] assert $ NEA.filterA (const Nothing) (NEA.range 0 10) == Nothing log "filterA should apply effects in the right order" assert $ NEA.filterA (Const <<< show) (NEA.range 1 5) == Const "12345" log "mapMaybe should transform every item in an array, throwing out Nothing values" - assert $ NEA.mapMaybe (\x -> if x /= 0 then Just x else Nothing) (fromArray [0, 1, 0, 0, 2, 3]) == [1, 2, 3] + assert $ NEA.mapMaybe (\x -> if x /= 0 then Just x else Nothing) (fromArray [ 0, 1, 0, 0, 2, 3 ]) == [ 1, 2, 3 ] log "catMaybe should take an array of Maybe values and throw out Nothings" - assert $ NEA.catMaybes (fromArray [Nothing, Just 2, Nothing, Just 4]) == [2, 4] + assert $ NEA.catMaybes (fromArray [ Nothing, Just 2, Nothing, Just 4 ]) == [ 2, 4 ] log "mapWithIndex applies a function with an index for every element" - assert $ NEA.mapWithIndex (\i x -> x - i) (fromArray [9,8,7,6,5]) == fromArray [9,7,5,3,1] + assert $ NEA.mapWithIndex (\i x -> x - i) (fromArray [ 9, 8, 7, 6, 5 ]) == fromArray [ 9, 7, 5, 3, 1 ] log "scanl should return an array that stores the accumulated value at each step" - assert $ NEA.scanl (+) 0 (fromArray [1,2,3]) == fromArray [1, 3, 6] - assert $ NEA.scanl (-) 10 (fromArray [1,2,3]) == fromArray [9, 7, 4] + assert $ NEA.scanl (+) 0 (fromArray [ 1, 2, 3 ]) == fromArray [ 1, 3, 6 ] + assert $ NEA.scanl (-) 10 (fromArray [ 1, 2, 3 ]) == fromArray [ 9, 7, 4 ] log "scanl should return the same results as its Foldable counterpart" - assert $ NEA.scanl (+) 0 (fromArray [1,2,3]) == scanl (+) 0 (fromArray [1,2,3]) - assert $ NEA.scanl (-) 10 (fromArray [1,2,3]) == scanl (-) 10 (fromArray [1,2,3]) + assert $ NEA.scanl (+) 0 (fromArray [ 1, 2, 3 ]) == scanl (+) 0 (fromArray [ 1, 2, 3 ]) + assert $ NEA.scanl (-) 10 (fromArray [ 1, 2, 3 ]) == scanl (-) 10 (fromArray [ 1, 2, 3 ]) log "scanr should return an array that stores the accumulated value at each step" - assert $ NEA.scanr (+) 0 (fromArray [1,2,3]) == fromArray [6,5,3] - assert $ NEA.scanr (flip (-)) 10 (fromArray [1,2,3]) == fromArray [4,5,7] + assert $ NEA.scanr (+) 0 (fromArray [ 1, 2, 3 ]) == fromArray [ 6, 5, 3 ] + assert $ NEA.scanr (flip (-)) 10 (fromArray [ 1, 2, 3 ]) == fromArray [ 4, 5, 7 ] log "scanr should return the same results as its Foldable counterpart" - assert $ NEA.scanr (+) 0 (fromArray [1,2,3]) == scanr (+) 0 (fromArray [1,2,3]) - assert $ NEA.scanr (flip (-)) 10 (fromArray [1,2,3]) == scanr (flip (-)) 10 (fromArray [1,2,3]) + assert $ NEA.scanr (+) 0 (fromArray [ 1, 2, 3 ]) == scanr (+) 0 (fromArray [ 1, 2, 3 ]) + assert $ NEA.scanr (flip (-)) 10 (fromArray [ 1, 2, 3 ]) == scanr (flip (-)) 10 (fromArray [ 1, 2, 3 ]) log "updateAtIndices changes the elements at specified indices" - assert $ NEA.updateAtIndices - [Tuple 0 false, Tuple 2 false, Tuple 8 false] - (fromArray [true, true, true, true]) == - fromArray [false, true, false, true] + assert $ + NEA.updateAtIndices + [ Tuple 0 false, Tuple 2 false, Tuple 8 false ] + (fromArray [ true, true, true, true ]) == + fromArray [ false, true, false, true ] log "modifyAtIndices modifies the elements at specified indices" - assert $ NEA.modifyAtIndices [0, 2, 8] not (fromArray [true, true, true, true]) == - (fromArray [false, true, false, true]) + assert $ NEA.modifyAtIndices [ 0, 2, 8 ] not (fromArray [ true, true, true, true ]) == + (fromArray [ false, true, false, true ]) log "sort should reorder a list into ascending order based on the result of compare" - assert $ NEA.sort (fromArray [1, 3, 2, 5, 6, 4]) == fromArray [1, 2, 3, 4, 5, 6] - assert $ NEA.sort (fromArray [defined 1, undefined, defined 2]) == fromArray [undefined, defined 1, defined 2] + assert $ NEA.sort (fromArray [ 1, 3, 2, 5, 6, 4 ]) == fromArray [ 1, 2, 3, 4, 5, 6 ] + assert $ NEA.sort (fromArray [ defined 1, undefined, defined 2 ]) == fromArray [ undefined, defined 1, defined 2 ] log "sortBy should reorder a list into ascending order based on the result of a comparison function" - assert $ NEA.sortBy (flip compare) (fromArray [1, 3, 2, 5, 6, 4]) == fromArray [6, 5, 4, 3, 2, 1] + assert $ NEA.sortBy (flip compare) (fromArray [ 1, 3, 2, 5, 6, 4 ]) == fromArray [ 6, 5, 4, 3, 2, 1 ] log "sortWith should reorder a list into ascending order based on the result of compare over a projection" - assert $ NEA.sortWith identity (fromArray [1, 3, 2, 5, 6, 4]) == fromArray [1, 2, 3, 4, 5, 6] + assert $ NEA.sortWith identity (fromArray [ 1, 3, 2, 5, 6, 4 ]) == fromArray [ 1, 2, 3, 4, 5, 6 ] log "take should keep the specified number of items from the front of an array, discarding the rest" - assert $ NEA.take 1 (fromArray [1, 2, 3]) == [1] - assert $ NEA.take 2 (fromArray [1, 2, 3]) == [1, 2] + assert $ NEA.take 1 (fromArray [ 1, 2, 3 ]) == [ 1 ] + assert $ NEA.take 2 (fromArray [ 1, 2, 3 ]) == [ 1, 2 ] log "takeWhile should keep all values that match a predicate from the front of an array" - assert $ NEA.takeWhile (_ /= 2) (fromArray [1, 2, 3]) == [1] - assert $ NEA.takeWhile (_ /= 3) (fromArray [1, 2, 3]) == [1, 2] + assert $ NEA.takeWhile (_ /= 2) (fromArray [ 1, 2, 3 ]) == [ 1 ] + assert $ NEA.takeWhile (_ /= 3) (fromArray [ 1, 2, 3 ]) == [ 1, 2 ] log "take should keep the specified number of items from the end of an array, discarding the rest" - assert $ NEA.takeEnd 1 (fromArray [1, 2, 3]) == [3] - assert $ NEA.takeEnd 2 (fromArray [1, 2, 3]) == [2, 3] + assert $ NEA.takeEnd 1 (fromArray [ 1, 2, 3 ]) == [ 3 ] + assert $ NEA.takeEnd 2 (fromArray [ 1, 2, 3 ]) == [ 2, 3 ] log "drop should remove the specified number of items from the front of an array" - assert $ NEA.drop 1 (fromArray [1, 2, 3]) == [2, 3] - assert $ NEA.drop 2 (fromArray [1, 2, 3]) == [3] + assert $ NEA.drop 1 (fromArray [ 1, 2, 3 ]) == [ 2, 3 ] + assert $ NEA.drop 2 (fromArray [ 1, 2, 3 ]) == [ 3 ] log "dropWhile should remove all values that match a predicate from the front of an array" - assert $ NEA.dropWhile (_ /= 1) (fromArray [1, 2, 3]) == [1, 2, 3] - assert $ NEA.dropWhile (_ /= 2) (fromArray [1, 2, 3]) == [2, 3] + assert $ NEA.dropWhile (_ /= 1) (fromArray [ 1, 2, 3 ]) == [ 1, 2, 3 ] + assert $ NEA.dropWhile (_ /= 2) (fromArray [ 1, 2, 3 ]) == [ 2, 3 ] log "drop should remove the specified number of items from the end of an array" - assert $ NEA.dropEnd 1 (fromArray [1, 2, 3]) == [1, 2] - assert $ NEA.dropEnd 2 (fromArray [1, 2, 3]) == [1] + assert $ NEA.dropEnd 1 (fromArray [ 1, 2, 3 ]) == [ 1, 2 ] + assert $ NEA.dropEnd 2 (fromArray [ 1, 2, 3 ]) == [ 1 ] log "span should split an array in two based on a predicate" - let testSpan { p, input, init_, rest_ } = do - let result = NEA.span p input - assert $ result.init == init_ - assert $ result.rest == rest_ + let + testSpan { p, input, init_, rest_ } = do + let result = NEA.span p input + assert $ result.init == init_ + assert $ result.rest == rest_ - let oneToSeven = fromArray [1, 2, 3, 4, 5, 6, 7] - testSpan { p: (_ < 4), input: oneToSeven, init_: [1, 2, 3], rest_: [4, 5, 6, 7] } + let oneToSeven = fromArray [ 1, 2, 3, 4, 5, 6, 7 ] + testSpan { p: (_ < 4), input: oneToSeven, init_: [ 1, 2, 3 ], rest_: [ 4, 5, 6, 7 ] } log "group should group consecutive equal elements into arrays" - assert $ NEA.group (fromArray [1, 2, 2, 3, 3, 3, 1]) == fromArray [NEA.singleton 1, fromArray [2, 2], fromArray [3, 3, 3], NEA.singleton 1] + assert $ NEA.group (fromArray [ 1, 2, 2, 3, 3, 3, 1 ]) == fromArray [ NEA.singleton 1, fromArray [ 2, 2 ], fromArray [ 3, 3, 3 ], NEA.singleton 1 ] log "groupAll should group equal elements into arrays" - assert $ NEA.groupAll (fromArray [1, 2, 2, 3, 3, 3, 1]) == fromArray [fromArray [1, 1], fromArray [2, 2], fromArray [3, 3, 3]] + assert $ NEA.groupAll (fromArray [ 1, 2, 2, 3, 3, 3, 1 ]) == fromArray [ fromArray [ 1, 1 ], fromArray [ 2, 2 ], fromArray [ 3, 3, 3 ] ] log "groupBy should group consecutive equal elements into arrays based on an equivalence relation" - assert $ NEA.groupBy (\x y -> odd x && odd y) (fromArray [1, 1, 2, 2, 3, 3]) == fromArray [fromArray [1, 1], NEA.singleton 2, NEA.singleton 2, fromArray [3, 3]] + assert $ NEA.groupBy (\x y -> odd x && odd y) (fromArray [ 1, 1, 2, 2, 3, 3 ]) == fromArray [ fromArray [ 1, 1 ], NEA.singleton 2, NEA.singleton 2, fromArray [ 3, 3 ] ] log "groupBy should be stable" - assert $ NEA.groupBy (\_ _ -> true) (fromArray [1, 2, 3]) == fromArray [fromArray [1, 2, 3]] + assert $ NEA.groupBy (\_ _ -> true) (fromArray [ 1, 2, 3 ]) == fromArray [ fromArray [ 1, 2, 3 ] ] log "groupAllBy should group equal elements into arrays based on the result of a comparison function" - assert $ NEA.groupAllBy (comparing Down) (fromArray [1, 3, 2, 4, 3, 3]) == fromArray [nea [4], nea [3, 3, 3], nea [2], nea [1]] + assert $ NEA.groupAllBy (comparing Down) (fromArray [ 1, 3, 2, 4, 3, 3 ]) == fromArray [ nea [ 4 ], nea [ 3, 3, 3 ], nea [ 2 ], nea [ 1 ] ] log "groupAllBy should be stable" - assert $ NEA.groupAllBy (\_ _ -> EQ) (fromArray [1, 2, 3]) == fromArray [nea [1, 2, 3]] + assert $ NEA.groupAllBy (\_ _ -> EQ) (fromArray [ 1, 2, 3 ]) == fromArray [ nea [ 1, 2, 3 ] ] log "nub should remove duplicate elements from the list, keeping the first occurence" - assert $ NEA.nub (fromArray [1, 2, 2, 3, 4, 1]) == fromArray [1, 2, 3, 4] + assert $ NEA.nub (fromArray [ 1, 2, 2, 3, 4, 1 ]) == fromArray [ 1, 2, 3, 4 ] log "nubEq should remove duplicate elements from the list, keeping the first occurence" - assert $ NEA.nubEq (fromArray [1, 2, 2, 3, 4, 1]) == fromArray [1, 2, 3, 4] + assert $ NEA.nubEq (fromArray [ 1, 2, 2, 3, 4, 1 ]) == fromArray [ 1, 2, 3, 4 ] log "nubByEq should remove duplicate items from the list using a supplied predicate" let nubPred = \x y -> if odd x then false else x == y - assert $ NEA.nubByEq nubPred (fromArray [1, 2, 2, 3, 3, 4, 4, 1]) == fromArray [1, 2, 3, 3, 4, 1] + assert $ NEA.nubByEq nubPred (fromArray [ 1, 2, 2, 3, 3, 4, 4, 1 ]) == fromArray [ 1, 2, 3, 3, 4, 1 ] log "union should produce the union of two arrays" - assert $ NEA.union (fromArray [1, 2, 3]) (fromArray [2, 3, 4]) == fromArray [1, 2, 3, 4] - assert $ NEA.union (fromArray [1, 1, 2, 3]) (fromArray [2, 3, 4]) == fromArray [1, 1, 2, 3, 4] + assert $ NEA.union (fromArray [ 1, 2, 3 ]) (fromArray [ 2, 3, 4 ]) == fromArray [ 1, 2, 3, 4 ] + assert $ NEA.union (fromArray [ 1, 1, 2, 3 ]) (fromArray [ 2, 3, 4 ]) == fromArray [ 1, 1, 2, 3, 4 ] log "unionBy should produce the union of two arrays using the specified equality relation" - assert $ NEA.unionBy (\_ y -> y < 5) (fromArray [1, 2, 3]) (fromArray [2, 3, 4, 5, 6]) == fromArray [1, 2, 3, 5, 6] + assert $ NEA.unionBy (\_ y -> y < 5) (fromArray [ 1, 2, 3 ]) (fromArray [ 2, 3, 4, 5, 6 ]) == fromArray [ 1, 2, 3, 5, 6 ] log "delete should remove the first matching item from an array" - assert $ NEA.delete 1 (fromArray [1, 2, 1]) == [2, 1] - assert $ NEA.delete 2 (fromArray [1, 2, 1]) == [1, 1] + assert $ NEA.delete 1 (fromArray [ 1, 2, 1 ]) == [ 2, 1 ] + assert $ NEA.delete 2 (fromArray [ 1, 2, 1 ]) == [ 1, 1 ] log "deleteBy should remove the first equality-relation-matching item from an array" - assert $ NEA.deleteBy (/=) 2 (fromArray [1, 2, 1]) == [2, 1] - assert $ NEA.deleteBy (/=) 1 (fromArray [1, 2, 1]) == [1, 1] + assert $ NEA.deleteBy (/=) 2 (fromArray [ 1, 2, 1 ]) == [ 2, 1 ] + assert $ NEA.deleteBy (/=) 1 (fromArray [ 1, 2, 1 ]) == [ 1, 1 ] log "intersect should return the intersection of two arrays" - assert $ NEA.intersect (fromArray [1, 2, 3, 4, 3, 2, 1]) (fromArray [1, 1, 2, 3]) == [1, 2, 3, 3, 2, 1] + assert $ NEA.intersect (fromArray [ 1, 2, 3, 4, 3, 2, 1 ]) (fromArray [ 1, 1, 2, 3 ]) == [ 1, 2, 3, 3, 2, 1 ] log "intersectBy should return the intersection of two arrays using the specified equivalence relation" - assert $ NEA.intersectBy (\x y -> (x * 2) == y) (fromArray [1, 2, 3]) (fromArray [2, 6]) == [1, 3] + assert $ NEA.intersectBy (\x y -> (x * 2) == y) (fromArray [ 1, 2, 3 ]) (fromArray [ 2, 6 ]) == [ 1, 3 ] log "zipWith should use the specified function to zip two arrays together" - assert $ NEA.zipWith (\x y -> [show x, y]) (fromArray [1, 2, 3]) (fromArray ["a", "b", "c"]) == fromArray [["1", "a"], ["2", "b"], ["3", "c"]] + assert $ NEA.zipWith (\x y -> [ show x, y ]) (fromArray [ 1, 2, 3 ]) (fromArray [ "a", "b", "c" ]) == fromArray [ [ "1", "a" ], [ "2", "b" ], [ "3", "c" ] ] log "zipWithA should use the specified function to zip two lists together" - assert $ NEA.zipWithA (\x y -> Just $ Tuple x y) (fromArray [1, 2, 3]) (fromArray ["a", "b", "c"]) == Just (fromArray [Tuple 1 "a", Tuple 2 "b", Tuple 3 "c"]) + assert $ NEA.zipWithA (\x y -> Just $ Tuple x y) (fromArray [ 1, 2, 3 ]) (fromArray [ "a", "b", "c" ]) == Just (fromArray [ Tuple 1 "a", Tuple 2 "b", Tuple 3 "c" ]) log "zip should use the specified function to zip two lists together" - assert $ NEA.zip (fromArray [1, 2, 3]) (fromArray ["a", "b", "c"]) == fromArray [Tuple 1 "a", Tuple 2 "b", Tuple 3 "c"] + assert $ NEA.zip (fromArray [ 1, 2, 3 ]) (fromArray [ "a", "b", "c" ]) == fromArray [ Tuple 1 "a", Tuple 2 "b", Tuple 3 "c" ] log "unzip should deconstruct a list of tuples into a tuple of lists" - assert $ NEA.unzip (fromArray [Tuple 1 "a", Tuple 2 "b", Tuple 3 "c"]) == Tuple (fromArray [1, 2, 3]) (fromArray ["a", "b", "c"]) + assert $ NEA.unzip (fromArray [ Tuple 1 "a", Tuple 2 "b", Tuple 3 "c" ]) == Tuple (fromArray [ 1, 2, 3 ]) (fromArray [ "a", "b", "c" ]) log "any should return true if at least one array element satisfy the given predicate" - assert $ NEA.any (_ > 0) $ fromArray [-1, 0, 1] - assert $ not $ NEA.any (_ > 0) $ fromArray [-1, -2, -3] + assert $ NEA.any (_ > 0) $ fromArray [ -1, 0, 1 ] + assert $ not $ NEA.any (_ > 0) $ fromArray [ -1, -2, -3 ] log "all should return true if all the array elements satisfy the given predicate" - assert $ NEA.all (_ > 0) $ fromArray [1, 2, 3] - assert $ not $ NEA.all (_ > 0) $ fromArray [-1, -2, -3] + assert $ NEA.all (_ > 0) $ fromArray [ 1, 2, 3 ] + assert $ not $ NEA.all (_ > 0) $ fromArray [ -1, -2, -3 ] log "fromFoldable" - for_ (fromArray [[], [1], [1,2], [1,2,3,4,5]]) \xs -> do + for_ (fromArray [ [], [ 1 ], [ 1, 2 ], [ 1, 2, 3, 4, 5 ] ]) \xs -> do assert $ NEA.fromFoldable xs == NEA.fromArray xs log "toUnfoldable" let toUnfoldableId xs = NEA.toUnfoldable xs == NEA.toArray xs traverse_ (assert <<< toUnfoldableId) $ - fromArray ( - [ fromArray [1] - , fromArray [1,2,3] - , fromArray [2,3,1] - , fromArray [4,0,0,1,25,36,458,5842,23757] - ]) + fromArray + ( [ fromArray [ 1 ] + , fromArray [ 1, 2, 3 ] + , fromArray [ 2, 3, 1 ] + , fromArray [ 4, 0, 0, 1, 25, 36, 458, 5842, 23757 ] + ] + ) log "toUnfoldable1" assert $ NEA.toUnfoldable1 (NEA.range 0 9) == 0 :| A.range 1 9 @@ -378,43 +382,43 @@ testNonEmptyArray = do assert $ U1.range 0 9 == NEA.range 0 9 log "foldMap1 should work" - assert $ foldMap1 Additive (fromArray [1, 2, 3, 4]) == Additive 10 + assert $ foldMap1 Additive (fromArray [ 1, 2, 3, 4 ]) == Additive 10 log "fold1 should work" -- test through sum - assert $ sum (fromArray [1, 2, 3, 4]) == 10 + assert $ sum (fromArray [ 1, 2, 3, 4 ]) == 10 log "foldr1 should work" - assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b", "c", "d"]) == "(a(b(cd)))" - assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b"]) == "(ab)" - assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a"]) == "a" + assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray [ "a", "b", "c", "d" ]) == "(a(b(cd)))" + assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray [ "a", "b" ]) == "(ab)" + assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray [ "a" ]) == "a" log "foldl1 should work" - assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b", "c", "d"]) == "(((ab)c)d)" - assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b"]) == "(ab)" - assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a"]) == "a" + assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray [ "a", "b", "c", "d" ]) == "(((ab)c)d)" + assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray [ "a", "b" ]) == "(ab)" + assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray [ "a" ]) == "a" log "traverse1 should work" - assert $ traverse1 Just (fromArray [1, 2, 3, 4]) == NEA.fromArray [1, 2, 3, 4] + assert $ traverse1 Just (fromArray [ 1, 2, 3, 4 ]) == NEA.fromArray [ 1, 2, 3, 4 ] log "transpose swaps rows and columns for a regular two-dimension array" - assert $ NEA.transpose (fromArray [ (fromArray [1,2,3]), (fromArray [4,5,6]), (fromArray [7,8,9])]) == - (fromArray [ (fromArray [1,4,7]), (fromArray [2,5,8]), (fromArray [3,6,9])]) - + assert $ NEA.transpose (fromArray [ (fromArray [ 1, 2, 3 ]), (fromArray [ 4, 5, 6 ]), (fromArray [ 7, 8, 9 ]) ]) == + (fromArray [ (fromArray [ 1, 4, 7 ]), (fromArray [ 2, 5, 8 ]), (fromArray [ 3, 6, 9 ]) ]) + log "transpose skips elements when rows don't match" - assert $ NEA.transpose (fromArray [ (fromArray [10,11]), (fromArray [20]), (fromArray [30,31,32])]) == - (fromArray [ (fromArray [10,20,30]), (fromArray [11,31]), (fromArray [32])]) + assert $ NEA.transpose (fromArray [ (fromArray [ 10, 11 ]), (fromArray [ 20 ]), (fromArray [ 30, 31, 32 ]) ]) == + (fromArray [ (fromArray [ 10, 20, 30 ]), (fromArray [ 11, 31 ]), (fromArray [ 32 ]) ]) log "transpose' handles the singleton empty array" assert $ NEA.transpose' (fromArray [ [] ]) == (Nothing :: Maybe (NEA.NonEmptyArray (Array Int))) log "transpose' swaps rows and columns for a regular two-dimension array" - assert $ NEA.transpose' (fromArray [[1,2,3], [4,5,6], [7,8,9]]) == - (Just $ fromArray [[1,4,7], [2,5,8], [3,6,9]]) - + assert $ NEA.transpose' (fromArray [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]) == + (Just $ fromArray [ [ 1, 4, 7 ], [ 2, 5, 8 ], [ 3, 6, 9 ] ]) + log "transpose' skips elements when rows don't match" - assert $ NEA.transpose' (fromArray [[10,11], [20], [30,31,32]]) == - (Just $ fromArray [[10,20,30], [11,31], [32]]) + assert $ NEA.transpose' (fromArray [ [ 10, 11 ], [ 20 ], [ 30, 31, 32 ] ]) == + (Just $ fromArray [ [ 10, 20, 30 ], [ 11, 31 ], [ 32 ] ]) odd :: Int -> Boolean odd n = n `mod` 2 /= zero diff --git a/test/Test/Data/Array/Partial.purs b/test/Test/Data/Array/Partial.purs index 27eaf757..61b296f5 100644 --- a/test/Test/Data/Array/Partial.purs +++ b/test/Test/Data/Array/Partial.purs @@ -2,7 +2,7 @@ module Test.Data.Array.Partial (testArrayPartial) where import Prelude -import Data.Array.Partial (init, last, tail, head) +import Data.Array.Partial (head, init, last, tail) import Effect (Effect) import Effect.Console (log) import Partial.Unsafe (unsafePartial) @@ -12,15 +12,15 @@ testArrayPartial :: Effect Unit testArrayPartial = do log "head should return the first item in an array" - assert $ unsafePartial $ head [1, 2, 3] == 1 - assert $ unsafePartial $ head [1] == 1 + assert $ unsafePartial $ head [ 1, 2, 3 ] == 1 + assert $ unsafePartial $ head [ 1 ] == 1 log "tail should return all but the first item in an array" - assert $ unsafePartial $ tail [1, 2, 3] == [2, 3] + assert $ unsafePartial $ tail [ 1, 2, 3 ] == [ 2, 3 ] log "last should return the last item of an array" - assert $ unsafePartial $ last [1, 2, 3] == 3 - assert $ unsafePartial $ last [1] == 1 + assert $ unsafePartial $ last [ 1, 2, 3 ] == 3 + assert $ unsafePartial $ last [ 1 ] == 1 log "init should return all but the last item of an array" - assert $ unsafePartial $ init [1, 2, 3] == [1, 2] + assert $ unsafePartial $ init [ 1, 2, 3 ] == [ 1, 2 ] diff --git a/test/Test/Data/Array/ST.purs b/test/Test/Data/Array/ST.purs index d408ec1c..a2a86321 100644 --- a/test/Test/Data/Array/ST.purs +++ b/test/Test/Data/Array/ST.purs @@ -19,17 +19,20 @@ testArrayST = do log "run should produce an immutable array by running a constructor operation" - assert $ STA.run (do - arr <- STA.new - void $ STA.push 1 arr - void $ STA.push 2 arr - pure arr) == [1, 2] + assert $ + STA.run + ( do + arr <- STA.new + void $ STA.push 1 arr + void $ STA.push 2 arr + pure arr + ) == [ 1, 2 ] log "withArray should run an operation on a copy of an array" - let original = [1, 2, 3] - assert $ ST.run (withArray (STA.push 42) original) == [1, 2, 3, 42] - assert $ original == [1, 2, 3] + let original = [ 1, 2, 3 ] + assert $ ST.run (withArray (STA.push 42) original) == [ 1, 2, 3, 42 ] + assert $ original == [ 1, 2, 3 ] log "empty should produce an empty array" @@ -37,283 +40,397 @@ testArrayST = do log "thaw should produce an STArray from a standard array" - assert $ STA.run (STA.thaw [1, 2, 3]) == [1, 2, 3] + assert $ STA.run (STA.thaw [ 1, 2, 3 ]) == [ 1, 2, 3 ] log "freeze should produce a standard array from an STArray" - assert $ ST.run (do - arr <- STA.thaw [1, 2, 3] - STA.freeze arr) == [1, 2, 3] + assert $ + ST.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + STA.freeze arr + ) == [ 1, 2, 3 ] log "clone should produce a shallow copy of an STArray" - assert $ ST.run (do - arr <- STA.thaw [1, 2, 3] - arr2 <- STA.clone arr - _ <- STA.poke 0 4 arr - STA.freeze arr2) == [1, 2, 3] + assert $ + ST.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + arr2 <- STA.clone arr + _ <- STA.poke 0 4 arr + STA.freeze arr2 + ) == [ 1, 2, 3 ] log "unsafeThaw should produce an STArray from a standard array" - assert $ STA.run (STA.unsafeThaw [1, 2, 3]) == [1, 2, 3] + assert $ STA.run (STA.unsafeThaw [ 1, 2, 3 ]) == [ 1, 2, 3 ] log "length should return the number of items in an STArray" - assert $ ST.run (do - arr <- STA.thaw nil - length <- STA.length arr - pure $ length == 0) - - assert $ ST.run (do - arr <- STA.thaw [1] - length <- STA.length arr - pure $ length == 1) - - assert $ ST.run (do - arr <- STA.thaw [1, 2, 3, 4, 5] - length <- STA.length arr - pure $ length == 5) + assert $ ST.run + ( do + arr <- STA.thaw nil + length <- STA.length arr + pure $ length == 0 + ) + + assert $ ST.run + ( do + arr <- STA.thaw [ 1 ] + length <- STA.length arr + pure $ length == 1 + ) + + assert $ ST.run + ( do + arr <- STA.thaw [ 1, 2, 3, 4, 5 ] + length <- STA.length arr + pure $ length == 5 + ) log "pop should remove elements from an STArray" - assert $ STA.run (do - arr <- STA.thaw [1, 2, 3] - void $ STA.pop arr - pure arr) == [1, 2] + assert $ + STA.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + void $ STA.pop arr + pure arr + ) == [ 1, 2 ] log "pop should return the last element of an STArray" - assert $ ST.run (do - arr <- STA.thaw [1, 2, 3] - STA.pop arr) == Just 3 + assert $ + ST.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + STA.pop arr + ) == Just 3 log "pop should return Nothing when given an empty array" - assert $ isNothing $ ST.run (do - arr <- STA.new - STA.pop arr) + assert $ isNothing $ ST.run + ( do + arr <- STA.new + STA.pop arr + ) log "push should append a value to the end of the array" - assert $ STA.run (do - arr <- STA.new - void $ STA.push 1 arr - void $ STA.push 2 arr - pure arr) == [1, 2] - - assert $ STA.run (do - arr <- STA.thaw [1, 2, 3] - void $ STA.push 4 arr - pure arr) == [1, 2, 3, 4] + assert $ + STA.run + ( do + arr <- STA.new + void $ STA.push 1 arr + void $ STA.push 2 arr + pure arr + ) == [ 1, 2 ] + + assert $ + STA.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + void $ STA.push 4 arr + pure arr + ) == [ 1, 2, 3, 4 ] log "push should return the new length of the array" - assert $ ST.run (do - arr <- STA.thaw [unit, unit, unit] - STA.push unit arr) == 4 + assert $ + ST.run + ( do + arr <- STA.thaw [ unit, unit, unit ] + STA.push unit arr + ) == 4 log "pushAll should append multiple values to the end of the array" - assert $ STA.run (do - arr <- STA.new - void $ STA.pushAll [1, 2] arr - pure arr) == [1, 2] - - assert $ STA.run (do - arr <- STA.thaw [1, 2, 3] - void $ STA.pushAll [4, 5, 6] arr - pure arr) == [1, 2, 3, 4, 5, 6] + assert $ + STA.run + ( do + arr <- STA.new + void $ STA.pushAll [ 1, 2 ] arr + pure arr + ) == [ 1, 2 ] + + assert $ + STA.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + void $ STA.pushAll [ 4, 5, 6 ] arr + pure arr + ) == [ 1, 2, 3, 4, 5, 6 ] log "pushAll should return the new length of the array" - assert $ ST.run (do - arr <- STA.thaw [unit, unit, unit] - STA.pushAll [unit, unit] arr) == 5 + assert $ + ST.run + ( do + arr <- STA.thaw [ unit, unit, unit ] + STA.pushAll [ unit, unit ] arr + ) == 5 log "peek should return Nothing when peeking a value outside the array bounds" - assert $ isNothing $ ST.run (do - arr <- STA.new - STA.peek 0 arr) + assert $ isNothing $ ST.run + ( do + arr <- STA.new + STA.peek 0 arr + ) - assert $ isNothing $ ST.run (do - arr <- STA.thaw [1] - STA.peek 1 arr) + assert $ isNothing $ ST.run + ( do + arr <- STA.thaw [ 1 ] + STA.peek 1 arr + ) - assert $ isNothing $ ST.run (do - arr <- STA.new - STA.peek (-1) arr) + assert $ isNothing $ ST.run + ( do + arr <- STA.new + STA.peek (-1) arr + ) log "peek should return the value at the specified index" - assert $ ST.run (do - arr <- STA.thaw [1] - STA.peek 0 arr) == Just 1 + assert $ + ST.run + ( do + arr <- STA.thaw [ 1 ] + STA.peek 0 arr + ) == Just 1 - assert $ ST.run (do - arr <- STA.thaw [1, 2, 3] - STA.peek 2 arr) == Just 3 + assert $ + ST.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + STA.peek 2 arr + ) == Just 3 log "poke should return true when a value has been updated succesfully" - assert $ ST.run (do - arr <- STA.thaw [1] - STA.poke 0 10 arr) + assert $ ST.run + ( do + arr <- STA.thaw [ 1 ] + STA.poke 0 10 arr + ) - assert $ ST.run (do - arr <- STA.thaw [1, 2, 3] - STA.poke 2 30 arr) + assert $ ST.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + STA.poke 2 30 arr + ) log "poke should return false when attempting to modify a value outside the array bounds" - assert $ not $ ST.run (do - arr <- STA.new - STA.poke 0 10 arr) + assert $ not $ ST.run + ( do + arr <- STA.new + STA.poke 0 10 arr + ) - assert $ not $ ST.run (do - arr <- STA.thaw [1, 2, 3] - STA.poke 3 100 arr) + assert $ not $ ST.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + STA.poke 3 100 arr + ) - assert $ not $ ST.run (do - arr <- STA.thaw [1, 2, 3] - STA.poke (-1) 100 arr) + assert $ not $ ST.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + STA.poke (-1) 100 arr + ) log "poke should replace the value at the specified index" - assert $ STA.run (do - arr <- STA.thaw [1] - void $ STA.poke 0 10 arr - pure arr) == [10] + assert $ + STA.run + ( do + arr <- STA.thaw [ 1 ] + void $ STA.poke 0 10 arr + pure arr + ) == [ 10 ] log "poke should do nothing when attempting to modify a value outside the array bounds" - assert $ STA.run (do - arr <- STA.thaw [1] - void $ STA.poke 1 2 arr - pure arr) == [1] + assert $ + STA.run + ( do + arr <- STA.thaw [ 1 ] + void $ STA.poke 1 2 arr + pure arr + ) == [ 1 ] log "shift should remove elements from an STArray" - assert $ STA.run (do - arr <- STA.thaw [1, 2, 3] - void $ STA.shift arr - pure arr) == [2, 3] + assert $ + STA.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + void $ STA.shift arr + pure arr + ) == [ 2, 3 ] log "shift should return the first element of an STArray" - assert $ ST.run (do - arr <- STA.thaw [1, 2, 3] - STA.shift arr) == Just 1 + assert $ + ST.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + STA.shift arr + ) == Just 1 log "shift should return Nothing when given an empty array" - assert $ isNothing $ ST.run (do - arr <- STA.new - STA.shift arr) + assert $ isNothing $ ST.run + ( do + arr <- STA.new + STA.shift arr + ) log "unshift should append a value to the front of the array" - assert $ STA.run (do - arr <- STA.new - void $ STA.unshift 1 arr - void $ STA.unshift 2 arr - pure arr) == [2, 1] - - assert $ STA.run (do - arr <- STA.thaw [1, 2, 3] - void $ STA.unshift 4 arr - pure arr) == [4, 1, 2, 3] + assert $ + STA.run + ( do + arr <- STA.new + void $ STA.unshift 1 arr + void $ STA.unshift 2 arr + pure arr + ) == [ 2, 1 ] + + assert $ + STA.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + void $ STA.unshift 4 arr + pure arr + ) == [ 4, 1, 2, 3 ] log "unshift should return the new length of the array" - assert $ ST.run (do - arr <- STA.thaw [unit, unit, unit] - STA.unshift unit arr) == 4 + assert $ + ST.run + ( do + arr <- STA.thaw [ unit, unit, unit ] + STA.unshift unit arr + ) == 4 log "unshiftAll should append multiple values to the front of the array" - assert $ STA.run (do - arr <- STA.new - void $ STA.unshiftAll [1, 2] arr - pure arr) == [1, 2] - - assert $ STA.run (do - arr <- STA.thaw [1, 2, 3] - void $ STA.unshiftAll [4, 5, 6] arr - pure arr) == [4, 5, 6, 1, 2, 3] + assert $ + STA.run + ( do + arr <- STA.new + void $ STA.unshiftAll [ 1, 2 ] arr + pure arr + ) == [ 1, 2 ] + + assert $ + STA.run + ( do + arr <- STA.thaw [ 1, 2, 3 ] + void $ STA.unshiftAll [ 4, 5, 6 ] arr + pure arr + ) == [ 4, 5, 6, 1, 2, 3 ] log "unshiftAll should return the new length of the array" - assert $ ST.run (do - arr <- STA.thaw [unit, unit, unit] - STA.unshiftAll [unit, unit] arr) == 5 + assert $ + ST.run + ( do + arr <- STA.thaw [ unit, unit, unit ] + STA.unshiftAll [ unit, unit ] arr + ) == 5 log "sort should reorder a list into ascending order based on the result of compare" - assert $ STA.run ( - STA.sort =<< STA.unsafeThaw [1, 3, 2, 5, 6, 4] - ) == [1, 2, 3, 4, 5, 6] - assert $ STA.run ( - STA.sort =<< STA.unsafeThaw [defined 1, undefined, defined 2] - ) == [undefined, defined 1, defined 2] + assert $ + STA.run + ( STA.sort =<< STA.unsafeThaw [ 1, 3, 2, 5, 6, 4 ] + ) == [ 1, 2, 3, 4, 5, 6 ] + assert $ + STA.run + ( STA.sort =<< STA.unsafeThaw [ defined 1, undefined, defined 2 ] + ) == [ undefined, defined 1, defined 2 ] log "sortBy should reorder a list into ascending order based on the result of a comparison function" - assert $ STA.run ( - STA.sortBy (flip compare) =<< STA.unsafeThaw [1, 3, 2, 5, 6, 4] - ) == [6, 5, 4, 3, 2, 1] + assert $ + STA.run + ( STA.sortBy (flip compare) =<< STA.unsafeThaw [ 1, 3, 2, 5, 6, 4 ] + ) == [ 6, 5, 4, 3, 2, 1 ] log "sortBy should not reorder elements that are equal according to a comparison function" let s1 = map (Tuple "a") (range 1 100) - assert $ STA.run ( - STA.sortBy (comparing fst) =<< STA.unsafeThaw s1 - ) == s1 + assert $ + STA.run + ( STA.sortBy (comparing fst) =<< STA.unsafeThaw s1 + ) == s1 log "sortWith should reorder a list into ascending order based on the result of compare over a projection" - assert $ STA.run ( - STA.sortWith identity =<< STA.unsafeThaw [1, 3, 2, 5, 6, 4] - ) == [1, 2, 3, 4, 5, 6] + assert $ + STA.run + ( STA.sortWith identity =<< STA.unsafeThaw [ 1, 3, 2, 5, 6, 4 ] + ) == [ 1, 2, 3, 4, 5, 6 ] log "sortWith should not reorder elements that are equal according to a projection" let s2 = map (Tuple "a") (range 1 100) - assert $ STA.run ( - STA.sortWith fst =<< STA.unsafeThaw s2 - ) == s2 + assert $ + STA.run + ( STA.sortWith fst =<< STA.unsafeThaw s2 + ) == s2 log "splice should be able to delete multiple items at a specified index" - assert $ STA.run (do - arr <- STA.thaw [1, 2, 3, 4, 5] - void $ STA.splice 1 3 [] arr - pure arr) == [1, 5] + assert $ + STA.run + ( do + arr <- STA.thaw [ 1, 2, 3, 4, 5 ] + void $ STA.splice 1 3 [] arr + pure arr + ) == [ 1, 5 ] log "splice should return the items removed" - assert $ ST.run (do - arr <- STA.thaw [1, 2, 3, 4, 5] - STA.splice 1 3 [] arr) == [2, 3, 4] + assert $ + ST.run + ( do + arr <- STA.thaw [ 1, 2, 3, 4, 5 ] + STA.splice 1 3 [] arr + ) == [ 2, 3, 4 ] log "splice should be able to insert multiple items at a specified index" - assert $ STA.run (do - arr <- STA.thaw [1, 2, 3, 4, 5] - void $ STA.splice 1 0 [0, 100] arr - pure arr) == [1, 0, 100, 2, 3, 4, 5] + assert $ + STA.run + ( do + arr <- STA.thaw [ 1, 2, 3, 4, 5 ] + void $ STA.splice 1 0 [ 0, 100 ] arr + pure arr + ) == [ 1, 0, 100, 2, 3, 4, 5 ] log "splice should be able to delete and insert at the same time" - assert $ STA.run (do - arr <- STA.thaw [1, 2, 3, 4, 5] - void $ STA.splice 1 2 [0, 100] arr - pure arr) == [1, 0, 100, 4, 5] + assert $ + STA.run + ( do + arr <- STA.thaw [ 1, 2, 3, 4, 5 ] + void $ STA.splice 1 2 [ 0, 100 ] arr + pure arr + ) == [ 1, 0, 100, 4, 5 ] log "toAssocArray should return all items in the array with the correct indices and values" - assert $ all (\{ value: v, index: i } -> v == i + 1) $ ST.run (do - arr <- STA.thaw [1, 2, 3, 4, 5] - STA.toAssocArray arr) - - assert $ all (\{ value: v, index: i } -> v == (i + 1) * 10) $ ST.run (do - arr <- STA.thaw [10, 20, 30, 40, 50] - STA.toAssocArray arr) + assert $ all (\{ value: v, index: i } -> v == i + 1) $ ST.run + ( do + arr <- STA.thaw [ 1, 2, 3, 4, 5 ] + STA.toAssocArray arr + ) + + assert $ all (\{ value: v, index: i } -> v == (i + 1) * 10) $ ST.run + ( do + arr <- STA.thaw [ 10, 20, 30, 40, 50 ] + STA.toAssocArray arr + ) nil :: Array Int nil = [] diff --git a/test/Test/Data/Array/ST/Partial.purs b/test/Test/Data/Array/ST/Partial.purs index 89c6f9eb..006e4db4 100644 --- a/test/Test/Data/Array/ST/Partial.purs +++ b/test/Test/Data/Array/ST/Partial.purs @@ -15,11 +15,11 @@ testArraySTPartial = do log "peekSTArray should return the value at the specified index" assert $ 2 == ST.run do - a <- thaw [1, 2, 3] + a <- thaw [ 1, 2, 3 ] unsafePartial $ STAP.peek 1 a log "pokeSTArray should modify the value at the specified index" - assert $ [1, 4, 3] == ST.run do - a <- thaw [1, 2, 3] + assert $ [ 1, 4, 3 ] == ST.run do + a <- thaw [ 1, 2, 3 ] unsafePartial $ STAP.poke 1 4 a unsafeFreeze a diff --git a/test/Test/Data/UndefinedOr.js b/test/Test/Data/UndefinedOr.js index 18017cb2..7812c30d 100644 --- a/test/Test/Data/UndefinedOr.js +++ b/test/Test/Data/UndefinedOr.js @@ -1,5 +1,5 @@ const undefinedImpl = undefined; -export {undefinedImpl as undefined}; +export { undefinedImpl as undefined }; export function defined(x) { return x; diff --git a/test/Test/Main.purs b/test/Test/Main.purs index 86c40291..d9e1a7e8 100644 --- a/test/Test/Main.purs +++ b/test/Test/Main.purs @@ -4,10 +4,10 @@ import Prelude import Effect (Effect) import Test.Data.Array (testArray) +import Test.Data.Array.NonEmpty (testNonEmptyArray) import Test.Data.Array.Partial (testArrayPartial) import Test.Data.Array.ST (testArrayST) import Test.Data.Array.ST.Partial (testArraySTPartial) -import Test.Data.Array.NonEmpty (testNonEmptyArray) main :: Effect Unit main = do