-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathTreesSpec.scala
97 lines (82 loc) · 2.7 KB
/
TreesSpec.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.thoughtworks.compute
import com.thoughtworks.compute.Trees.AllTrees
import com.thoughtworks.feature.Factory
import org.scalatest.Assertion
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers
/**
* @author 杨博 (Yang Bo)
*/
final class TreesSpec extends AnyFreeSpec with Matchers {
private val trees: AllTrees = Factory[AllTrees with Trees.StructuralTrees].newInstance()
private def reflexive(term: => trees.Term): Assertion = {
val t0 = term
val t1 = term
t0 should be(t0)
t0.## should be(t0.##)
t1 should be(t1)
t1.## should be(t1.##)
t0 should be(t1)
t0.## should be(t1.##)
sameStructuralDifferentParameterName(t0, t0.alphaConversion)
}
private def sameStructuralDifferentParameterName(term1: trees.Term, term2: trees.Term): Assertion = {
term1 should be(term2)
term1.## should be(term2.##)
}
private def differentStructural(term1: trees.Term, term2: trees.Term): Assertion = {
term1 shouldNot be(term2)
term1.## shouldNot be(term2.##)
}
"float" in {
reflexive(trees.float.parameter("my_id"))
reflexive(trees.float.literal(42.0f))
sameStructuralDifferentParameterName(trees.float.parameter("my_id_1"), trees.float.parameter("my_id_2"))
}
"array" in {
reflexive(trees.array.parameter("my_id", trees.float.literal(42.0f), Array(12, 34)))
sameStructuralDifferentParameterName(trees.array.parameter("my_id_3", trees.float.literal(42.0f), Array(12, 34)),
trees.array.parameter("my_id_4", trees.float.literal(42.0f), Array(12, 34)))
differentStructural(
trees.array.parameter("my_id", trees.float.literal(0.1f), Array(12, 34)),
trees.array.parameter("my_id2", trees.float.literal(99.9f), Array(56, 78))
)
}
"tuple.zip" - {
"reflexive" in {
reflexive(
trees.tuple.join(
trees.float.parameter("my_id"),
trees.float.literal(2.0f),
trees.float.literal(3.0f)
)
)
}
"sameStructuralDifferentParameterName" in {
sameStructuralDifferentParameterName(
trees.tuple.join(
trees.float.parameter("my_id1"),
trees.float.parameter("my_id2"),
trees.float.literal(0.0f)
),
trees.tuple.join(
trees.float.parameter("my_id2"),
trees.float.parameter("my_id3"),
trees.float.literal(0.0f)
)
)
}
"differentStructural" in {
differentStructural(
trees.tuple.join(
trees.float.literal(1.0f),
trees.float.literal(0.0f)
),
trees.tuple.join(
trees.float.literal(0.0f),
trees.float.literal(1.0f)
)
)
}
}
}