2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-06-09 12:14:08 +02:00
|
|
|
describe Logic::BinaryOperator do
|
2022-06-20 15:11:48 +02:00
|
|
|
include Logic
|
2022-06-09 14:00:18 +02:00
|
|
|
let(:two_greater_than_one) { greater_than(constant(2), constant(1)) }
|
2022-06-09 12:14:08 +02:00
|
|
|
|
|
|
|
describe '#type' do
|
|
|
|
it { expect(two_greater_than_one.type).to eq(:boolean) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#to_s' do
|
2022-09-26 21:21:55 +02:00
|
|
|
it { expect(two_greater_than_one.to_s([])).to eq('(2 > 1)') }
|
2022-06-09 12:14:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#==' do
|
|
|
|
it { expect(two_greater_than_one).to eq(greater_than(constant(2), constant(1))) }
|
|
|
|
it { expect(two_greater_than_one).not_to eq(greater_than(constant(1), constant(2))) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#errors' do
|
2022-09-14 10:43:18 +02:00
|
|
|
it { expect(greater_than(constant(1), constant(true)).errors).to eq([{ operator_name: "Logic::GreaterThan", type: :required_number }]) }
|
2022-06-09 12:14:08 +02:00
|
|
|
end
|
2023-01-04 11:10:10 +01:00
|
|
|
|
|
|
|
describe '#sources' do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:champ) { Champs::IntegerNumberChamp.new(value: nil, stable_id: 1) }
|
|
|
|
let(:champ2) { Champs::IntegerNumberChamp.new(value: nil, stable_id: 2) }
|
2023-01-04 11:10:10 +01:00
|
|
|
|
|
|
|
it { expect(two_greater_than_one.sources).to eq([]) }
|
|
|
|
it { expect(greater_than(champ_value(champ.stable_id), constant(2)).sources).to eq([champ.stable_id]) }
|
|
|
|
it { expect(greater_than(constant(2), champ_value(champ.stable_id)).sources).to eq([champ.stable_id]) }
|
|
|
|
it { expect(greater_than(champ_value(champ.stable_id), champ_value(champ2.stable_id)).sources).to eq([champ.stable_id, champ2.stable_id]) }
|
|
|
|
end
|
2022-06-09 12:14:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe Logic::GreaterThan do
|
2022-06-20 15:11:48 +02:00
|
|
|
include Logic
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :integer_number }]) }
|
|
|
|
let(:tdc) { procedure.active_revision.types_de_champ.first }
|
|
|
|
let(:dossier) { create(:dossier, procedure:) }
|
|
|
|
let(:champ) { Champs::IntegerNumberChamp.new(value: nil, stable_id: tdc.stable_id, dossier:) }
|
2022-07-18 16:19:28 +02:00
|
|
|
|
2022-06-09 12:14:08 +02:00
|
|
|
it 'computes' do
|
|
|
|
expect(greater_than(constant(1), constant(1)).compute).to be(false)
|
|
|
|
expect(greater_than(constant(2), constant(1)).compute).to be(true)
|
2022-07-18 16:19:28 +02:00
|
|
|
expect(greater_than(champ_value(champ.stable_id), constant(2)).compute([champ])).to be(false)
|
2022-06-09 12:14:08 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe Logic::GreaterThanEq do
|
2022-06-20 15:11:48 +02:00
|
|
|
include Logic
|
2022-06-09 12:14:08 +02:00
|
|
|
it 'computes' do
|
|
|
|
expect(greater_than_eq(constant(0), constant(1)).compute).to be(false)
|
|
|
|
expect(greater_than_eq(constant(1), constant(1)).compute).to be(true)
|
|
|
|
expect(greater_than_eq(constant(2), constant(1)).compute).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe Logic::LessThan do
|
2022-06-20 15:11:48 +02:00
|
|
|
include Logic
|
2022-06-09 12:14:08 +02:00
|
|
|
it 'computes' do
|
|
|
|
expect(less_than(constant(1), constant(1)).compute).to be(false)
|
|
|
|
expect(less_than(constant(1), constant(2)).compute).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe Logic::LessThanEq do
|
2022-06-20 15:11:48 +02:00
|
|
|
include Logic
|
2022-06-09 12:14:08 +02:00
|
|
|
it 'computes' do
|
|
|
|
expect(less_than_eq(constant(0), constant(1)).compute).to be(true)
|
|
|
|
expect(less_than_eq(constant(1), constant(1)).compute).to be(true)
|
|
|
|
expect(less_than_eq(constant(2), constant(1)).compute).to be(false)
|
|
|
|
end
|
|
|
|
end
|