Skip to content

Commit 08338d1

Browse files
committed
Add some basic tests
1 parent 9d98a21 commit 08338d1

File tree

8 files changed

+298
-63
lines changed

8 files changed

+298
-63
lines changed

Gruntfile.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

README.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,23 @@ modifyAt :: forall a. Int -> (a -> a) -> [a] -> [a]
196196

197197
Apply a function to the element at the specified index, creating a new array.
198198

199-
#### `deleteBy`
199+
#### `delete`
200200

201201
``` purescript
202-
deleteBy :: forall a. (a -> a -> Boolean) -> a -> [a] -> [a]
202+
delete :: forall a. (Eq a) => a -> [a] -> [a]
203203
```
204204

205-
Delete the first element of an array which matches the specified value, under the
206-
equivalence relation provided in the first argument, creating a new array.
205+
Delete the first element of an array which is equal to the specified value,
206+
creating a new array.
207207

208-
#### `delete`
208+
#### `deleteBy`
209209

210210
``` purescript
211-
delete :: forall a. (Eq a) => a -> [a] -> [a]
211+
deleteBy :: forall a. (a -> a -> Boolean) -> a -> [a] -> [a]
212212
```
213213

214-
Delete the first element of an array which is equal to the specified value,
215-
creating a new array.
214+
Delete the first element of an array which matches the specified value, under the
215+
equivalence relation provided in the first argument, creating a new array.
216216

217217
#### `(\\)`
218218

@@ -223,22 +223,22 @@ creating a new array.
223223
Delete the first occurrence of each element in the second array from the first array,
224224
creating a new array.
225225

226-
#### `intersectBy`
226+
#### `intersect`
227227

228228
``` purescript
229-
intersectBy :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> [a]
229+
intersect :: forall a. (Eq a) => [a] -> [a] -> [a]
230230
```
231231

232-
Calculate the intersection of two arrays, using the specified equivalence relation
233-
to compare elements, creating a new array.
232+
Calculate the intersection of two arrays, creating a new array.
234233

235-
#### `intersect`
234+
#### `intersectBy`
236235

237236
``` purescript
238-
intersect :: forall a. (Eq a) => [a] -> [a] -> [a]
237+
intersectBy :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> [a]
239238
```
240239

241-
Calculate the intersection of two arrays, creating a new array.
240+
Calculate the intersection of two arrays, using the specified equivalence relation
241+
to compare elements, creating a new array.
242242

243243
#### `concatMap`
244244

@@ -662,4 +662,7 @@ init :: forall a. [a] -> [a]
662662

663663
Get all but the last element of a non-empty array.
664664

665-
Running time: `O(n)`, where `n` is the length of the array.
665+
Running time: `O(n)`, where `n` is the length of the array.
666+
667+
668+

gulpfile.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"use strict";
2+
3+
var gulp = require("gulp");
4+
var plumber = require("gulp-plumber");
5+
var purescript = require("gulp-purescript");
6+
var jsvalidate = require("gulp-jsvalidate");
7+
var run = require("gulp-run");
8+
9+
var paths = [
10+
"src/**/*.purs",
11+
"bower_components/purescript-*/src/**/*.purs",
12+
"test/**/*.purs"
13+
];
14+
15+
gulp.task("make", function() {
16+
return gulp.src(paths)
17+
.pipe(plumber())
18+
.pipe(purescript.pscMake());
19+
});
20+
21+
gulp.task("jsvalidate", ["make"], function () {
22+
return gulp.src("output/**/*.js")
23+
.pipe(plumber())
24+
.pipe(jsvalidate());
25+
});
26+
27+
gulp.task("docs", function () {
28+
return gulp.src("src/**/*.purs")
29+
.pipe(plumber())
30+
.pipe(purescript.pscDocs())
31+
.pipe(gulp.dest("README.md"));
32+
});
33+
34+
gulp.task("test", function() {
35+
return gulp.src(paths)
36+
.pipe(plumber())
37+
.pipe(purescript.psc({ main: "Test.Main" }))
38+
.pipe(run("node"));
39+
});
40+
41+
gulp.task("default", ["jsvalidate", "docs"]);

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"private": true,
3-
"dependencies": {
4-
"grunt": "~0.4.4",
5-
"grunt-purescript": "~0.5.1",
6-
"grunt-contrib-clean": "~0.6.0"
3+
"devDependencies": {
4+
"gulp": "^3.8.11",
5+
"gulp-jsvalidate": "^1.0.1",
6+
"gulp-plumber": "^1.0.0",
7+
"gulp-purescript": "^0.3.1",
8+
"gulp-run": "^1.6.7"
79
}
810
}

src/Data/Array.purs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ module Data.Array
3232
, deleteAt
3333
, updateAt
3434
, modifyAt
35-
, deleteBy
3635
, delete
36+
, deleteBy
3737
, (\\)
38-
, intersectBy
3938
, intersect
39+
, intersectBy
4040
, concatMap
4141
, filter
4242
, range
@@ -132,9 +132,10 @@ findIndex f xs = runFn4 findIndexJS Just Nothing f xs
132132

133133
foreign import findIndexJS
134134
"""
135-
function findIndexJS (just, nothing, f, arr) {
135+
function findIndexJS(just, nothing, f, arr) {
136136
for (var i = 0, l = arr.length; i < l; i++) {
137137
if (f(arr[i])) return just(i);
138+
}
138139
return nothing;
139140
};
140141
""" :: forall a. Fn4 (Int -> Maybe Int) (Maybe Int) (a -> Boolean) [a] (Maybe Int)
@@ -145,7 +146,7 @@ findLastIndex f xs = runFn4 findLastIndexJS Just Nothing f xs
145146

146147
foreign import findLastIndexJS
147148
"""
148-
function findLastIndex (just, nothing, f, arr) {
149+
function findLastIndexJS(just, nothing, f, arr) {
149150
for (var i = arr.length - 1; i >= 0; i--) {
150151
if (f(arr[i])) return just(i);
151152
}
@@ -264,17 +265,17 @@ foreign import updateAt
264265
modifyAt :: forall a. Int -> (a -> a) -> [a] -> [a]
265266
modifyAt i f xs = maybe xs (\x -> updateAt i (f x) xs) (xs !! i)
266267

268+
-- | Delete the first element of an array which is equal to the specified value,
269+
-- | creating a new array.
270+
delete :: forall a. (Eq a) => a -> [a] -> [a]
271+
delete = deleteBy (==)
272+
267273
-- | Delete the first element of an array which matches the specified value, under the
268274
-- | equivalence relation provided in the first argument, creating a new array.
269275
deleteBy :: forall a. (a -> a -> Boolean) -> a -> [a] -> [a]
270276
deleteBy _ _ [] = []
271277
deleteBy eq x ys = maybe ys (\i -> deleteAt i one ys) (findIndex (eq x) ys)
272278

273-
-- | Delete the first element of an array which is equal to the specified value,
274-
-- | creating a new array.
275-
delete :: forall a. (Eq a) => a -> [a] -> [a]
276-
delete = deleteBy (==)
277-
278279
infix 5 \\
279280

280281
-- | Delete the first occurrence of each element in the second array from the first array,
@@ -286,17 +287,17 @@ infix 5 \\
286287
go [] _ = []
287288
go xs (y:ys) = go (delete y xs) ys
288289

290+
-- | Calculate the intersection of two arrays, creating a new array.
291+
intersect :: forall a. (Eq a) => [a] -> [a] -> [a]
292+
intersect = intersectBy (==)
293+
289294
-- | Calculate the intersection of two arrays, using the specified equivalence relation
290295
-- | to compare elements, creating a new array.
291296
intersectBy :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> [a]
292297
intersectBy _ [] _ = []
293298
intersectBy _ _ [] = []
294299
intersectBy eq xs ys = filter (\x -> isJust (findIndex (eq x) ys)) xs
295300

296-
-- | Calculate the intersection of two arrays, creating a new array.
297-
intersect :: forall a. (Eq a) => [a] -> [a] -> [a]
298-
intersect = intersectBy (==)
299-
300301
-- | Apply a function to each element in an array, and flatten the results
301302
-- | into a single, new array.
302303
foreign import concatMap

test/Test/Common.purs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Test.Common where
2+
3+
import Control.Monad.Eff (Eff())
4+
5+
foreign import data Assert :: !
6+
7+
foreign import assert
8+
"""
9+
function assert(success) {
10+
return function () {
11+
if (success) return {};
12+
throw new Error("Assertion failed");
13+
};
14+
}
15+
""" :: forall e. Boolean -> Eff (assert :: Assert | e) Unit

0 commit comments

Comments
 (0)