1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00
semantic/prototype/DoubtTests/RangedDiff.swift

30 lines
888 B
Swift
Raw Normal View History

2015-10-17 00:17:48 +03:00
struct RangedDiff {
2015-10-22 23:02:03 +03:00
typealias Diff = Free<String, (RangedTerm.Term.Annotation, RangedTerm.Term.Annotation), Patch<RangedTerm.Term>>
2015-10-17 00:17:48 +03:00
2015-10-19 18:47:52 +03:00
let a: RangedTerm
let b: RangedTerm
2015-10-17 00:17:48 +03:00
let diff: Diff
}
2015-10-17 00:21:45 +03:00
extension RangedDiff: Arbitrary {
2015-10-19 18:47:52 +03:00
static let interpreter = Interpreter<RangedTerm.Term>(equal: ==, comparable: const(true), cost: Diff.sum(Patch.difference))
2015-10-17 00:21:45 +03:00
static var arbitrary: Gen<RangedDiff> {
return RangedTerm.arbitrary.bind { a in
RangedTerm.arbitrary.fmap { b in
2015-10-19 18:47:52 +03:00
RangedDiff(a: a, b: b, diff: interpreter.run(a.term, b.term))
2015-10-17 00:21:45 +03:00
}
}
}
2015-10-19 18:49:05 +03:00
static func shrink(diff: RangedDiff) -> [RangedDiff] {
return RangedTerm.shrink(diff.a).map { RangedDiff(a: $0, b: diff.b, diff: interpreter.run($0.term, diff.b.term)) }
+ RangedTerm.shrink(diff.b).map { RangedDiff(a: diff.a, b: $0, diff: interpreter.run(diff.a.term, $0.term)) }
}
2015-10-17 00:21:45 +03:00
}
2015-10-17 00:17:48 +03:00
import Doubt
2015-10-17 00:21:45 +03:00
import Prelude
import SwiftCheck