Merge branch 'temp'

This commit is contained in:
pjht 2020-05-08 15:08:20 -05:00
commit 32a6c59cd8
6 changed files with 36 additions and 10 deletions

View File

@ -1,3 +1,4 @@
source "https://rubygems.org"
gem "yard"
gem "pry"
gem "rspec"

View File

@ -2,10 +2,24 @@ GEM
remote: https://rubygems.org/
specs:
coderay (1.1.2)
diff-lcs (1.3)
method_source (0.9.0)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.2)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.3)
yard (0.9.14)
PLATFORMS
@ -13,7 +27,8 @@ PLATFORMS
DEPENDENCIES
pry
rspec
yard
BUNDLED WITH
1.16.1
1.17.2

View File

@ -43,6 +43,7 @@ class Gate
# @param table [Array<Array<Integer>>] The truth table,
# which is an array of entries. The last value in the entry is the expected output,
# the rest are the inputs to the ports.
# @return [Boolean] Whether the truth table matches the gate's behavior
def self.test_table(table)
ports=[]
(table[0].length-1).times do

View File

@ -1,13 +1,6 @@
# Represents a NOT gate
class NotGate < Gate
# (see Gate#initialize)
def initialize(*args)
@outmask=0
super
@outmask=(2**@width)-1
end
# Add a port to the gate. As this is a NOT gate, there may only be one port.
# @param (see Gate#add_input)
# @return [void]
@ -22,6 +15,6 @@ class NotGate < Gate
# Calculates NOT of input and sets output port to that value.
# @param vals [Array<Integer>] List of values for connected ports.
def inputs_changed(vals)
out.setval((~vals[0]) & @outmask)
out.setval((~vals[0]) & ((2**@width)-1))
end
end

View File

@ -2,7 +2,8 @@
class VCD
# @!attribute [w] fd
# @api private
# @api private
# Used for testing to set the file to an RSpec double.
attr_writer :fd
# @param filename [String] The filename to output to
# @param timescale [String] The timescale

View File

@ -10,6 +10,21 @@ describe Gate do
end
end
end
it "makes sure that all ports have the same width on creation" do
a=Port.new(8)
b=Port.new(7)
expect{klass.new(a,b)}.to raise_error ArgumentError,"Incorrect width 7, expected 8"
end
it "makes sure that all ports have the same width on adding a port" do
a=Port.new(8)
b=Port.new(8)
gate=klass.new(a,b)
port=Port.new(7)
expect{gate.add_input(port)}.to raise_error ArgumentError,"Incorrect width 7, expected 8"
end
it "calls #inputs_changed when input values change or an input is added" do
a=Port.new(8)
b=Port.new(8)