rcircuit/spec/gate_spec.rb

32 lines
693 B
Ruby
Raw Normal View History

2018-07-09 14:56:30 -05:00
describe Gate do
let(:klass) do
Class.new(Gate) do
def inputs_changed(vals)
tot=0
vals.each do |val|
tot+=val
end
out.setval(tot)
end
end
end
it "calls #inputs_changed when input values change or an input is added" do
a=Port.new(8)
b=Port.new(8)
gate=klass.new(a,b)
expect(gate).to receive(:inputs_changed).with([8,0])
a.setval(8)
expect(gate).to receive(:inputs_changed).with([8,10])
b.setval(10)
end
it "can perform computations in #inputs_changed" do
a=Port.new(8)
b=Port.new(8)
gate=klass.new(a,b)
a.setval(8)
b.setval(10)
expect(gate.out.val).to eq(18)
end
end