fix: binary operator computes false by default

This commit is contained in:
simon lehericey 2022-07-18 16:19:28 +02:00
parent 27ed32bff0
commit 2d26ba3507
2 changed files with 4 additions and 1 deletions

View file

@ -33,7 +33,7 @@ class Logic::BinaryOperator < Logic::Term
l = @left.compute(champs) l = @left.compute(champs)
r = @right.compute(champs) r = @right.compute(champs)
l.send(operation, r) l&.send(operation, r) || false
end end
def to_s = "(#{@left} #{operation} #{@right})" def to_s = "(#{@left} #{operation} #{@right})"

View file

@ -22,9 +22,12 @@ end
describe Logic::GreaterThan do describe Logic::GreaterThan do
include Logic include Logic
let(:champ) { create(:champ_integer_number, value: nil) }
it 'computes' do it 'computes' do
expect(greater_than(constant(1), constant(1)).compute).to be(false) expect(greater_than(constant(1), constant(1)).compute).to be(false)
expect(greater_than(constant(2), constant(1)).compute).to be(true) expect(greater_than(constant(2), constant(1)).compute).to be(true)
expect(greater_than(champ_value(champ.stable_id), constant(2)).compute([champ])).to be(false)
end end
end end