Skip to content

Commit

Permalink
test(Pair): add tests for Pair
Browse files Browse the repository at this point in the history
  • Loading branch information
safareli committed Oct 11, 2016
1 parent a451348 commit 35dea85
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion examples/Pair.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ Pair.prototype.equals = function(b) {
Pair.prototype.concat = function(b) {
if (Q.isEmpty(this._1) || Q.isEmpty(this._2)) {
return b
} else if (Q.isEmpty(b) || Q.isEmpty(b._1) || Q.isEmpty(b._2)) {
} else if (Q.isEmpty(b) || (Q.isEmpty(b._1) && Q.isEmpty(b._2))) {
return this
} else if (Q.isEmpty(b._1)) {
return Pair(this._1, this._2[fl.concat](b._2))
} else if (Q.isEmpty(b._2)) {
return Pair(this._1[fl.concat](b._1), this._2)
} else {
return Pair(this._1[fl.concat](b._1), this._2[fl.concat](b._2))
}
Expand Down
2 changes: 2 additions & 0 deletions test/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ const List = require('../examples/List.js')
test('eq', t => {
const a = 'a'
const as = List.fromArray([a])
const a2s = List.fromArray([a,a])

t.equals('Cons(a,Nil)', as.toString())
t.eqFL(as, as.concat(empty))
t.eqFL(a2s, as.concat(as))
t.notOk(List.fromArray([a, a]).equals(List.fromArray([a])))
t.notOk(List.fromArray([a]).equals(List.fromArray([a, a])))
t.eqFL(of(as), of(a).reduce((acc, a) => List.Cons(a, acc), List.Nil))
Expand Down
27 changes: 27 additions & 0 deletions test/Pair.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { test } = require('./lib')

const { of, empty } = require('../src/quasi.js')

const Pair = require('../examples/Pair.js')
const List = require('../examples/List.js')

test('eq', t => {
const a = 'a'
const as = List.fromArray([a])
const a2s = List.fromArray([a, a])
t.eqFL(Pair(as, as), Pair(empty, empty).concat(Pair(as, as)))
t.eqFL(Pair(as, as), Pair(as, as).concat(Pair(empty, empty)))
t.eqFL(Pair(as, as), Pair(as, empty).concat(Pair(as, as)))
t.eqFL(Pair(as, as), Pair(empty, as).concat(Pair(as, as)))
t.eqFL(Pair(as, as), Pair(as, as).concat(empty))
t.eqFL(Pair(as, as), empty.concat(Pair(as, as)))
t.eqFL(Pair(a2s, as), Pair(as, as).concat(Pair(as, empty)))
t.eqFL(Pair(as, a2s), Pair(as, as).concat(Pair(empty, as)))
t.eqFL(Pair(as, as), Pair(as, as).concat(Pair(empty, empty)))
t.eqFL(Pair(a2s, a2s), Pair(as, as).concat(Pair(as, as)))
t.eqFL(Pair(a2s, as), Pair(as, as).concat(Pair(as, empty)))
t.eqFL(Pair(as, a2s), Pair(as, as).map((as) => as.concat(as)))
t.eqFL(Pair(as, as), Pair(as, as).ap(Pair.of(as => as)))
t.eqFL(Pair(a2s, as), Pair(as, as).ap(Pair(as, as => as)))
t.end()
})

0 comments on commit 35dea85

Please sign in to comment.