Logic add_empty_condition_to
This commit is contained in:
parent
df7acf70c8
commit
c631c5cd82
2 changed files with 18 additions and 0 deletions
|
@ -60,6 +60,18 @@ module Logic
|
|||
end
|
||||
end
|
||||
|
||||
def self.add_empty_condition_to(condition)
|
||||
empty_condition = EmptyOperator.new(Empty.new, Empty.new)
|
||||
|
||||
if condition.nil?
|
||||
empty_condition
|
||||
elsif [And, Or].include?(condition.class)
|
||||
condition.tap { |c| c.operands << empty_condition }
|
||||
else
|
||||
Logic::And.new([condition, empty_condition])
|
||||
end
|
||||
end
|
||||
|
||||
def ds_eq(left, right) = Logic::Eq.new(left, right)
|
||||
|
||||
def greater_than(left, right) = Logic::GreaterThan.new(left, right)
|
||||
|
|
|
@ -79,4 +79,10 @@ describe Logic do
|
|||
# false && (true || true) = false
|
||||
it { expect(ds_and([constant(false), ds_or([constant(true), constant(true)])]).compute).to be false }
|
||||
end
|
||||
|
||||
describe '.add_empty_condition_to' do
|
||||
it { expect(Logic.add_empty_condition_to(nil)).to eq(empty_operator(empty, empty)) }
|
||||
it { expect(Logic.add_empty_condition_to(constant(true))).to eq(ds_and([constant(true), empty_operator(empty, empty)])) }
|
||||
it { expect(Logic.add_empty_condition_to(ds_or([constant(true)]))).to eq(ds_or([constant(true), empty_operator(empty, empty)])) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue