2015-10-17 00:07:37 +03:00
|
|
|
final class DiffTests: XCTestCase {
|
|
|
|
override static func setUp() {
|
|
|
|
sranddev()
|
|
|
|
}
|
2015-10-17 00:13:51 +03:00
|
|
|
|
|
|
|
typealias Term = RangedTerm.Term
|
|
|
|
typealias Diff = Free<String, Patch<Term>>
|
2015-10-17 00:13:59 +03:00
|
|
|
|
|
|
|
let interpreter = Interpreter<Term>(equal: ==, comparable: const(true), cost: Diff.sum(const(1)))
|
2015-10-17 00:14:08 +03:00
|
|
|
|
|
|
|
func testEqualTermsProduceIdentityDiffs() {
|
|
|
|
property("equal terms produce identity diffs") <- forAll { (term: RangedTerm) in
|
|
|
|
Diff.sum(const(1))(self.interpreter.run(term.term, term.term)) == 0
|
|
|
|
}
|
|
|
|
}
|
2015-10-17 00:26:35 +03:00
|
|
|
|
|
|
|
func testEqualityIsReflexive() {
|
|
|
|
property("equality is reflexive") <- forAll { (diff: RangedDiff) in
|
|
|
|
Free.equals(ifPure: Patch.equals(Cofree.equals(annotation: ==, leaf: ==)), ifRoll: ==)(diff.diff, diff.diff)
|
|
|
|
}
|
|
|
|
}
|
2015-10-17 00:34:34 +03:00
|
|
|
|
|
|
|
func testOriginalTermsAreRecoverable() {
|
|
|
|
let equal = Cofree<String, ()>.equals(annotation: const(true), leaf: ==)
|
|
|
|
property("before state is recoverable") <- forAll { (diff: RangedDiff) in
|
|
|
|
return diff.diff.map { $0.map { $0.map(const(())) } }.before.map {
|
|
|
|
equal($0, diff.a.map(const(())))
|
|
|
|
} ?? false
|
|
|
|
}
|
2015-10-17 00:35:18 +03:00
|
|
|
|
|
|
|
property("after state is recoverable") <- forAll { (diff: RangedDiff) in
|
|
|
|
return diff.diff.map { $0.map { $0.map(const(())) } }.after.map {
|
|
|
|
equal($0, diff.b.map(const(())))
|
|
|
|
} ?? false
|
|
|
|
}
|
2015-10-17 00:34:34 +03:00
|
|
|
}
|
2015-10-17 00:07:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@testable import Doubt
|
2015-10-17 00:13:59 +03:00
|
|
|
import Prelude
|
2015-10-17 00:07:37 +03:00
|
|
|
import SwiftCheck
|
|
|
|
import XCTest
|