-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconstraint_test.exs
More file actions
191 lines (165 loc) · 5.8 KB
/
Copy pathconstraint_test.exs
File metadata and controls
191 lines (165 loc) · 5.8 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
defmodule HexSolver.ConstraintTest do
use HexSolver.Case, async: true
use ExUnitProperties
alias HexSolver.Constraint
alias HexSolver.Constraints.Union
defp always_lt([left, right | rest]) do
assert Constraint.compare(left, right) == :lt
always_lt([right | rest])
end
defp always_lt([_constraint]) do
:ok
end
describe "allows_any?/2" do
property "commutative" do
check all left <- constraint(),
not Constraint.empty?(left),
right <- constraint(),
not Constraint.empty?(right) do
assert Constraint.allows_any?(left, right) == Constraint.allows_any?(right, left)
end
end
end
describe "compare/2" do
property "ordered" do
check all left <- constraint(),
not Constraint.empty?(left),
right <- constraint(),
not Constraint.empty?(right) do
if Constraint.compare(left, right) == :eq do
assert Constraint.compare(right, left) == :eq
else
assert Constraint.compare(left, right) != Constraint.compare(right, left)
end
end
end
end
describe "difference/2" do
property "allows?/2" do
check all left <- constraint(),
right <- constraint(),
version <- version() do
difference = Constraint.difference(left, right)
if Constraint.allows?(left, version) and not Constraint.allows?(right, version) do
assert Constraint.allows?(difference, version)
else
refute Constraint.allows?(difference, version)
end
end
end
property "allows_any?/2" do
check all left <- constraint(),
right <- constraint(),
constraint <- constraint(),
not Constraint.empty?(constraint) do
difference = Constraint.difference(left, right)
if not Constraint.allows_any?(left, constraint) and
Constraint.allows_any?(right, constraint) do
refute Constraint.allows_any?(difference, constraint)
end
end
end
property "allows_all?/2" do
check all left <- constraint(),
right <- constraint(),
constraint <- constraint() do
difference = Constraint.difference(left, right)
if not Constraint.allows_all?(left, constraint) and
Constraint.allows_all?(right, constraint) do
refute Constraint.allows_all?(difference, constraint)
end
end
end
end
describe "intersect/2" do
property "allows?/2" do
check all left <- constraint(),
right <- constraint(),
version <- version() do
intersection = Constraint.intersect(left, right)
if Constraint.allows?(left, version) and Constraint.allows?(right, version) do
assert Constraint.allows?(intersection, version)
else
refute Constraint.allows?(intersection, version)
end
end
end
property "allows_any?/2" do
check all left <- constraint(),
right <- constraint(),
constraint <- constraint() do
intersection = Constraint.intersect(left, right)
if not Constraint.allows_any?(left, constraint) and
not Constraint.allows_any?(right, constraint) and
not Constraint.empty?(intersection) do
refute Constraint.allows_any?(intersection, constraint)
end
end
end
property "allows_all?/2" do
check all left <- constraint(),
right <- constraint(),
constraint <- constraint() do
intersection = Constraint.intersect(left, right)
if Constraint.allows_all?(left, constraint) and Constraint.allows_all?(right, constraint) do
assert Constraint.allows_all?(intersection, constraint)
else
refute Constraint.allows_all?(intersection, constraint)
end
end
end
end
describe "union/2" do
property "orders unions" do
check all left <- constraint(),
right <- constraint() do
case Constraint.union(left, right) do
%Union{ranges: ranges} -> always_lt(ranges)
_ -> :ok
end
end
end
property "allows?/2" do
check all left <- constraint(),
right <- constraint(),
version <- version() do
union = Constraint.union(left, right)
if Constraint.allows?(left, version) or Constraint.allows?(right, version) do
assert Constraint.allows?(union, version)
else
refute Constraint.allows?(union, version)
end
end
end
property "allows_any?/2" do
check all left <- constraint(),
right <- constraint(),
constraint <- constraint(),
not Constraint.empty?(constraint) do
union = Constraint.union(left, right)
if Constraint.allows_any?(left, constraint) or Constraint.allows_any?(right, constraint) do
assert Constraint.allows_any?(union, constraint)
else
refute Constraint.allows_any?(union, constraint)
end
end
end
property "allows_all?/2" do
check all left <- constraint(),
right <- constraint(),
constraint <- constraint() do
union = Constraint.union(left, right)
if Constraint.allows_all?(left, constraint) or Constraint.allows_all?(right, constraint) do
assert Constraint.allows_all?(union, constraint)
end
end
end
end
property "constraint requirements round-trip" do
check all constraint <- constraint() do
requirement = Constraint.to_requirement(constraint)
assert {:ok, _requirement} = Version.parse_requirement(requirement)
assert HexSolver.parse_constraint!(requirement) == constraint
end
end
end