Gate tests in separate files

This commit is contained in:
pjht 2018-07-10 08:03:40 -05:00
parent 1760655308
commit 7476eed452
5 changed files with 51 additions and 54 deletions

13
spec/and_spec.rb Normal file
View File

@ -0,0 +1,13 @@
require_relative "../and.rb"
describe AndGate do
it "should AND together all inputs" do
table=[
[0,0,0],
[0,1,0],
[1,0,0],
[1,1,1],
]
ok=AndGate.test_table(table)
expect(ok).to eq true
end
end

View File

@ -1,9 +1,6 @@
require_relative "../port.rb" require_relative "../port.rb"
require_relative "../gate.rb" require_relative "../gate.rb"
require_relative "../not.rb"
require_relative "../and.rb"
require_relative "../or.rb"
require_relative "../xor.rb"
describe Gate do describe Gate do
let(:klass) do let(:klass) do
Class.new(Gate) do Class.new(Gate) do
@ -34,54 +31,4 @@ describe Gate do
b.setval(10) b.setval(10)
expect(gate.out.val).to eq(18) expect(gate.out.val).to eq(18)
end end
context "NotGate" do
it "should NOT the input" do
table=[
[0,1],
[1,0]
]
ok=NotGate.test_table(table)
expect(ok).to eq true
end
end
context "AndGate" do
it "should AND together all inputs" do
table=[
[0,0,0],
[0,1,0],
[1,0,0],
[1,1,1],
]
ok=AndGate.test_table(table)
expect(ok).to eq true
end
end
context "OrGate" do
it "should OR together all inputs" do
table=[
[0,0,0],
[0,1,1],
[1,0,1],
[1,1,1],
]
ok=OrGate.test_table(table)
expect(ok).to eq true
end
end
context "XorGate" do
it "should XOR together all inputs" do
table=[
[0,0,0],
[0,1,1],
[1,0,1],
[1,1,0],
]
ok=XorGate.test_table(table)
expect(ok).to eq true
end
end
end end

11
spec/not_spec.rb Normal file
View File

@ -0,0 +1,11 @@
require_relative "../not.rb"
describe NotGate do
it "should NOT the input" do
table=[
[0,1],
[1,0]
]
ok=NotGate.test_table(table)
expect(ok).to eq true
end
end

13
spec/or_spec.rb Normal file
View File

@ -0,0 +1,13 @@
require_relative "../or.rb"
describe OrGate do
it "should OR together all inputs" do
table=[
[0,0,0],
[0,1,1],
[1,0,1],
[1,1,1],
]
ok=OrGate.test_table(table)
expect(ok).to eq true
end
end

13
spec/xor_spec.rb Normal file
View File

@ -0,0 +1,13 @@
require_relative "../xor.rb"
describe XorGate do
it "should XOR together all inputs" do
table=[
[0,0,0],
[0,1,1],
[1,0,1],
[1,1,0],
]
ok=XorGate.test_table(table)
expect(ok).to eq true
end
end