diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2013-04-10 15:05:28 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-11-10 18:03:23 +0100 |
commit | 32021a0347c4f364a3407ced8455dff139b18adb (patch) | |
tree | 898a3508b24f1505c5324729bb4be6e0f761a6c7 /Scala/funsets/src/test | |
parent | c09ffb13d5d3e2d13b336ffc455dd2b2307f7f37 (diff) | |
download | coursera-32021a0347c4f364a3407ced8455dff139b18adb.zip coursera-32021a0347c4f364a3407ced8455dff139b18adb.tar.gz |
Scala : week2: implement forall, exists, map
Diffstat (limited to 'Scala/funsets/src/test')
-rw-r--r-- | Scala/funsets/src/test/scala/funsets/FunSetSuite.scala | 60 |
1 files changed, 50 insertions, 10 deletions
diff --git a/Scala/funsets/src/test/scala/funsets/FunSetSuite.scala b/Scala/funsets/src/test/scala/funsets/FunSetSuite.scala index 7c3fd53..4ca61a5 100644 --- a/Scala/funsets/src/test/scala/funsets/FunSetSuite.scala +++ b/Scala/funsets/src/test/scala/funsets/FunSetSuite.scala @@ -77,6 +77,8 @@ class FunSetSuite extends FunSuite { val s1 = singletonSet(1) val s2 = singletonSet(2) val s3 = singletonSet(3) + def boundedSet(m: Int, n: Int): Set = x => x >= m && x <= n + val v13 = boundedSet(1,3) } /** @@ -165,16 +167,54 @@ class FunSetSuite extends FunSuite { test("filter") { new TestSets { - val s = filter(s1, (x => x == 1)) - assert(!contains(s, 0), "Filter none") - assert(contains(s, 1), "Filter 1") - assert(!contains(s, 2), "Filter none") - assert(!contains(s, 3), "Filter none") - val v = filter(s1, (x => x == 0)) - assert(!contains(v, 0), "Filter none") - assert(!contains(v, 1), "Filter none") - assert(!contains(v, 2), "Filter none") - assert(!contains(v, 3), "Filter none") + val s = filter(s1, x => x == 1) + assert(!contains(s, 0), "Filter not s 0") + assert(contains(s, 1), "Filter s 1") + assert(!contains(s, 2), "Filter not s 2") + assert(!contains(s, 3), "Filter not s3") + val v = filter(s1, x => x == 0) + assert(!contains(v, 0), "Filter not v 0") + assert(!contains(v, 1), "Filter not v 1") + assert(!contains(v, 2), "Filter not v 2") + assert(!contains(v, 3), "Filter not v 3") + } + } + + test("forall") { + new TestSets { + assert(forall(s1, x => x == 1), "forall 1") + assert(forall(s2, x => x == 2), "forall 2") + assert(forall(s3, x => x == 3), "forall 3") + assert(!forall(s1, x => x == 0), "forall not s1 0") + assert(!forall(s2, x => x == 0), "forall not s2 0") + assert(!forall(s3, x => x == 0), "forall not s3 0") + assert(forall(s1, v13), "s1 v13") + assert(forall(s2, v13), "s2 v13") + assert(forall(s3, v13), "s3 v13") + } + } + + test("exists") { + new TestSets { + assert(exists(v13, x => x == 1), "exists 1") + assert(exists(v13, x => x == 2), "exists 1") + assert(exists(v13, x => x == 3), "exists 1") + assert(!exists(v13, x => x == 0), "exists not 0") + assert(!exists(v13, x => x == 4), "exists not 4") + } + } + + test("map") { + new TestSets { + val x = map(v13, x => x * 3) + assert(contains(x, 3), "map 1") + assert(!contains(x, 4), "map 2") + assert(!contains(x, 5), "map 3") + assert(contains(x, 6), "map 4") + assert(!contains(x, 7), "map 5") + assert(!contains(x, 8), "map 6") + assert(contains(x, 9), "map 7") + assert(!contains(x, 10), "map 8") } } } |