From 9f5345e476b5e9b2a8d1f0096d80962c1303b25b Mon Sep 17 00:00:00 2001 From: Tim Kuminecz Date: Tue, 20 Dec 2016 01:13:15 -0500 Subject: [PATCH] tests --- src/pair.js | 9 +++++---- test/io.js | 4 +++- test/pair.js | 9 ++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/pair.js b/src/pair.js index 71c5224..f44c11f 100644 --- a/src/pair.js +++ b/src/pair.js @@ -48,12 +48,13 @@ export class Pair { } /** - * `map :: Pair a b ~> ([a, b] -> [x, y]) -> Pair x y` + * `map :: Pair a b ~> (b -> c) -> Pair a c` * - * Transforms the values in the `Pair` instance. + * Transforms the right (second) value in the `Pair` instance. */ - map(f: (p: [A, B]) => [X, Y]): Pair { - return Pair.of(f(this.data)); + map(f: (b: B) => C): Pair { + const [ a, b ] = this.data; + return Pair.of([ a, f(b) ]); } /** diff --git a/test/io.js b/test/io.js index ccb194f..7c9700d 100644 --- a/test/io.js +++ b/test/io.js @@ -6,7 +6,7 @@ import * as Util from './test-util'; const ioMapper = (ia: IO): A => ia.runIO(); test('IO', t => { - t.plan(5); + t.plan(6); const tIO = { t, mapper: ioMapper }; @@ -15,4 +15,6 @@ test('IO', t => { Util.testLift(tIO, IO); Util.testLift2(tIO, IO); Util.testLift3(tIO, IO); + + t.equal(IO.from(() => 42).runIO(), 42, 'IO.from'); }); diff --git a/test/pair.js b/test/pair.js index 7135530..70c32a8 100644 --- a/test/pair.js +++ b/test/pair.js @@ -3,7 +3,7 @@ import { Pair } from '../src/pair'; import test from 'tape'; test('Pair', t => { - t.plan(4); + t.plan(7); let pair = Pair.of([ 'foo', 42 ]); @@ -18,9 +18,12 @@ test('Pair', t => { ); t.deepEqual( - pair.map(([ s, n ]) => [s.toUpperCase(), n * 2]), - Pair.of([ 'FOO', 84 ]), + pair.map(n => n * 2), + Pair.of([ 'foo', 84 ]), 'Pair.map' ); + t.deepEqual(pair.toTuple(), [ 'foo', 42 ], 'pair.toTuple'); + t.equal(pair.left(), 'foo', 'pair.left'); + t.equal(pair.right(), 42, 'pair.right'); });