2022-06-09 11:48:30 +02:00
|
|
|
describe Logic do
|
|
|
|
include Logic
|
|
|
|
|
|
|
|
it 'serializes deserializes' do
|
|
|
|
expect(Logic.from_h(constant(1).to_h)).to eq(constant(1))
|
|
|
|
expect(Logic.from_json(constant(1).to_json)).to eq(constant(1))
|
2022-06-09 11:54:29 +02:00
|
|
|
|
|
|
|
expect(Logic.from_h(empty.to_h)).to eq(empty)
|
2022-06-09 12:14:08 +02:00
|
|
|
|
2022-06-16 17:21:47 +02:00
|
|
|
expect(Logic.from_h(champ_value(1).to_h)).to eq(champ_value(1))
|
|
|
|
|
2022-06-09 12:14:08 +02:00
|
|
|
expect(Logic.from_h(greater_than(constant(1), constant(2)).to_h)).to eq(greater_than(constant(1), constant(2)))
|
2022-06-09 14:00:18 +02:00
|
|
|
|
|
|
|
expect(Logic.from_h(ds_and([constant(true), constant(true), constant(false)]).to_h))
|
|
|
|
.to eq(ds_and([constant(true), constant(true), constant(false)]))
|
2022-06-09 11:48:30 +02:00
|
|
|
end
|
2022-06-09 13:43:35 +02:00
|
|
|
|
|
|
|
describe '.compatible_type?' do
|
|
|
|
it { expect(Logic.compatible_type?(constant(true), constant(true))).to be true }
|
|
|
|
it { expect(Logic.compatible_type?(constant(1), constant(true))).to be false }
|
|
|
|
end
|
2022-06-09 14:00:18 +02:00
|
|
|
|
|
|
|
describe 'priority' do
|
|
|
|
# (false && true) || true = true
|
|
|
|
it { expect(ds_or([ds_and([constant(false), constant(true)]), constant(true)]).compute).to be true }
|
|
|
|
|
|
|
|
# false && (true || true) = false
|
|
|
|
it { expect(ds_and([constant(false), ds_or([constant(true), constant(true)])]).compute).to be false }
|
|
|
|
end
|
2022-06-09 11:48:30 +02:00
|
|
|
end
|