diff options
author | David Symonds <dsymonds@golang.org> | 2009-04-19 23:52:29 -0700 |
---|---|---|
committer | David Symonds <dsymonds@golang.org> | 2009-04-19 23:52:29 -0700 |
commit | 476cc3254015d18836029b9e871fb690d27e2ac0 (patch) | |
tree | ddccebe6eef326f435652eb02df1bd4d44d611c6 /src/lib/container/iterable_test.go | |
parent | cb66f00f1f58c07847be18dc43223cd09b5d04aa (diff) | |
download | golang-476cc3254015d18836029b9e871fb690d27e2ac0.tar.gz |
Add Inject function to iterable package.
Fix a couple of style mistakes.
R=r,rsc
APPROVED=r
DELTA=34 (30 added, 1 deleted, 3 changed)
OCL=27623
CL=27623
Diffstat (limited to 'src/lib/container/iterable_test.go')
-rw-r--r-- | src/lib/container/iterable_test.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/lib/container/iterable_test.go b/src/lib/container/iterable_test.go index f266a955b..ceb1de6e4 100644 --- a/src/lib/container/iterable_test.go +++ b/src/lib/container/iterable_test.go @@ -42,6 +42,9 @@ func doubler(n interface {}) interface {} { func addOne(n interface {}) interface {} { return n.(int) + 1 } +func adder(acc interface {}, n interface {}) interface {} { + return acc.(int) + n.(int) +} // A stream of the natural numbers: 0, 1, 2, 3, ... type integerStream struct {} @@ -107,6 +110,13 @@ func TestFind(t *testing.T) { } } +func TestInject(t *testing.T) { + res := Inject(oneToFive, 0, adder); + if res.(int) != 15 { + t.Errorf("Inject(oneToFive, 0, adder) = %v, want 15", res) + } +} + func TestMap(t *testing.T) { res := Data(Map(Map(oneToFive, doubler), addOne)); assertArraysAreEqual(t, res, []int{ 3, 5, 7, 9, 11 }) |