z3 0.0.20181126 → 0.0.20181229

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/z3/ast.rb +8 -0
  4. data/spec/expr_spec.rb +62 -0
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c93f27f8597c24344b97bcb79677cb1c91d92d626e457600ab36e355db41586
4
- data.tar.gz: a85deb034bee0faeb6a6c4283e85657cf394ae7ec2643b91f4d8d249ac337748
3
+ metadata.gz: b88561867f390fe0aa80a1744d15f5daf65e018e3eec21c659aaaa4747a33774
4
+ data.tar.gz: 8b78a9f60131dcf2f3945894ea1e5e418910729ebae07868e3447713529e71a5
5
5
  SHA512:
6
- metadata.gz: 34781021336dab28fe7969b707638461bd8da2bb1b331038ca10e0c7eb015582c478360f0264c2174b517807e99bbf7598431dd985b39b3d0472fea8b550d23f
7
- data.tar.gz: e382c7d4caa935adda0172436e4d3f7e6499dd46c4dcb0f2a95ee641ac1487c2bb06035a7fe6c6d40f35a1d9d664a3948cd26fac856d890833f0ec8c85eb6b71
6
+ metadata.gz: 72c8908ad9bb03adce26c2ab5b10a32fb651cc0c970f3f3c346c4b9a7db98eafd839a313875bee213f5d0caef29c0fea5f09f234765bb0150fd0da2a04ee33fd
7
+ data.tar.gz: d6385ee4215aee32b4bc50b427f48afed7efdc8637c0ffd6d4ccd4af8345d41acc9d4beae79f3ccf7bb9408b6fad527af430e87c32c1a9fc28c402be97cb19b5
data/README.md CHANGED
@@ -12,7 +12,7 @@ You can use most Ruby operators to construct Z3 expressions, but use `| &` inste
12
12
 
13
13
  The interface is potentially unstable, and can change in the future.
14
14
 
15
- `Z3::VeryLowLever` and `Z3::LowLevel` are FFI interface for internal use, and they shouldn't be used directly. Also don't use any method starting with `_`. Doing this is likely to lead to segmentation faults unless extreme care is taken.
15
+ `Z3::VeryLowLevel` and `Z3::LowLevel` are FFI interfaces for internal use, and they shouldn't be used directly. Also don't use any method starting with `_`. Doing this is likely to lead to segmentation faults unless extreme care is taken.
16
16
 
17
17
  A utility at `api/gen_api` will loop through a .h file and generate Ruby definitions. This will update the API when upstream changes `z3_api.h`
18
18
 
@@ -46,6 +46,14 @@ module Z3
46
46
  sort.new(LowLevel.simplify(self))
47
47
  end
48
48
 
49
+ def eql?(other)
50
+ self.class == other.class and self._ast == other._ast
51
+ end
52
+
53
+ def hash
54
+ _ast.address
55
+ end
56
+
49
57
  private_class_method :new
50
58
  end
51
59
  end
@@ -183,4 +183,66 @@ module Z3
183
183
  end
184
184
  end
185
185
  end
186
+
187
+ describe "#hash / #eql?" do
188
+ let(:x1) { Z3.Int("x") }
189
+ let(:x2) { Z3.Int("x") }
190
+ let(:y1) { Z3.Int("y") }
191
+ let(:y2) { Z3.Int("y") }
192
+ let(:e1) { x1 + y1 }
193
+ let(:e2) { x2 + y2 }
194
+ let(:f1) { y1 + x1 }
195
+ let(:f2) { y2 + x2 }
196
+ let(:samples) { [x1, x2, y1, y2, e1, e2, f1, f2] }
197
+
198
+ it "object is eql? to itself" do
199
+ expect(x1.eql?(x1)).to be true
200
+ expect(y1.eql?(y1)).to be true
201
+ expect(e1.eql?(e1)).to be true
202
+
203
+ expect(x1.eql?(y1)).to be false
204
+ expect(x1.eql?(e1)).to be false
205
+ end
206
+
207
+ it "object is eql? to structurally identical object" do
208
+ expect(x1.eql?(x2)).to be true
209
+ expect(y1.eql?(y2)).to be true
210
+ expect(e1.eql?(e2)).to be true
211
+ expect(f1.eql?(f2)).to be true
212
+ end
213
+
214
+ it "object is not eql? to semantically identical object" do
215
+ expect(e1.eql?(f1)).to be false
216
+ end
217
+
218
+ it "#hash aligns with #eql?" do
219
+ samples.each do |a|
220
+ samples.each do |b|
221
+ if a.eql?(b)
222
+ expect(a.hash).to eq(b.hash)
223
+ else
224
+ expect(a.hash).to_not eq(b.hash)
225
+ end
226
+ end
227
+ end
228
+ end
229
+
230
+ it "works when used as Hash keys" do
231
+ ht = {}
232
+ ht[x1] = 1
233
+ ht[y1] = 2
234
+ ht[e1] = 3
235
+ ht[e2] = 4
236
+
237
+ expect(ht.size).to eq(3)
238
+ expect(ht[x1]).to eq(1)
239
+ expect(ht[x2]).to eq(1)
240
+ expect(ht[y1]).to eq(2)
241
+ expect(ht[y2]).to eq(2)
242
+ expect(ht[e1]).to eq(4)
243
+ expect(ht[e2]).to eq(4)
244
+ expect(ht[f1]).to eq(nil)
245
+ expect(ht[f2]).to eq(nil)
246
+ end
247
+ end
186
248
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: z3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20181126
4
+ version: 0.0.20181229
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Wegrzanowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-26 00:00:00.000000000 Z
11
+ date: 2018-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry