Skip to content

Commit b8b2190

Browse files
committed
fixup! Add Predicate#to_hashes
1 parent 0618507 commit b8b2190

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

spec/predicate/test_to_hashes.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
require 'spec_helper'
2+
class Predicate
3+
describe Predicate, "to_hashes" do
4+
5+
let(:p){ Predicate }
6+
7+
subject{ predicate.to_hashes }
8+
9+
context "tautology" do
10+
let(:predicate){ Predicate.tautology }
11+
12+
it{ expect(subject).to eql([{},{}]) }
13+
end
14+
15+
context "contradiction" do
16+
let(:predicate){ Predicate.contradiction }
17+
18+
it{ expect{ subject }.to raise_error(ArgumentError) }
19+
end
20+
21+
context "eq" do
22+
let(:predicate){ Predicate.eq(:x, 2) }
23+
24+
it{ expect(subject).to eql([{x: 2}, {}]) }
25+
end
26+
27+
context "neq" do
28+
let(:predicate){ Predicate.neq(:x, 2) }
29+
30+
it{ expect(subject).to eql([{},{x: 2}]) }
31+
end
32+
33+
context "in" do
34+
let(:predicate){ Predicate.in(:x, [2,3]) }
35+
36+
it{ expect(subject).to eql([{x: [2,3]},{}]) }
37+
end
38+
39+
context "and" do
40+
let(:predicate){ Predicate.eq(:x, 3) & Predicate.in(:y, [2,3]) }
41+
42+
it{ expect(subject).to eql([{x: 3, y: [2,3]},{}]) }
43+
end
44+
45+
context "and with a neq" do
46+
let(:predicate){ Predicate.neq(:x, 3) & Predicate.in(:y, [2,3]) }
47+
48+
it{ expect(subject).to eql([{y: [2,3]},{x: 3}]) }
49+
end
50+
51+
context "not nil & eq" do
52+
let(:predicate){ Predicate.neq(:x, nil) & Predicate.eq(:x, [2,3]) }
53+
54+
it{ expect(subject).to eql([{x: [2,3]},{x: nil}]) }
55+
end
56+
57+
## unsupported
58+
59+
context "not" do
60+
let(:predicate){ Predicate.not(Predicate.eq(:x, 2)) }
61+
62+
it{ expect{ subject }.to raise_error(ArgumentError) }
63+
end
64+
65+
context "not-and" do
66+
let(:predicate){ Predicate.not(Predicate.eq(:x, 3) & Predicate.in(:y, [2,3])) }
67+
68+
it{ expect{ subject }.to raise_error(ArgumentError) }
69+
end
70+
71+
end
72+
end

0 commit comments

Comments
 (0)