forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckSet.scala
More file actions
70 lines (52 loc) · 2.18 KB
/
CheckSet.scala
File metadata and controls
70 lines (52 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package fj
package data
import org.scalacheck.Prop._
import data.ArbitrarySet.arbitrarySet
import data.ArbitraryList.arbitraryList
import ArbitraryP.arbitraryP1
import Equal.{setEqual, stringEqual, listEqual}
import Ord.intOrd
import Ord.stringOrd
import P.p
import Unit.unit
import Set.{empty, single, join, iterableSet}
import org.scalacheck.Properties
object CheckSet extends Properties("Set") {
def idInt(n: Int) = n:java.lang.Integer
implicit def oi : Ord[Int] = intOrd.comap(idInt _)
implicit def os : Ord[String] = stringOrd
property("isEmpty") = forAll((a: Set[Int]) =>
a.isEmpty == (a.size == 0))
property("isNotEmpty") = forAll((a: Set[Int]) =>
!a.isEmpty == (a.size > 0))
property("insertMember") = forAll((a: Set[Int], n: Int) =>
a.insert(n).member(n))
property("deleteInsertIsId") = forAll((a: Set[String], s: String) =>
setEqual(stringEqual).eq(a.delete(s).insert(s).delete(s), a.delete(s)))
property("deleteSize") = forAll((a: Set[String], s: String) =>
(a.insert(s).size == a.size + 1) != a.member(s))
property("singleMember") = forAll((n: Int) =>
single(oi, n).member(n))
property("noDupesFromList") = forAll((a: List[String]) =>
setEqual(stringEqual).eq(iterableSet(os, a.nub(stringEqual)), iterableSet(os, a)))
property("noDupesToList") = forAll((a: List[String]) =>
iterableSet(os, a).toList().length() == a.nub(stringEqual).length())
property("subsetEmpty") = forAll((a: Set[Int]) =>
empty(oi).subsetOf(a))
property("subsetUnion") = forAll((a: Set[Int], b: Set[Int]) =>
b.subsetOf(a.union(b)))
property("subsetSelf") = forAll((a: Set[Int]) =>
a.subsetOf(a))
property("subsetSize") = forAll((a: Set[Int], b: Set[Int]) =>
a.size > b.size ==> !a.subsetOf(b))
property("mapId") = forAll((a: Set[String]) =>
setEqual(stringEqual).eq(a.map(os, (x: String) => x), a))
property("updateId") = forAll((a: Set[String], b: String) => {
val s = a.insert(b)
setEqual(stringEqual).eq(s.update(b, (x: String) => x)._2, s)
})
property("update") = forAll((a: Set[String], b: String, c: Char) => {
val s = a.insert(b).delete(c + b)
!setEqual(stringEqual).eq(s.update(b, (x: String) => c + x)._2, s)
})
}