circuits 0.2.6 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/.rspec +1 -0
- data/README.md +2 -1
- data/Rakefile +17 -0
- data/circuits.gemspec +3 -0
- data/lib/circuits/component/xnor.rb +1 -1
- data/lib/circuits/component/xor.rb +1 -1
- data/lib/circuits/component.rb +17 -3
- data/lib/circuits/version.rb +1 -1
- data/spec/unit/circuits/component/and_spec.rb +48 -0
- data/spec/unit/circuits/component/nand_spec.rb +47 -0
- data/spec/unit/circuits/component/nor_spec.rb +47 -0
- data/spec/unit/circuits/component/or_spec.rb +47 -0
- data/spec/unit/circuits/component/xnor_spec.rb +116 -0
- data/spec/unit/circuits/component/xor_spec.rb +116 -0
- data/spec/unit/circuits/component_spec.rb +53 -3
- metadata +44 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,15 +1,15 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            !binary "U0hBMQ==":
         | 
| 3 3 | 
             
              metadata.gz: !binary |-
         | 
| 4 | 
            -
                 | 
| 4 | 
            +
                NzMwZGNkMDQ1ZmY2ZTVlMjhjZjA1ODUyZTFmNDc1OTMyZTA2YmM1Mw==
         | 
| 5 5 | 
             
              data.tar.gz: !binary |-
         | 
| 6 | 
            -
                 | 
| 6 | 
            +
                M2ZjMmNmYzM5OGExZjAxMWU0MjI3NzRlZTYyY2QzYWVjNjI1MDc0Zg==
         | 
| 7 7 | 
             
            SHA512:
         | 
| 8 8 | 
             
              metadata.gz: !binary |-
         | 
| 9 | 
            -
                 | 
| 10 | 
            -
                 | 
| 11 | 
            -
                 | 
| 9 | 
            +
                YWJkYmY2NTE1YWYzMWU0OTk2NjIzZDNkYTY1MTE3NDEzOTkzZDg5MThlMzZh
         | 
| 10 | 
            +
                YjhiNmE5NjRmYTRhZDNmNTE4Yjc0ZDllZTY3OGIxM2Q4MjMyZmM1YWU3ZjM1
         | 
| 11 | 
            +
                N2FlNTg1YWNlNWQ5NTFjZjEwOTlhOTdjNzRmZWFkYWIwZWZlZDU=
         | 
| 12 12 | 
             
              data.tar.gz: !binary |-
         | 
| 13 | 
            -
                 | 
| 14 | 
            -
                 | 
| 15 | 
            -
                 | 
| 13 | 
            +
                OWNmNzVkMTQyMWQ3MWJjNDFlNjJkZGZmYjZjYzQ1OGU5NGY5Y2JjNGM2ODA4
         | 
| 14 | 
            +
                MTRjOWM5NjI3MWQ3OWJmZWRmZTBkMGUxZjI0YjRmZDg1NGE2M2I4YTE3ZjZh
         | 
| 15 | 
            +
                YjdlYTRkMDI2OGNhMmVkZWEzOTc1NzU2NTJlZDUxNjBlODc1MGY=
         | 
    
        data/.rspec
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -2,6 +2,7 @@ | |
| 2 2 | 
             
            [](https://badge.fury.io/rb/circuits)
         | 
| 3 3 | 
             
            [](https://coveralls.io/github/meringu/circuits?branch=master)
         | 
| 4 4 | 
             
            [](https://codeclimate.com/github/meringu/circuits)
         | 
| 5 | 
            +
            [](https://gemnasium.com/meringu/circuits)
         | 
| 5 6 | 
             
            [](http://inch-ci.org/github/meringu/circuits)
         | 
| 6 7 |  | 
| 7 8 | 
             
            # Circuits
         | 
| @@ -50,7 +51,7 @@ and_gate.outputs[0].get # false | |
| 50 51 |  | 
| 51 52 | 
             
            ```ruby
         | 
| 52 53 | 
             
            and_gate = Circuits::Component::And.new
         | 
| 53 | 
            -
            not_gate = Circuits::Component:: | 
| 54 | 
            +
            not_gate = Circuits::Component::Not.new(inputs: [and_gate.outputs[0]])
         | 
| 54 55 | 
             
            ```
         | 
| 55 56 |  | 
| 56 57 | 
             
            ## Contributing
         | 
    
        data/Rakefile
    CHANGED
    
    | @@ -1,6 +1,23 @@ | |
| 1 1 | 
             
            require 'bundler/gem_tasks'
         | 
| 2 2 | 
             
            require 'rspec/core/rake_task'
         | 
| 3 | 
            +
            require 'rubocop/rake_task'
         | 
| 4 | 
            +
            require 'reek/rake/task'
         | 
| 5 | 
            +
            require 'yard'
         | 
| 3 6 |  | 
| 4 7 | 
             
            RSpec::Core::RakeTask.new(:spec)
         | 
| 5 8 |  | 
| 6 9 | 
             
            task default: :spec
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            RuboCop::RakeTask.new(:rubocop) do |task|
         | 
| 12 | 
            +
              task.patterns = ['lib/**/*.rb']
         | 
| 13 | 
            +
              # only show the files with failures
         | 
| 14 | 
            +
              task.formatters = ['files']
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            Reek::Rake::Task.new
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            task lint: [:rubocop, :reek]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            YARD::Rake::YardocTask.new(:yard) do |t|
         | 
| 22 | 
            +
              t.stats_options = ['--list-undoc']
         | 
| 23 | 
            +
            end
         | 
    
        data/circuits.gemspec
    CHANGED
    
    | @@ -21,4 +21,7 @@ Gem::Specification.new do |spec| | |
| 21 21 | 
             
              spec.add_development_dependency 'coveralls'
         | 
| 22 22 | 
             
              spec.add_development_dependency 'rake', '~> 10.0'
         | 
| 23 23 | 
             
              spec.add_development_dependency 'rspec', '~> 3.3'
         | 
| 24 | 
            +
              spec.add_development_dependency 'rubocop', '~> 0.34'
         | 
| 25 | 
            +
              spec.add_development_dependency 'reek', '~> 3.5'
         | 
| 26 | 
            +
              spec.add_development_dependency 'yard', '~> 0.8.7'
         | 
| 24 27 | 
             
            end
         | 
    
        data/lib/circuits/component.rb
    CHANGED
    
    | @@ -8,10 +8,13 @@ module Circuits | |
| 8 8 | 
             
              module Component
         | 
| 9 9 | 
             
                # Creates the Component with inputs and outputs
         | 
| 10 10 | 
             
                # @param opts [Hash] options to create the Component with
         | 
| 11 | 
            -
                # @option opts [Array<Input | 
| 11 | 
            +
                # @option opts [Array<Input>, FixNum] :inputs The array of inputs to use, or
         | 
| 12 | 
            +
                #   the number of inputs to create
         | 
| 12 13 | 
             
                def initialize(opts = {})
         | 
| 13 | 
            -
                  @inputs = opts[:inputs]  | 
| 14 | 
            -
             | 
| 14 | 
            +
                  @inputs = opts[:inputs] if opts[:inputs].is_a? Array
         | 
| 15 | 
            +
                  @inputs = create_inputs opts[:inputs] if opts[:inputs].is_a? Integer
         | 
| 16 | 
            +
                  @inputs = create_inputs input_count if opts[:inputs].nil?
         | 
| 17 | 
            +
             | 
| 15 18 | 
             
                  @outputs = output_count.times.collect { Circuits::Terminal::Output.new }
         | 
| 16 19 | 
             
                  setup
         | 
| 17 20 | 
             
                end
         | 
| @@ -41,6 +44,17 @@ module Circuits | |
| 41 44 | 
             
                def output_count
         | 
| 42 45 | 
             
                  fail NotImplementedError
         | 
| 43 46 | 
             
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                # Creates an array of N inputs, where N is equal to or greater than the
         | 
| 49 | 
            +
                #   default number of inputs for this component
         | 
| 50 | 
            +
                # @param n [FixNum] The number of inputs to create
         | 
| 51 | 
            +
                # @return [Array<Input>] An array of inputs
         | 
| 52 | 
            +
                def create_inputs(n)
         | 
| 53 | 
            +
                  if n < input_count
         | 
| 54 | 
            +
                    fail ArgumentError, "Invalid number of inputs, #{self.class} requires at least #{input_count} inputs"
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
                  n.times.collect { Circuits::Terminal::Input.new }
         | 
| 57 | 
            +
                end
         | 
| 44 58 |  | 
| 45 59 | 
             
                def setup
         | 
| 46 60 | 
             
                end
         | 
    
        data/lib/circuits/version.rb
    CHANGED
    
    
| @@ -55,5 +55,53 @@ describe Circuits::Component::And do | |
| 55 55 | 
             
                    end
         | 
| 56 56 | 
             
                  end
         | 
| 57 57 | 
             
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                [3, 4, 8].each do |n|
         | 
| 60 | 
            +
                  context "with #{n} inputs" do
         | 
| 61 | 
            +
                    subject { Circuits::Component::And.new inputs: n }
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                    before do
         | 
| 64 | 
            +
                      n.times { |x| subject.inputs[x].set inputs[x] }
         | 
| 65 | 
            +
                    end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                    context 'when all inputs are true' do
         | 
| 68 | 
            +
                      let(:inputs) { n.times.collect { true } }
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                      it '= true' do
         | 
| 71 | 
            +
                        subject.tick
         | 
| 72 | 
            +
                        subject.tock
         | 
| 73 | 
            +
                        expect(subject.outputs[0].get).to eq(true)
         | 
| 74 | 
            +
                      end
         | 
| 75 | 
            +
                    end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                    context 'when all inputs are false' do
         | 
| 78 | 
            +
                      let(:inputs) { n.times.collect { false } }
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                      it '= false' do
         | 
| 81 | 
            +
                        subject.tick
         | 
| 82 | 
            +
                        subject.tock
         | 
| 83 | 
            +
                        expect(subject.outputs[0].get).to eq(false)
         | 
| 84 | 
            +
                      end
         | 
| 85 | 
            +
                    end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                    context 'when any input is false' do
         | 
| 88 | 
            +
                      n.times do |x|
         | 
| 89 | 
            +
                        context "when input #{x} is false" do
         | 
| 90 | 
            +
                          let(:inputs) do
         | 
| 91 | 
            +
                            inputs =  n.times.collect { true }
         | 
| 92 | 
            +
                            inputs[x] = false
         | 
| 93 | 
            +
                            inputs
         | 
| 94 | 
            +
                          end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                          it '= false' do
         | 
| 97 | 
            +
                            subject.tick
         | 
| 98 | 
            +
                            subject.tock
         | 
| 99 | 
            +
                            expect(subject.outputs[0].get).to eq(false)
         | 
| 100 | 
            +
                          end
         | 
| 101 | 
            +
                        end
         | 
| 102 | 
            +
                      end
         | 
| 103 | 
            +
                    end
         | 
| 104 | 
            +
                  end
         | 
| 105 | 
            +
                end
         | 
| 58 106 | 
             
              end
         | 
| 59 107 | 
             
            end
         | 
| @@ -55,5 +55,52 @@ describe Circuits::Component::Nand do | |
| 55 55 | 
             
                    end
         | 
| 56 56 | 
             
                  end
         | 
| 57 57 | 
             
                end
         | 
| 58 | 
            +
                [3, 4, 8].each do |n|
         | 
| 59 | 
            +
                  context "with #{n} inputs" do
         | 
| 60 | 
            +
                    subject { Circuits::Component::Nand.new inputs: n }
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    before do
         | 
| 63 | 
            +
                      n.times { |x| subject.inputs[x].set inputs[x] }
         | 
| 64 | 
            +
                    end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                    context 'when all inputs are true' do
         | 
| 67 | 
            +
                      let(:inputs) { n.times.collect { true } }
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                      it '= false' do
         | 
| 70 | 
            +
                        subject.tick
         | 
| 71 | 
            +
                        subject.tock
         | 
| 72 | 
            +
                        expect(subject.outputs[0].get).to eq(false)
         | 
| 73 | 
            +
                      end
         | 
| 74 | 
            +
                    end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                    context 'when all inputs are false' do
         | 
| 77 | 
            +
                      let(:inputs) { n.times.collect { false } }
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                      it '= true' do
         | 
| 80 | 
            +
                        subject.tick
         | 
| 81 | 
            +
                        subject.tock
         | 
| 82 | 
            +
                        expect(subject.outputs[0].get).to eq(true)
         | 
| 83 | 
            +
                      end
         | 
| 84 | 
            +
                    end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                    context 'when any input is false' do
         | 
| 87 | 
            +
                      n.times do |x|
         | 
| 88 | 
            +
                        context "when input #{x} is false" do
         | 
| 89 | 
            +
                          let(:inputs) do
         | 
| 90 | 
            +
                            inputs =  n.times.collect { true }
         | 
| 91 | 
            +
                            inputs[x] = false
         | 
| 92 | 
            +
                            inputs
         | 
| 93 | 
            +
                          end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                          it '= true' do
         | 
| 96 | 
            +
                            subject.tick
         | 
| 97 | 
            +
                            subject.tock
         | 
| 98 | 
            +
                            expect(subject.outputs[0].get).to eq(true)
         | 
| 99 | 
            +
                          end
         | 
| 100 | 
            +
                        end
         | 
| 101 | 
            +
                      end
         | 
| 102 | 
            +
                    end
         | 
| 103 | 
            +
                  end
         | 
| 104 | 
            +
                end
         | 
| 58 105 | 
             
              end
         | 
| 59 106 | 
             
            end
         | 
| @@ -55,5 +55,52 @@ describe Circuits::Component::Nor do | |
| 55 55 | 
             
                    end
         | 
| 56 56 | 
             
                  end
         | 
| 57 57 | 
             
                end
         | 
| 58 | 
            +
                [3, 4, 8].each do |n|
         | 
| 59 | 
            +
                  context "with #{n} inputs" do
         | 
| 60 | 
            +
                    subject { Circuits::Component::Nor.new inputs: n }
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    before do
         | 
| 63 | 
            +
                      n.times { |x| subject.inputs[x].set inputs[x] }
         | 
| 64 | 
            +
                    end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                    context 'when all inputs are true' do
         | 
| 67 | 
            +
                      let(:inputs) { n.times.collect { true } }
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                      it '= false' do
         | 
| 70 | 
            +
                        subject.tick
         | 
| 71 | 
            +
                        subject.tock
         | 
| 72 | 
            +
                        expect(subject.outputs[0].get).to eq(false)
         | 
| 73 | 
            +
                      end
         | 
| 74 | 
            +
                    end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                    context 'when all inputs are false' do
         | 
| 77 | 
            +
                      let(:inputs) { n.times.collect { false } }
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                      it '= true' do
         | 
| 80 | 
            +
                        subject.tick
         | 
| 81 | 
            +
                        subject.tock
         | 
| 82 | 
            +
                        expect(subject.outputs[0].get).to eq(true)
         | 
| 83 | 
            +
                      end
         | 
| 84 | 
            +
                    end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                    context 'when any input is false' do
         | 
| 87 | 
            +
                      n.times do |x|
         | 
| 88 | 
            +
                        context "when input #{x} is false" do
         | 
| 89 | 
            +
                          let(:inputs) do
         | 
| 90 | 
            +
                            inputs =  n.times.collect { true }
         | 
| 91 | 
            +
                            inputs[x] = false
         | 
| 92 | 
            +
                            inputs
         | 
| 93 | 
            +
                          end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                          it '= false' do
         | 
| 96 | 
            +
                            subject.tick
         | 
| 97 | 
            +
                            subject.tock
         | 
| 98 | 
            +
                            expect(subject.outputs[0].get).to eq(false)
         | 
| 99 | 
            +
                          end
         | 
| 100 | 
            +
                        end
         | 
| 101 | 
            +
                      end
         | 
| 102 | 
            +
                    end
         | 
| 103 | 
            +
                  end
         | 
| 104 | 
            +
                end
         | 
| 58 105 | 
             
              end
         | 
| 59 106 | 
             
            end
         | 
| @@ -55,5 +55,52 @@ describe Circuits::Component::Or do | |
| 55 55 | 
             
                    end
         | 
| 56 56 | 
             
                  end
         | 
| 57 57 | 
             
                end
         | 
| 58 | 
            +
                [3, 4, 8].each do |n|
         | 
| 59 | 
            +
                  context "with #{n} inputs" do
         | 
| 60 | 
            +
                    subject { Circuits::Component::Or.new inputs: n }
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    before do
         | 
| 63 | 
            +
                      n.times { |x| subject.inputs[x].set inputs[x] }
         | 
| 64 | 
            +
                    end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                    context 'when all inputs are true' do
         | 
| 67 | 
            +
                      let(:inputs) { n.times.collect { true } }
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                      it '= true' do
         | 
| 70 | 
            +
                        subject.tick
         | 
| 71 | 
            +
                        subject.tock
         | 
| 72 | 
            +
                        expect(subject.outputs[0].get).to eq(true)
         | 
| 73 | 
            +
                      end
         | 
| 74 | 
            +
                    end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                    context 'when all inputs are false' do
         | 
| 77 | 
            +
                      let(:inputs) { n.times.collect { false } }
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                      it '= false' do
         | 
| 80 | 
            +
                        subject.tick
         | 
| 81 | 
            +
                        subject.tock
         | 
| 82 | 
            +
                        expect(subject.outputs[0].get).to eq(false)
         | 
| 83 | 
            +
                      end
         | 
| 84 | 
            +
                    end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                    context 'when any input is false' do
         | 
| 87 | 
            +
                      n.times do |x|
         | 
| 88 | 
            +
                        context "when input #{x} is false" do
         | 
| 89 | 
            +
                          let(:inputs) do
         | 
| 90 | 
            +
                            inputs =  n.times.collect { true }
         | 
| 91 | 
            +
                            inputs[x] = false
         | 
| 92 | 
            +
                            inputs
         | 
| 93 | 
            +
                          end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                          it '= true' do
         | 
| 96 | 
            +
                            subject.tick
         | 
| 97 | 
            +
                            subject.tock
         | 
| 98 | 
            +
                            expect(subject.outputs[0].get).to eq(true)
         | 
| 99 | 
            +
                          end
         | 
| 100 | 
            +
                        end
         | 
| 101 | 
            +
                      end
         | 
| 102 | 
            +
                    end
         | 
| 103 | 
            +
                  end
         | 
| 104 | 
            +
                end
         | 
| 58 105 | 
             
              end
         | 
| 59 106 | 
             
            end
         | 
| @@ -55,5 +55,121 @@ describe Circuits::Component::Xnor do | |
| 55 55 | 
             
                    end
         | 
| 56 56 | 
             
                  end
         | 
| 57 57 | 
             
                end
         | 
| 58 | 
            +
                context 'when the number of inputs is even' do
         | 
| 59 | 
            +
                  [2, 4, 8].each do |n|
         | 
| 60 | 
            +
                    context "with #{n} inputs" do
         | 
| 61 | 
            +
                      subject { Circuits::Component::Xnor.new inputs: n }
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                      before do
         | 
| 64 | 
            +
                        n.times { |x| subject.inputs[x].set inputs[x] }
         | 
| 65 | 
            +
                      end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                      context 'when all inputs are true' do
         | 
| 68 | 
            +
                        let(:inputs) { n.times.collect { true } }
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                        it '= true' do
         | 
| 71 | 
            +
                          subject.tick
         | 
| 72 | 
            +
                          subject.tock
         | 
| 73 | 
            +
                          expect(subject.outputs[0].get).to eq(true)
         | 
| 74 | 
            +
                        end
         | 
| 75 | 
            +
                      end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                      context 'when all inputs are false' do
         | 
| 78 | 
            +
                        let(:inputs) { n.times.collect { false } }
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                        it '= true' do
         | 
| 81 | 
            +
                          subject.tick
         | 
| 82 | 
            +
                          subject.tock
         | 
| 83 | 
            +
                          expect(subject.outputs[0].get).to eq(true)
         | 
| 84 | 
            +
                        end
         | 
| 85 | 
            +
                      end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                      context 'when any input is false' do
         | 
| 88 | 
            +
                        n.times do |x|
         | 
| 89 | 
            +
                          context "when input #{x} is false" do
         | 
| 90 | 
            +
                            let(:inputs) do
         | 
| 91 | 
            +
                              inputs =  n.times.collect { true }
         | 
| 92 | 
            +
                              inputs[x] = false
         | 
| 93 | 
            +
                              inputs
         | 
| 94 | 
            +
                            end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                            it '= false' do
         | 
| 97 | 
            +
                              subject.tick
         | 
| 98 | 
            +
                              subject.tock
         | 
| 99 | 
            +
                              expect(subject.outputs[0].get).to eq(false)
         | 
| 100 | 
            +
                            end
         | 
| 101 | 
            +
                          end
         | 
| 102 | 
            +
                        end
         | 
| 103 | 
            +
                      end
         | 
| 104 | 
            +
                    end
         | 
| 105 | 
            +
                  end
         | 
| 106 | 
            +
                end
         | 
| 107 | 
            +
                context 'when the number of inputs is odd' do
         | 
| 108 | 
            +
                  [3, 5, 7].each do |n|
         | 
| 109 | 
            +
                    context "with #{n} inputs" do
         | 
| 110 | 
            +
                      subject { Circuits::Component::Xnor.new inputs: n }
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                      before do
         | 
| 113 | 
            +
                        n.times { |x| subject.inputs[x].set inputs[x] }
         | 
| 114 | 
            +
                      end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                      context 'when all inputs are true' do
         | 
| 117 | 
            +
                        let(:inputs) { n.times.collect { true } }
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                        it '= false' do
         | 
| 120 | 
            +
                          subject.tick
         | 
| 121 | 
            +
                          subject.tock
         | 
| 122 | 
            +
                          expect(subject.outputs[0].get).to eq(false)
         | 
| 123 | 
            +
                        end
         | 
| 124 | 
            +
                      end
         | 
| 125 | 
            +
             | 
| 126 | 
            +
                      context 'when all inputs are false' do
         | 
| 127 | 
            +
                        let(:inputs) { n.times.collect { false } }
         | 
| 128 | 
            +
             | 
| 129 | 
            +
                        it '= true' do
         | 
| 130 | 
            +
                          subject.tick
         | 
| 131 | 
            +
                          subject.tock
         | 
| 132 | 
            +
                          expect(subject.outputs[0].get).to eq(true)
         | 
| 133 | 
            +
                        end
         | 
| 134 | 
            +
                      end
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                      context 'when any input is false' do
         | 
| 137 | 
            +
                        n.times do |x|
         | 
| 138 | 
            +
                          context "when input #{x} is false" do
         | 
| 139 | 
            +
                            let(:inputs) do
         | 
| 140 | 
            +
                              inputs =  n.times.collect { true }
         | 
| 141 | 
            +
                              inputs[x] = false
         | 
| 142 | 
            +
                              inputs
         | 
| 143 | 
            +
                            end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                            it '= true' do
         | 
| 146 | 
            +
                              subject.tick
         | 
| 147 | 
            +
                              subject.tock
         | 
| 148 | 
            +
                              expect(subject.outputs[0].get).to eq(true)
         | 
| 149 | 
            +
                            end
         | 
| 150 | 
            +
                          end
         | 
| 151 | 
            +
                        end
         | 
| 152 | 
            +
                      end
         | 
| 153 | 
            +
             | 
| 154 | 
            +
                      context 'when any input is true' do
         | 
| 155 | 
            +
                        n.times do |x|
         | 
| 156 | 
            +
                          context "when input #{x} is true" do
         | 
| 157 | 
            +
                            let(:inputs) do
         | 
| 158 | 
            +
                              inputs =  n.times.collect { false }
         | 
| 159 | 
            +
                              inputs[x] = true
         | 
| 160 | 
            +
                              inputs
         | 
| 161 | 
            +
                            end
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                            it '= false' do
         | 
| 164 | 
            +
                              subject.tick
         | 
| 165 | 
            +
                              subject.tock
         | 
| 166 | 
            +
                              expect(subject.outputs[0].get).to eq(false)
         | 
| 167 | 
            +
                            end
         | 
| 168 | 
            +
                          end
         | 
| 169 | 
            +
                        end
         | 
| 170 | 
            +
                      end
         | 
| 171 | 
            +
                    end
         | 
| 172 | 
            +
                  end
         | 
| 173 | 
            +
                end
         | 
| 58 174 | 
             
              end
         | 
| 59 175 | 
             
            end
         | 
| @@ -55,5 +55,121 @@ describe Circuits::Component::Xor do | |
| 55 55 | 
             
                    end
         | 
| 56 56 | 
             
                  end
         | 
| 57 57 | 
             
                end
         | 
| 58 | 
            +
                context 'when the number of inputs is even' do
         | 
| 59 | 
            +
                  [2, 4, 8].each do |n|
         | 
| 60 | 
            +
                    context "with #{n} inputs" do
         | 
| 61 | 
            +
                      subject { Circuits::Component::Xor.new inputs: n }
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                      before do
         | 
| 64 | 
            +
                        n.times { |x| subject.inputs[x].set inputs[x] }
         | 
| 65 | 
            +
                      end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                      context 'when all inputs are true' do
         | 
| 68 | 
            +
                        let(:inputs) { n.times.collect { true } }
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                        it '= false' do
         | 
| 71 | 
            +
                          subject.tick
         | 
| 72 | 
            +
                          subject.tock
         | 
| 73 | 
            +
                          expect(subject.outputs[0].get).to eq(false)
         | 
| 74 | 
            +
                        end
         | 
| 75 | 
            +
                      end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                      context 'when all inputs are false' do
         | 
| 78 | 
            +
                        let(:inputs) { n.times.collect { false } }
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                        it '= false' do
         | 
| 81 | 
            +
                          subject.tick
         | 
| 82 | 
            +
                          subject.tock
         | 
| 83 | 
            +
                          expect(subject.outputs[0].get).to eq(false)
         | 
| 84 | 
            +
                        end
         | 
| 85 | 
            +
                      end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                      context 'when any input is false' do
         | 
| 88 | 
            +
                        n.times do |x|
         | 
| 89 | 
            +
                          context "when input #{x} is false" do
         | 
| 90 | 
            +
                            let(:inputs) do
         | 
| 91 | 
            +
                              inputs =  n.times.collect { true }
         | 
| 92 | 
            +
                              inputs[x] = false
         | 
| 93 | 
            +
                              inputs
         | 
| 94 | 
            +
                            end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                            it '= true' do
         | 
| 97 | 
            +
                              subject.tick
         | 
| 98 | 
            +
                              subject.tock
         | 
| 99 | 
            +
                              expect(subject.outputs[0].get).to eq(true)
         | 
| 100 | 
            +
                            end
         | 
| 101 | 
            +
                          end
         | 
| 102 | 
            +
                        end
         | 
| 103 | 
            +
                      end
         | 
| 104 | 
            +
                    end
         | 
| 105 | 
            +
                  end
         | 
| 106 | 
            +
                end
         | 
| 107 | 
            +
                context 'when the number of inputs is odd' do
         | 
| 108 | 
            +
                  [3, 5, 7].each do |n|
         | 
| 109 | 
            +
                    context "with #{n} inputs" do
         | 
| 110 | 
            +
                      subject { Circuits::Component::Xor.new inputs: n }
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                      before do
         | 
| 113 | 
            +
                        n.times { |x| subject.inputs[x].set inputs[x] }
         | 
| 114 | 
            +
                      end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                      context 'when all inputs are true' do
         | 
| 117 | 
            +
                        let(:inputs) { n.times.collect { true } }
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                        it '= true' do
         | 
| 120 | 
            +
                          subject.tick
         | 
| 121 | 
            +
                          subject.tock
         | 
| 122 | 
            +
                          expect(subject.outputs[0].get).to eq(true)
         | 
| 123 | 
            +
                        end
         | 
| 124 | 
            +
                      end
         | 
| 125 | 
            +
             | 
| 126 | 
            +
                      context 'when all inputs are false' do
         | 
| 127 | 
            +
                        let(:inputs) { n.times.collect { false } }
         | 
| 128 | 
            +
             | 
| 129 | 
            +
                        it '= false' do
         | 
| 130 | 
            +
                          subject.tick
         | 
| 131 | 
            +
                          subject.tock
         | 
| 132 | 
            +
                          expect(subject.outputs[0].get).to eq(false)
         | 
| 133 | 
            +
                        end
         | 
| 134 | 
            +
                      end
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                      context 'when any input is false' do
         | 
| 137 | 
            +
                        n.times do |x|
         | 
| 138 | 
            +
                          context "when input #{x} is false" do
         | 
| 139 | 
            +
                            let(:inputs) do
         | 
| 140 | 
            +
                              inputs =  n.times.collect { true }
         | 
| 141 | 
            +
                              inputs[x] = false
         | 
| 142 | 
            +
                              inputs
         | 
| 143 | 
            +
                            end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                            it '= false' do
         | 
| 146 | 
            +
                              subject.tick
         | 
| 147 | 
            +
                              subject.tock
         | 
| 148 | 
            +
                              expect(subject.outputs[0].get).to eq(false)
         | 
| 149 | 
            +
                            end
         | 
| 150 | 
            +
                          end
         | 
| 151 | 
            +
                        end
         | 
| 152 | 
            +
                      end
         | 
| 153 | 
            +
             | 
| 154 | 
            +
                      context 'when any input is true' do
         | 
| 155 | 
            +
                        n.times do |x|
         | 
| 156 | 
            +
                          context "when input #{x} is true" do
         | 
| 157 | 
            +
                            let(:inputs) do
         | 
| 158 | 
            +
                              inputs =  n.times.collect { false }
         | 
| 159 | 
            +
                              inputs[x] = true
         | 
| 160 | 
            +
                              inputs
         | 
| 161 | 
            +
                            end
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                            it '= true' do
         | 
| 164 | 
            +
                              subject.tick
         | 
| 165 | 
            +
                              subject.tock
         | 
| 166 | 
            +
                              expect(subject.outputs[0].get).to eq(true)
         | 
| 167 | 
            +
                            end
         | 
| 168 | 
            +
                          end
         | 
| 169 | 
            +
                        end
         | 
| 170 | 
            +
                      end
         | 
| 171 | 
            +
                    end
         | 
| 172 | 
            +
                  end
         | 
| 173 | 
            +
                end
         | 
| 58 174 | 
             
              end
         | 
| 59 175 | 
             
            end
         | 
| @@ -8,17 +8,67 @@ class MockComponent | |
| 8 8 | 
             
              def initialize(opts = {})
         | 
| 9 9 | 
             
                @outputs = opts[:outputs]
         | 
| 10 10 | 
             
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def mock_input_count
         | 
| 13 | 
            +
                input_count
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              def mock_output_count
         | 
| 17 | 
            +
                output_count
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              def mock_create_inputs(n)
         | 
| 21 | 
            +
                create_inputs(n)
         | 
| 22 | 
            +
              end
         | 
| 11 23 | 
             
            end
         | 
| 12 24 |  | 
| 13 25 | 
             
            describe Circuits::Component do
         | 
| 14 | 
            -
               | 
| 15 | 
            -
             | 
| 26 | 
            +
              let(:outputs) { [double('output')] }
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              subject { MockComponent.new(outputs: outputs) }
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              describe '#input_count' do
         | 
| 31 | 
            +
                it 'is not implemented' do
         | 
| 32 | 
            +
                  expect { subject.mock_input_count }.to raise_error(NotImplementedError)
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              describe '#output_count' do
         | 
| 37 | 
            +
                it 'is not implemented' do
         | 
| 38 | 
            +
                  expect { subject.mock_output_count }.to raise_error(NotImplementedError)
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
              end
         | 
| 16 41 |  | 
| 17 | 
            -
             | 
| 42 | 
            +
              describe '#tick' do
         | 
| 43 | 
            +
                it 'is not implemented' do
         | 
| 44 | 
            +
                  expect { subject.tick }.to raise_error(NotImplementedError)
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
              end
         | 
| 18 47 |  | 
| 48 | 
            +
              describe '#tock' do
         | 
| 19 49 | 
             
                it 'tocks the outputs' do
         | 
| 20 50 | 
             
                  expect(outputs[0]).to receive(:tock)
         | 
| 21 51 | 
             
                  subject.tock
         | 
| 22 52 | 
             
                end
         | 
| 23 53 | 
             
              end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
              describe '#create_inputs' do
         | 
| 56 | 
            +
                before :each do
         | 
| 57 | 
            +
                  allow(subject).to receive(:input_count).and_return(2)
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                context 'when the given argument is less than the value of input count' do
         | 
| 61 | 
            +
                  it 'fails with an argument error' do
         | 
| 62 | 
            +
                    expect { subject.mock_create_inputs(0) }.to raise_error(ArgumentError)
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                context 'when given a valid number of inputs' do
         | 
| 67 | 
            +
                  [2, 4, 6].each do |n|
         | 
| 68 | 
            +
                    it "creates #{n} inputs" do
         | 
| 69 | 
            +
                      expect(subject.mock_create_inputs(n).size).to eq(n)
         | 
| 70 | 
            +
                    end
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
              end
         | 
| 24 74 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: circuits
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Henry Muru Paenga
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-10- | 
| 11 | 
            +
            date: 2015-10-24 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -66,6 +66,48 @@ dependencies: | |
| 66 66 | 
             
                - - ~>
         | 
| 67 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 68 | 
             
                    version: '3.3'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: rubocop
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - ~>
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '0.34'
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - ~>
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '0.34'
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: reek
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - ~>
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '3.5'
         | 
| 90 | 
            +
              type: :development
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - ~>
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '3.5'
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: yard
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - ~>
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: 0.8.7
         | 
| 104 | 
            +
              type: :development
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - ~>
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: 0.8.7
         | 
| 69 111 | 
             
            description: 
         | 
| 70 112 | 
             
            email:
         | 
| 71 113 | 
             
            - meringu@gmail.com
         |