Skip to content

Commit

Permalink
(pair) test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Mar 10, 2019
1 parent eb6b972 commit 321d50c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const removeEventListeners = (node, listeners) => {

/**
* @param {string} name
* @param {Array<pair.Pair<string,string>>} attrs Array of key-value pairs
* @param {Array<pair.Pair<string,string>|pair.Pair<string,boolean>>} attrs Array of key-value pairs
* @param {Array<Node>} children
* @return {Element}
*/
Expand Down
16 changes: 9 additions & 7 deletions pair.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

/**
* @template L
* @template R
* @template L,R
*/
export class Pair {
/**
Expand All @@ -14,21 +13,24 @@ export class Pair {
}
}

/**
* @template L,R
* @param {L} left
* @param {R} right
* @return {Pair<L,R>}
*/
export const create = (left, right) => new Pair(left, right)
export const createReversed = (right, left) => new Pair(left, right)

/**
* @template L
* @template R
* @template L,R
* @param {Array<Pair<L,R>>} arr
* @param {function(L, R):any} f
*/
export const forEach = (arr, f) => arr.forEach(p => f(p.left, p.right))

/**
* @template L
* @template R
* @template X
* @template L,R,X
* @param {Array<Pair<L,R>>} arr
* @param {function(L, R):X} f
* @return {Array<X>}
Expand Down
18 changes: 18 additions & 0 deletions pair.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as t from './testing.js'
import * as pair from './pair.js'
import * as math from './math.js'

export const testPair = tc => {
const ps = [pair.create(1, 2), pair.create(3, 4), pair.createReversed(6, 5)]
t.describe('Counting elements in pair list')
let countLeft = 0
let countRight = 0
pair.forEach(ps, (left, right) => {
countLeft += left
countRight += right
})
t.assert(countLeft === 9)
t.assert(countRight === 12)
t.assert(countLeft === pair.map(ps, left => left).reduce(math.add))
t.assert(countRight === pair.map(ps, (left, right) => right).reduce(math.add))
}
4 changes: 3 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as promise from './promise.test.js'
import * as map from './map.test.js'
import * as eventloop from './eventloop.test.js'
import * as time from './time.test.js'
import * as pair from './pair.test.js'

import { isBrowser, isNode } from './environment.js'

Expand All @@ -37,7 +38,8 @@ runTests({
promise,
map,
eventloop,
time
time,
pair
}).then(success => {
/* istanbul ignore next */
if (isNode) {
Expand Down

0 comments on commit 321d50c

Please sign in to comment.