rcircuit/spec/port_spec.rb

50 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2018-07-08 17:19:58 -05:00
describe Port do
2018-07-09 14:56:30 -05:00
it "should set the port's value when we call #setval" do
2018-07-08 17:57:51 -05:00
a=Port.new(4)
2018-07-08 17:19:58 -05:00
a.setval(1)
expect(a).to eq 1
end
2018-07-08 17:57:51 -05:00
2018-07-09 14:56:30 -05:00
it "should propagate values when we call #setval" do
2018-07-08 17:57:51 -05:00
a=Port.new(4)
b=Port.new(4)
c=Port.new(4)
d=Port.new(4)
2018-07-08 17:19:58 -05:00
#connect A-B and C-D
a.connect(b)
c.connect(d)
a.setval(1)
c.setval(2)
expect(a).to eq 1
expect(b).to eq 1
expect(c).to eq 2
expect(d).to eq 2
#connect them all together
b.connect(c)
a.setval(3)
expect(a).to eq 3
expect(b).to eq 3
expect(c).to eq 3
expect(d).to eq 3
d.setval(4)
expect(a).to eq 4
expect(b).to eq 4
expect(c).to eq 4
expect(d).to eq 4
end
2018-07-08 17:57:51 -05:00
it "should not allow value to go over max allowed by width" do
a=Port.new(4)
expect {a.setval(16)}.to raise_error ArgumentError
end
2018-07-09 14:56:30 -05:00
it "should call registered callbacks" do
a=Port.new(4)
expect { |b| a.add_callback(&b); a.setval(10) }.to yield_with_args(10)
expect { |b| a.add_callback(&b); a.setval(8) }.to yield_with_args(8)
end
2018-07-08 17:19:58 -05:00
end