Skip to content

Commit

Permalink
fix(tests): change mechanism for testing list equality
Browse files Browse the repository at this point in the history
  • Loading branch information
sjsyrek committed Aug 28, 2016
1 parent 692e342 commit dc568e9
Show file tree
Hide file tree
Showing 26 changed files with 62 additions and 54 deletions.
2 changes: 1 addition & 1 deletion test/concat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
4 changes: 2 additions & 2 deletions test/cons-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
2 changes: 1 addition & 1 deletion test/cycle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
4 changes: 2 additions & 2 deletions test/drop-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
4 changes: 2 additions & 2 deletions test/dropWhile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
2 changes: 1 addition & 1 deletion test/filter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
2 changes: 1 addition & 1 deletion test/fromArrayToList-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
2 changes: 1 addition & 1 deletion test/fromStringToList-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
2 changes: 1 addition & 1 deletion test/init-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion test/iterate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
31 changes: 15 additions & 16 deletions test/list-class-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion test/list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
3 changes: 2 additions & 1 deletion test/listAppend-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
2 changes: 1 addition & 1 deletion test/listInf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
2 changes: 1 addition & 1 deletion test/listInfBy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
8 changes: 5 additions & 3 deletions test/listRange-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
8 changes: 5 additions & 3 deletions test/listRangeBy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
3 changes: 2 additions & 1 deletion test/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
3 changes: 2 additions & 1 deletion test/repeat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
3 changes: 2 additions & 1 deletion test/replicate-test.js
Original file line number Diff line number Diff line change
@@ -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
})
})
2 changes: 1 addition & 1 deletion test/reverse-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
12 changes: 6 additions & 6 deletions test/sort-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
4 changes: 2 additions & 2 deletions test/sortBy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
2 changes: 1 addition & 1 deletion test/tail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/take-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/takeWhile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dc568e9

Please sign in to comment.