From dc568e95badf427ec397f7758d4dcb1e30867d00 Mon Sep 17 00:00:00 2001 From: Steven Syrek Date: Sun, 28 Aug 2016 16:37:27 -0400 Subject: [PATCH] fix(tests): change mechanism for testing list equality --- test/concat-test.js | 2 +- test/cons-test.js | 4 ++-- test/cycle-test.js | 2 +- test/drop-test.js | 4 ++-- test/dropWhile-test.js | 4 ++-- test/filter-test.js | 2 +- test/fromArrayToList-test.js | 2 +- test/fromStringToList-test.js | 2 +- test/init-test.js | 2 +- test/iterate-test.js | 3 ++- test/list-class-test.js | 31 +++++++++++++++---------------- test/list-test.js | 2 +- test/listAppend-test.js | 3 ++- test/listInf-test.js | 2 +- test/listInfBy-test.js | 2 +- test/listRange-test.js | 8 +++++--- test/listRangeBy-test.js | 8 +++++--- test/map-test.js | 3 ++- test/repeat-test.js | 3 ++- test/replicate-test.js | 3 ++- test/reverse-test.js | 2 +- test/sort-test.js | 12 ++++++------ test/sortBy-test.js | 4 ++-- test/tail-test.js | 2 +- test/take-test.js | 2 +- test/takeWhile-test.js | 2 +- 26 files changed, 62 insertions(+), 54 deletions(-) diff --git a/test/concat-test.js b/test/concat-test.js index b13b02e..0c68388 100644 --- a/test/concat-test.js +++ b/test/concat-test.js @@ -6,6 +6,6 @@ describe(`concat()`, function () { const lst3 = lazy.list() const xss = lazy.list(lst1, lst2, lst3) it(`should concatenate (flatten) the elements in a list of lists`, function () { - lazy.concat(xss).should.eql(lazy.list(1, 2, 3, 4, 5, 6)) + lazy.concat(xss).isEq(lazy.list(1, 2, 3, 4, 5, 6)).should.be.true }) }) diff --git a/test/cons-test.js b/test/cons-test.js index 639001d..b4e5deb 100644 --- a/test/cons-test.js +++ b/test/cons-test.js @@ -3,7 +3,7 @@ import * as lazy from '../source' describe(`cons()`, function () { const lst = lazy.list(4, 5, 6) it(`should create a new list from a head and tail`, function () { - lazy.cons(3, lst).should.eql(lazy.list(3, 4, 5, 6)) - lazy.cons(1, lazy.emptyList).should.eql(lazy.list(1)) + lazy.cons(3, lst).isEq(lazy.list(3, 4, 5, 6)) + lazy.cons(1, lazy.emptyList).isEq(lazy.list(1)).should.be.true }) }) diff --git a/test/cycle-test.js b/test/cycle-test.js index 793092b..5fada8c 100644 --- a/test/cycle-test.js +++ b/test/cycle-test.js @@ -4,7 +4,7 @@ describe(`cycle()`, function () { const lst = lazy.list(1, 2, 3) const cyc = lazy.cycle(lst) it(`should return the infinite repetition of a list`, function () { - lazy.take(9, cyc).should.eql(lazy.list(1, 2, 3, 1, 2, 3, 1, 2, 3)) + lazy.take(9, cyc).isEq(lazy.list(1, 2, 3, 1, 2, 3, 1, 2, 3)).should.be.true lazy.index(cyc, 100).should.equal(2) }) it(`should throw an error if the list is empty`, function () { diff --git a/test/drop-test.js b/test/drop-test.js index 13e8f7c..846498d 100644 --- a/test/drop-test.js +++ b/test/drop-test.js @@ -3,9 +3,9 @@ import * as lazy from '../source' describe(`drop()`, function () { const lst = lazy.list(1, 2, 3) it(`should return the suffix of a list after discarding a specified number of values`, function () { - lazy.drop(2, lst).should.eql(lazy.list(3)) + lazy.drop(2, lst).isEq(lazy.list(3)).should.be.true }) it(`should return the empty list if the second argument is the empty list`, function () { - lazy.drop(2, lazy.list()).should.equal(lazy.emptyList) + lazy.drop(2, lazy.list()).isEq(lazy.emptyList).should.be.true }) }) diff --git a/test/dropWhile-test.js b/test/dropWhile-test.js index 89c55a6..2856389 100644 --- a/test/dropWhile-test.js +++ b/test/dropWhile-test.js @@ -4,9 +4,9 @@ describe(`dropWhile()`, function () { const lst = lazy.list(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) const f = x => x < 3 it(`should drop values from a list while a given predicate function returns true`, function () { - lazy.dropWhile(f, lst).should.eql(lazy.list(3, 4, 5, 6, 7, 8, 9, 10)) + lazy.dropWhile(f, lst).isEq(lazy.list(3, 4, 5, 6, 7, 8, 9, 10)).should.be.true }) it(`should return an empty list if the second argument is an empty list`, function () { - lazy.dropWhile(f, lazy.emptyList).should.equal(lazy.emptyList) + lazy.dropWhile(f, lazy.emptyList).isEq(lazy.emptyList).should.be.true }) }) diff --git a/test/filter-test.js b/test/filter-test.js index edc0a2f..f45fb1f 100644 --- a/test/filter-test.js +++ b/test/filter-test.js @@ -4,6 +4,6 @@ describe(`filter()`, function () { const lst = lazy.listRangeBy(0, 50, x => x + 5) const f = x => x % 10 === 0 it(`should return the list of elements in a list for which a function f returns true`, function () { - lazy.filter(f, lst).should.eql(lazy.list(0, 10, 20, 30, 40, 50)) + lazy.filter(f, lst).isEq(lazy.list(0, 10, 20, 30, 40, 50)).should.be.true }) }) diff --git a/test/fromArrayToList-test.js b/test/fromArrayToList-test.js index 8eb6b67..4dceeda 100644 --- a/test/fromArrayToList-test.js +++ b/test/fromArrayToList-test.js @@ -4,6 +4,6 @@ describe(`fromArrayToList()`, function () { const lst = lazy.list(1, 2, 3) const arr = [1, 2, 3] it(`should convert an array into a list`, function () { - lazy.fromArrayToList(arr).should.eql(lst) + lazy.fromArrayToList(arr).isEq(lst).should.be.true }) }) diff --git a/test/fromStringToList-test.js b/test/fromStringToList-test.js index 045c792..e8147d4 100644 --- a/test/fromStringToList-test.js +++ b/test/fromStringToList-test.js @@ -3,6 +3,6 @@ import * as lazy from '../source' describe(`fromStringToList()`, function () { const str = lazy.list(`a`, `b`, `c`) it(`should convert a string into a list`, function () { - lazy.fromStringToList(`abc`).should.eql(str) + lazy.fromStringToList(`abc`).isEq(str).should.be.true }) }) diff --git a/test/init-test.js b/test/init-test.js index 36460fb..b8999bb 100644 --- a/test/init-test.js +++ b/test/init-test.js @@ -3,7 +3,7 @@ import * as lazy from '../source' describe(`init()`, function () { const lst = lazy.list(1, 2, 3) it(`should return all the elements of a list except the last one`, function () { - lazy.init(lst).should.eql(lazy.list(1, 2)) + lazy.init(lst).isEq(lazy.list(1, 2)).should.be.true }) it(`should throw an error if the list is empty`, function () { lazy.init.bind(null, lazy.emptyList).should.throw() diff --git a/test/iterate-test.js b/test/iterate-test.js index 30ce59a..dc7f2fb 100644 --- a/test/iterate-test.js +++ b/test/iterate-test.js @@ -2,8 +2,9 @@ import * as lazy from '../source' describe(`iterate()`, function () { const inf = lazy.iterate(x => x * 2, 1) + const lst = lazy.list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512) it(`should return an infinite list of repeated applications of a function to a value`, function () { - lazy.take(10, inf).should.eql(lazy.list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512)) + lazy.take(10, inf).isEq(lst).should.be.true lazy.index(inf, 10).should.equal(1024) }) }) diff --git a/test/list-class-test.js b/test/list-class-test.js index 6f016ec..4488197 100644 --- a/test/list-class-test.js +++ b/test/list-class-test.js @@ -90,9 +90,9 @@ describe(`List`, function () { const lst1 = lazy.list(1, 2, 3) const lst2 = lazy.list(4, 5, 6) it(`should append the first list to the second, satisfying the monoid laws`, function () { - lst1.mappend(lazy.emptyList).should.eql(lst1) - lazy.emptyList.mappend(lst1).should.eql(lst1) - lst1.mappend(lst2).should.eql(lazy.list(1, 2, 3, 4, 5, 6)) + lst1.mappend(lazy.emptyList).isEq(lst1).should.be.true + lazy.emptyList.mappend(lst1).isEq(lst1).should.be.true + lst1.mappend(lst2).isEq(lazy.list(1, 2, 3, 4, 5, 6)).should.be.true }) }) describe(`#foldr()`, function () { @@ -107,23 +107,23 @@ describe(`List`, function () { const lst = lazy.list(1, 2, 3) const f = x => lazy.list(x * 10) it(`should map a function that returns a list over a list and collect the results`, function () { - lst.traverse(f).should.eql(lazy.list(lazy.list(10, 20, 30))) - lazy.emptyList.traverse(f).should.eql(lazy.list(lazy.emptyList)) + lst.traverse(f).isEq(lazy.list(10, 20, 30)).should.be.true + lazy.emptyList.traverse(f).isEq(lazy.list(lazy.emptyList)).should.be.true }) }) describe(`#fmap()`, function () { const lst = lazy.list(1, 2, 3) const f = x => x * 10 it(`should map a function over a list and return a new list containing the results`, function () { - lst.fmap(f).should.eql(lazy.list(10, 20, 30)) + lst.fmap(f).isEq(lazy.list(10, 20, 30)).should.be.true }) }) describe(`#pure()`, function () { const lst = lazy.list(1, 2, 3) it(`should return a new list containing the argument value`, function () { - lst.pure(1).should.eql(lazy.list(1)) - lst.pure(lst).should.eql(lazy.list(lst)) - lazy.emptyList.pure(lazy.emptyList).should.eql(lazy.list(lazy.list())) + lst.pure(1).isEq(lazy.list(1)).should.be.true + lst.pure(lst).isEq(lazy.list(lst)).should.be.true + lazy.emptyList.pure(lazy.emptyList).isEq(lazy.list(lazy.list())).should.be.true }) }) describe(`#ap()`, function () { @@ -132,17 +132,16 @@ describe(`List`, function () { const fs1 = lazy.list(f) const fs2 = lazy.list(f, f, f) it(`should sequentially apply the function(s) contained in a list to another list of values and collect the results in a new list`, function () { - fs1.ap(lst).should.eql(lazy.list(10, 20, 30)) - fs1.ap(lazy.emptyList).should.equal(lazy.emptyList) - fs2.ap(lst).should.eql(lazy.list(10, 20, 30, 10, 20, 30, 10, 20, 30)) + fs1.ap(lst).isEq(lazy.list(10, 20, 30)).should.be.true + fs1.ap(lazy.emptyList).isEq(lazy.emptyList).should.be.true + fs2.ap(lst).isEq(lazy.list(10, 20, 30, 10, 20, 30, 10, 20, 30)).should.be.true }) }) describe(`#flatMap()`, function () { const lst = lazy.list(1, 2, 3) const f = x => lazy.list(x * 10) it(`should map a function that returns a list over a list, collect the results, and flatten the list`, function () { - lst.flatMap(f).should.eql(lazy.list(10, 20, 30)) - lazy.emptyList.flatMap(f).should.equal(lazy.emptyList) + lst.flatMap(f).isEq(lazy.list(10, 20, 30)).should.be.true }) }) describe(`#then()`, function () { @@ -151,9 +150,9 @@ describe(`List`, function () { const f = x => x * 10 const fs = lazy.list(f) it(`should sequentially apply the elements of one list to another but ignore the values of the first list`, function () { - lst1.then(lst2).should.eql(lazy.list(4, 5, 6, 4, 5, 6, 4, 5, 6)) + lst1.then(lst2).isEq(lazy.list(4, 5, 6, 4, 5, 6, 4, 5, 6)).should.be.true lst1.then(lazy.emptyList).should.equal(lazy.emptyList) - fs.then(lst1).should.eql(lazy.list(1, 2, 3, 1, 2, 3, 1, 2, 3)) + fs.then(lst1).isEq(lazy.list(1, 2, 3, 1, 2, 3, 1, 2, 3)).should.be.true }) }) describe(`#toString()`, function () { diff --git a/test/list-test.js b/test/list-test.js index a3ebb96..9c939a6 100644 --- a/test/list-test.js +++ b/test/list-test.js @@ -3,6 +3,6 @@ import * as lazy from '../source' describe(`list()`, function () { const lst = lazy.list(1, 2, 3) it(`should create a new list from a series of zero or more values`, function () { - lazy.list(1, 2, 3).should.eql(lst) + lazy.list(1, 2, 3).isEq(lst).should.be.true }) }) diff --git a/test/listAppend-test.js b/test/listAppend-test.js index 49e282b..d386002 100644 --- a/test/listAppend-test.js +++ b/test/listAppend-test.js @@ -3,7 +3,8 @@ import * as lazy from '../source' describe(`listAppend()`, function () { const lst1 = lazy.list(1, 2, 3) const lst2 = lazy.list(4, 5, 6) + const lst3 = lazy.list(1, 2, 3, 4, 5, 6) it(`should append one list to another`, function () { - lazy.listAppend(lst1, lst2).should.eql(lazy.list(1, 2, 3, 4, 5, 6)) + lazy.listAppend(lst1, lst2).isEq(lst3).should.be.true }) }) diff --git a/test/listInf-test.js b/test/listInf-test.js index 0fcfb59..aed2885 100644 --- a/test/listInf-test.js +++ b/test/listInf-test.js @@ -4,7 +4,7 @@ describe(`listInf()`, function () { const lst = lazy.list(1, 2, 3) const inf = lazy.listInf(1) it(`should generate an infinite list`, function () { - lazy.take(3, inf).should.eql(lst) + lazy.take(3, inf).isEq(lst).should.be.true lazy.index(inf, 1000).should.equal(1001) }) }) diff --git a/test/listInfBy-test.js b/test/listInfBy-test.js index b008ad7..f53b0b8 100644 --- a/test/listInfBy-test.js +++ b/test/listInfBy-test.js @@ -3,7 +3,7 @@ import * as lazy from '../source' describe(`listInfBy()`, function () { const inf = lazy.listInfBy(1, x => x * 2) it(`should generate an infinite list`, function () { - lazy.take(3, inf).should.eql(lazy.list(1, 2, 4)) + lazy.take(3, inf).isEq(lazy.list(1, 2, 4)).should.be.true lazy.index(inf, 10).should.equal(1024) }) }) diff --git a/test/listRange-test.js b/test/listRange-test.js index 6b1185b..897362c 100644 --- a/test/listRange-test.js +++ b/test/listRange-test.js @@ -3,11 +3,13 @@ import * as lazy from '../source' describe(`listRange()`, function () { const lst1 = lazy.listRange(0, 10) const lst2 = lazy.listRange(10, 0) + const lst3 = lazy.list(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + const lst4 = lazy.list(10, 9, 8, 7, 6, 5, 4, 3, 2, 1) it(`should build a list from a range of values`, function () { - lst1.should.eql(lazy.list(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) - lst2.should.eql(lazy.list(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)) + lst1.isEq(lst3).should.be.true + lst2.isEq(lst4).should.be.true }) it(`should return a singleton list if the start and end values are the same`, function () { - lazy.listRange(1, 1).should.eql(lazy.list(1)) + lazy.listRange(1, 1).isEq(lazy.list(1)).should.be.true }) }) diff --git a/test/listRangeBy-test.js b/test/listRangeBy-test.js index 72e626a..772c0dd 100644 --- a/test/listRangeBy-test.js +++ b/test/listRangeBy-test.js @@ -3,11 +3,13 @@ import * as lazy from '../source' describe(`listRangeBy()`, function () { const lst1 = lazy.listRangeBy(0, 50, x => x + 5) const lst2 = lazy.listRangeBy(10, 0, x => x - 1) + const lst3 = lazy.list(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50) + const lst4 = lazy.list(10, 9, 8, 7, 6, 5, 4, 3, 2, 1) it(`should build a list from a range of values`, function () { - lst1.should.eql(lazy.list(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50)) - lst2.should.eql(lazy.list(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)) + lst1.isEq(lst3).should.be.true + lst2.isEq(lst4).should.be.true }) it(`should return a singleton list if the start and end values are the same`, function () { - lazy.listRangeBy(1, 1).should.eql(lazy.list(1)) + lazy.listRangeBy(1, 1).isEq(lazy.list(1)).should.be.true }) }) diff --git a/test/map-test.js b/test/map-test.js index eb4d7a9..f8927a7 100644 --- a/test/map-test.js +++ b/test/map-test.js @@ -2,8 +2,9 @@ import * as lazy from '../source' describe(`map()`, function () { const lst1 = lazy.list(1, 2, 3) + const lst2 = lazy.list(3, 6, 9) const f = x => x * 3 it(`should map a function over a list and return the results in a new list`, function () { - lazy.map(f, lst1).should.eql(lazy.list(3, 6, 9)) + lazy.map(f, lst1).isEq(lst2).should.be.true }) }) diff --git a/test/repeat-test.js b/test/repeat-test.js index c423d99..298a5dc 100644 --- a/test/repeat-test.js +++ b/test/repeat-test.js @@ -2,8 +2,9 @@ import * as lazy from '../source' describe(`repeat()`, function () { const inf = lazy.repeat(3) + const lst = lazy.list(3, 3, 3, 3, 3, 3, 3, 3, 3, 3) it(`should build an infinite list of identical values`, function () { - lazy.take(10, inf).should.eql(lazy.list(3, 3, 3, 3, 3, 3, 3, 3, 3, 3)) + lazy.take(10, inf).isEq(lst).should.be.true lazy.index(inf, 100).should.equal(3) }) }) diff --git a/test/replicate-test.js b/test/replicate-test.js index 8cf596e..7219bb3 100644 --- a/test/replicate-test.js +++ b/test/replicate-test.js @@ -1,7 +1,8 @@ import * as lazy from '../source' describe(`replicate()`, function () { + const lst = lazy.list(3, 3, 3, 3, 3, 3, 3, 3, 3, 3) it(`should return a list of a specified length in which every value is the same`, function () { - lazy.replicate(10, 3).should.eql(lazy.list(3, 3, 3, 3, 3, 3, 3, 3, 3, 3)) + lazy.replicate(10, 3).isEq(lst).should.be.true }) }) diff --git a/test/reverse-test.js b/test/reverse-test.js index f2ff27e..c6916f5 100644 --- a/test/reverse-test.js +++ b/test/reverse-test.js @@ -4,6 +4,6 @@ describe(`reverse()`, function () { const lst1 = lazy.list(1, 2, 3) const lst2 = lazy.list(3, 2, 1) it(`should reverse a list`, function () { - lazy.reverse(lst1).should.eql(lst2) + lazy.reverse(lst1).isEq(lst2).should.be.true }) }) diff --git a/test/sort-test.js b/test/sort-test.js index dfcb8e6..4c5a41f 100644 --- a/test/sort-test.js +++ b/test/sort-test.js @@ -8,11 +8,11 @@ describe(`sort()`, function () { const lst5 = lazy.list(20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9) const lst6 = lazy.list(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 30) it(`should sort a list using a merge sort algorithm`, function () { - lazy.sort(lst1).should.eql(lst1) - lazy.sort(lst2).should.eql(lst1) - lazy.sort(lazy.list(1)).should.eql(lazy.list(1)) - lazy.sort(lazy.list()).should.equal(lazy.emptyList) - lazy.sort(lst3).should.eql(lst4) - lazy.sort(lst5).should.eql(lst6) + lazy.sort(lst1).isEq(lst1).should.be.true + lazy.sort(lst2).isEq(lst1).should.be.true + lazy.sort(lazy.list(1)).isEq(lazy.list(1)).should.be.true + lazy.sort(lazy.list()).isEq(lazy.emptyList).should.be.true + lazy.sort(lst3).isEq(lst4).should.be.true + lazy.sort(lst5).isEq(lst6).should.be.true }) }) diff --git a/test/sortBy-test.js b/test/sortBy-test.js index 6a6f307..2cb6b93 100644 --- a/test/sortBy-test.js +++ b/test/sortBy-test.js @@ -9,7 +9,7 @@ describe(`sort()`, function () { const lst2 = lazy.list(10, 9, 8, 7, 6, 5, 4, 3, 2, 1) const lst3 = lazy.listRange(0, 10) it(`should sort a list using a merge sort algorithm and a custom comparison function`, function () { - lazy.sortBy((a, b) => a === b ? EQ : (a < b ? GT : LT), lst2).should.eql(lst2) - lazy.sortBy((a, b) => a === b ? EQ : (a < b ? LT : GT), lst3).should.eql(lst1) + lazy.sortBy((a, b) => a === b ? EQ : (a < b ? GT : LT), lst2).isEq(lst2).should.be.true + lazy.sortBy((a, b) => a === b ? EQ : (a < b ? LT : GT), lst3).isEq(lst1).should.be.true }) }) diff --git a/test/tail-test.js b/test/tail-test.js index f10f3cc..1aefff7 100644 --- a/test/tail-test.js +++ b/test/tail-test.js @@ -3,7 +3,7 @@ import * as lazy from '../source' describe(`tail()`, function () { const lst = lazy.list(1, 2, 3) it(`should extract the elements after the head of a list`, function () { - lazy.tail(lst).should.eql(lazy.list(2, 3)) + lazy.tail(lst).isEq(lazy.list(2, 3)).should.be.true }) it(`should throw an error if the list is empty`, function () { lazy.tail.bind(null, lazy.emptyList).should.throw() diff --git a/test/take-test.js b/test/take-test.js index c2db7f9..df022c9 100644 --- a/test/take-test.js +++ b/test/take-test.js @@ -3,7 +3,7 @@ import * as lazy from '../source' describe(`take()`, function () { const lst = lazy.list(1, 2, 3) it(`should return the prefix of a list of a given length`, function () { - lazy.take(2, lst).should.eql(lazy.list(1, 2)) + lazy.take(2, lst).isEq(lazy.list(1, 2)).should.be.true }) it(`should return the empty list if the second argument is the empty list`, function () { lazy.take(2, lazy.list()).should.equal(lazy.emptyList) diff --git a/test/takeWhile-test.js b/test/takeWhile-test.js index 679c742..e67c3e9 100644 --- a/test/takeWhile-test.js +++ b/test/takeWhile-test.js @@ -4,7 +4,7 @@ describe(`takeWhile()`, function () { const lst = lazy.list(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) const f = x => x < 3 it(`should return the longest prefix of a list of values that satisfy a predicate function`, function () { - lazy.takeWhile(f, lst).should.eql(lazy.list(0, 1, 2)) + lazy.takeWhile(f, lst).isEq(lazy.list(0, 1, 2)).should.be.true }) it(`should return an empty list if the second argument is an empty list`, function () { lazy.takeWhile(f, lazy.emptyList).should.equal(lazy.emptyList)