-
Notifications
You must be signed in to change notification settings - Fork 1
/
RefLawTests.scala
70 lines (59 loc) · 2.22 KB
/
RefLawTests.scala
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
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2016-2024 Daniel Urban and contributors listed in NOTICE.txt
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.tauri.choam
package laws
package discipline
import cats.kernel.Eq
import cats.kernel.laws.discipline.catsLawsIsEqToProp
import org.scalacheck.{ Arbitrary, Cogen }
import org.scalacheck.Prop.forAll
import org.typelevel.discipline.Laws
object RefLawTests {
def apply(ti: TestInstances): RefLawTests = new RefLawTests {
final override def arbRef[A : Arbitrary] =
ti.arbRef
override implicit def eqAxn[A](implicit equA: Eq[A]): Eq[Axn[A]] =
ti.testingEqAxn[A]
override implicit def eqRxn[A, B](implicit arbA: Arbitrary[A], equB: Eq[B]): Eq[Rxn[A, B]] =
ti.testingEqRxn[A, B]
}
}
sealed trait RefLawTests extends Laws {
implicit def arbRef[A : Arbitrary]: Arbitrary[Ref[A]]
implicit def eqAxn[A](implicit equA: Eq[A]): Eq[Axn[A]]
implicit def eqRxn[A, B](implicit arbA: Arbitrary[A], equB: Eq[B]): Eq[Rxn[A, B]]
def laws: RefLaws =
RefLaws.newRefLaws
def ref[A, B, C](
implicit
equC: Eq[C],
arbA: Arbitrary[A],
arbB: Arbitrary[B],
arbC: Arbitrary[C],
cogA: Cogen[A],
cogB: Cogen[B],
): RuleSet = new DefaultRuleSet(
name = "ref",
parent = None,
"equals itself" -> forAll(laws.equalsItself[A] _),
"unique IDs (same type)" -> forAll(laws.uniqueIdsSameType[A] _),
"unique IDs (different type)" -> forAll(laws.uniqueIdsDifferentType[A, B] _),
"hashCode is based on ID" -> forAll(laws.hashCodeBasedOnId[A] _),
"Order consistent with identity" -> forAll(laws.orderConsistentWithIdentity[A] _),
"updWith and ret is upd" -> forAll(laws.updWithRetIsUpd[A, B, C] _),
)
}