circuits 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/circuits/component/and.rb +10 -6
- data/lib/circuits/component/base.rb +34 -66
- data/lib/circuits/component/nand.rb +10 -6
- data/lib/circuits/component/nor.rb +10 -6
- data/lib/circuits/component/not.rb +10 -6
- data/lib/circuits/component/or.rb +10 -6
- data/lib/circuits/component/sr_nand.rb +23 -24
- data/lib/circuits/component/sr_nor.rb +23 -24
- data/lib/circuits/component/xnor.rb +10 -6
- data/lib/circuits/component/xor.rb +10 -6
- data/lib/circuits/terminal/output.rb +2 -1
- data/lib/circuits/version.rb +1 -1
- data/spec/spec_helper.rb +3 -1
- data/spec/unit/circuits/component/and_spec.rb +1 -1
- data/spec/unit/circuits/component/base_spec.rb +30 -78
- data/spec/unit/circuits/component/nand_spec.rb +1 -1
- data/spec/unit/circuits/component/nor_spec.rb +1 -1
- data/spec/unit/circuits/component/or_spec.rb +1 -1
- data/spec/unit/circuits/component/xnor_spec.rb +2 -2
- data/spec/unit/circuits/component/xor_spec.rb +2 -2
- data/spec/unit/circuits/terminal/input_spec.rb +49 -0
- data/spec/unit/circuits/terminal/output_spec.rb +111 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzM4MzA1YTA1NmFhMjY1ZmMzYzY1ZTgxOWY2MDlhMTQ3YzVkY2Q3OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzhmN2Y4ZTdiODliY2ZkYjQyNjRjODk0OWZmNmYwNmE4NDRjMGQ1Nw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGRlNzY4OThhNmRmNWE4MDQ1NzdjMDk2NmEzNzM1YTQ3ZWRiMGMzNGExMTM5
|
10
|
+
N2JiMmVhNDI3ODQ1MzM1YmQ1NmNiNjExZWJmZDA4MzI0YmUzMTc2YjE4NGI3
|
11
|
+
OWY5NGIzNjE3Nzc4NmQ4NDA4MTE2ZTExMWVjZGFmMTM3ZGViNzg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjFmOTRjYWM1NDExNDgzMDEwMTFiNTQ1ZTI3NjYyNzA4MzUyNWIwNjYzNjk1
|
14
|
+
MDU5ODQ4ZDY5M2Y2MWVjYjJmNTE3OTIxMTliZjNlNzRjNzgxOWRiYWQ5NWFk
|
15
|
+
ZGQyM2U4YmMzYjBjZGI3OGVmOWJiYmVjYTYwNTA1Yzk2ODM4YWM=
|
@@ -4,16 +4,20 @@ module Circuits
|
|
4
4
|
module Component
|
5
5
|
# Logical AND Operator
|
6
6
|
class And < Base
|
7
|
-
def initialize(opts = {})
|
8
|
-
@input_count = 2
|
9
|
-
@output_count = 1
|
10
|
-
super opts
|
11
|
-
end
|
12
|
-
|
13
7
|
# Sets the output to be the result of a logical AND of the inputs
|
14
8
|
def tick
|
15
9
|
self[:out].set(inputs.map(&:get).inject(:&))
|
16
10
|
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def default_input_count
|
15
|
+
2
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_output_count
|
19
|
+
1
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -10,17 +10,22 @@ module Circuits
|
|
10
10
|
class Base
|
11
11
|
# Creates the Component with inputs and outputs
|
12
12
|
# @param opts [Hash] options to create the Component with
|
13
|
-
# @option opts [
|
14
|
-
#
|
13
|
+
# @option opts [FixNum] :input_count The number of inputs
|
14
|
+
# @option opts [FixNum] :ouput_count The number of outputs
|
15
|
+
# @option opts [Hash] :port_mappings The port_mappings to use
|
15
16
|
def initialize(opts = {})
|
16
|
-
|
17
|
-
|
17
|
+
input_count = opts[:input_count] || default_input_count
|
18
|
+
output_count = opts[:output_count] || default_output_count
|
19
|
+
@inputs = input_count.times.collect { Circuits::Terminal::Input.new }
|
20
|
+
@outputs = output_count.times.collect { Circuits::Terminal::Output.new }
|
21
|
+
@port_mappings = opts[:port_mappings] || default_port_mappings
|
18
22
|
end
|
19
23
|
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
# the inputs of this component
|
25
|
+
attr_reader :inputs
|
26
|
+
|
27
|
+
# the outputs of this component
|
28
|
+
attr_reader :outputs
|
24
29
|
|
25
30
|
# Sets all the outputs expose what was set in #tick
|
26
31
|
def tock
|
@@ -31,83 +36,46 @@ module Circuits
|
|
31
36
|
# @param port [Symbol] The symbol that represents the terminal
|
32
37
|
# @return [Input, Output] The terminal
|
33
38
|
def [](port)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
inputs[p[:number]]
|
38
|
-
when :output
|
39
|
-
outputs[p[:number]]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Assigns to an input or output
|
44
|
-
# @param port [Symbol] The symbol that represents the terminal
|
45
|
-
# @param terminal [Input, Output] The terminal to assign
|
46
|
-
# @return [Input, Output] The terminal that was passed in
|
47
|
-
def []=(port, terminal)
|
48
|
-
p = port_mappings[port]
|
49
|
-
case p[:type]
|
39
|
+
port_mapping = port_mappings[port]
|
40
|
+
port_number = port_mapping[:number]
|
41
|
+
case port_mapping[:type]
|
50
42
|
when :input
|
51
|
-
inputs[
|
43
|
+
inputs[port_number]
|
52
44
|
when :output
|
53
|
-
outputs[
|
45
|
+
outputs[port_number]
|
54
46
|
end
|
55
47
|
end
|
56
48
|
|
57
|
-
# the inputs of this component
|
58
|
-
attr_reader :inputs
|
59
|
-
|
60
|
-
# the outputs of this component
|
61
|
-
attr_reader :outputs
|
62
|
-
|
63
49
|
private
|
64
50
|
|
65
|
-
|
66
|
-
if opts[:inputs].class == Array
|
67
|
-
@inputs = opts[:inputs]
|
68
|
-
@input_count = @inputs.length
|
69
|
-
elsif opts[:inputs].class == Fixnum
|
70
|
-
@input_count = opts[:inputs]
|
71
|
-
end
|
72
|
-
@inputs ||= @input_count.times.collect { Circuits::Terminal::Input.new }
|
73
|
-
end
|
51
|
+
attr_reader :port_mappings
|
74
52
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
elsif opts[:outputs].class == Fixnum
|
80
|
-
@output_count = opts[:outputs]
|
81
|
-
end
|
82
|
-
@outputs ||= @output_count.times.collect do
|
83
|
-
Circuits::Terminal::Output.new
|
53
|
+
def default_port_mappings
|
54
|
+
res = {}
|
55
|
+
(input_mappings + output_mappings).each do |mapping|
|
56
|
+
res.merge!(mapping)
|
84
57
|
end
|
85
|
-
|
86
|
-
|
87
|
-
def port_mappings
|
88
|
-
return @port_mappings unless @port_mappings.nil?
|
89
|
-
@port_mappings = {}
|
90
|
-
input_mappings.each { |x| @port_mappings.merge!(x) }
|
91
|
-
output_mappings.each { |x| @port_mappings.merge!(x) }
|
92
|
-
@port_mappings
|
58
|
+
res
|
93
59
|
end
|
94
60
|
|
95
61
|
def input_mappings
|
96
|
-
|
97
|
-
|
98
|
-
|
62
|
+
input_count = inputs.length
|
63
|
+
return [{ in: { type: :input, number: 0 } }] if input_count == 1
|
64
|
+
input_count.times.collect do |num|
|
65
|
+
{ num_to_port(num) => { type: :input, number: num } }
|
99
66
|
end
|
100
67
|
end
|
101
68
|
|
102
69
|
def output_mappings
|
103
|
-
|
104
|
-
|
105
|
-
|
70
|
+
output_count = outputs.length
|
71
|
+
return[{ out: { type: :output, number: 0 } }] if output_count == 1
|
72
|
+
output_count.times.collect do |num|
|
73
|
+
{ num_to_port(num + inputs.length) => { type: :output, number: num } }
|
106
74
|
end
|
107
75
|
end
|
108
76
|
|
109
|
-
def num_to_port(
|
110
|
-
(
|
77
|
+
def num_to_port(num)
|
78
|
+
(num + 'a'.ord).chr.to_sym
|
111
79
|
end
|
112
80
|
end
|
113
81
|
end
|
@@ -4,16 +4,20 @@ module Circuits
|
|
4
4
|
module Component
|
5
5
|
# Logical NAND Operator
|
6
6
|
class Nand < Base
|
7
|
-
def initialize(opts = {})
|
8
|
-
@input_count = 2
|
9
|
-
@output_count = 1
|
10
|
-
super opts
|
11
|
-
end
|
12
|
-
|
13
7
|
# Sets the output to be the result of a logical NAND of the inputs
|
14
8
|
def tick
|
15
9
|
self[:out].set(!inputs.map(&:get).inject(:&))
|
16
10
|
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def default_input_count
|
15
|
+
2
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_output_count
|
19
|
+
1
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -4,16 +4,20 @@ module Circuits
|
|
4
4
|
module Component
|
5
5
|
# Logical NOR Operator
|
6
6
|
class Nor < Base
|
7
|
-
def initialize(opts = {})
|
8
|
-
@input_count = 2
|
9
|
-
@output_count = 1
|
10
|
-
super opts
|
11
|
-
end
|
12
|
-
|
13
7
|
# Sets the output to be the result of a logical OR of the inputs
|
14
8
|
def tick
|
15
9
|
self[:out].set(!inputs.map(&:get).inject(:|))
|
16
10
|
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def default_input_count
|
15
|
+
2
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_output_count
|
19
|
+
1
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -4,16 +4,20 @@ module Circuits
|
|
4
4
|
module Component
|
5
5
|
# Logical NOT Operator
|
6
6
|
class Not < Base
|
7
|
-
def initialize(opts = {})
|
8
|
-
@input_count = 1
|
9
|
-
@output_count = 1
|
10
|
-
super opts
|
11
|
-
end
|
12
|
-
|
13
7
|
# Sets the output to be the result of a logical NOT of the inputs
|
14
8
|
def tick
|
15
9
|
self[:out].set(!self[:in].get)
|
16
10
|
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def default_input_count
|
15
|
+
1
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_output_count
|
19
|
+
1
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -4,16 +4,20 @@ module Circuits
|
|
4
4
|
module Component
|
5
5
|
# Logical OR Operator
|
6
6
|
class Or < Base
|
7
|
-
def initialize(opts = {})
|
8
|
-
@input_count = 2
|
9
|
-
@output_count = 1
|
10
|
-
super opts
|
11
|
-
end
|
12
|
-
|
13
7
|
# Sets the output to be the result of a logical OR of the inputs
|
14
8
|
def tick
|
15
9
|
self[:out].set(inputs.map(&:get).inject(:|))
|
16
10
|
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def default_input_count
|
15
|
+
2
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_output_count
|
19
|
+
1
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -5,9 +5,11 @@ module Circuits
|
|
5
5
|
module Component
|
6
6
|
# SR NAND Latch
|
7
7
|
class SrNand < Base
|
8
|
-
def initialize
|
9
|
-
|
10
|
-
|
8
|
+
def initialize
|
9
|
+
super(port_mappings: { not_s: { type: :input, number: 0 },
|
10
|
+
not_r: { type: :input, number: 1 },
|
11
|
+
q: { type: :output, number: 0 },
|
12
|
+
not_q: { type: :output, number: 1 } })
|
11
13
|
create_sub_components
|
12
14
|
link_inputs
|
13
15
|
link_outputs
|
@@ -24,38 +26,35 @@ module Circuits
|
|
24
26
|
|
25
27
|
private
|
26
28
|
|
27
|
-
attr_reader :
|
29
|
+
attr_reader :nand_s, :nand_r, :sub_components
|
28
30
|
|
29
31
|
def create_sub_components
|
30
|
-
@
|
31
|
-
@
|
32
|
-
@sub_components = [@
|
32
|
+
@nand_s = Nand.new
|
33
|
+
@nand_r = Nand.new
|
34
|
+
@sub_components = [@nand_s, @nand_r]
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_input_count
|
38
|
+
2
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_output_count
|
42
|
+
2
|
33
43
|
end
|
34
44
|
|
35
45
|
def link_inputs
|
36
|
-
|
37
|
-
|
46
|
+
nand_s[:a].set self[:not_s]
|
47
|
+
nand_r[:a].set self[:not_r]
|
38
48
|
end
|
39
49
|
|
40
50
|
def link_outputs
|
41
|
-
self[:q].set
|
42
|
-
self[:not_q].set
|
51
|
+
self[:q].set nand_s[:out]
|
52
|
+
self[:not_q].set nand_r[:out]
|
43
53
|
end
|
44
54
|
|
45
55
|
def link_sub_components
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def set_defaults
|
51
|
-
@input_count = 2
|
52
|
-
@output_count = 2
|
53
|
-
@port_mappings = {
|
54
|
-
not_s: { type: :input, number: 0 },
|
55
|
-
not_r: { type: :input, number: 1 },
|
56
|
-
q: { type: :output, number: 0 },
|
57
|
-
not_q: { type: :output, number: 1 }
|
58
|
-
}
|
56
|
+
nand_s[:b].set nand_r[:out]
|
57
|
+
nand_r[:b].set nand_s[:out]
|
59
58
|
end
|
60
59
|
end
|
61
60
|
end
|
@@ -5,9 +5,11 @@ module Circuits
|
|
5
5
|
module Component
|
6
6
|
# SR NOR Latch
|
7
7
|
class SrNor < Base
|
8
|
-
def initialize
|
9
|
-
|
10
|
-
|
8
|
+
def initialize
|
9
|
+
super(port_mappings: { r: { type: :input, number: 0 },
|
10
|
+
s: { type: :input, number: 1 },
|
11
|
+
q: { type: :output, number: 0 },
|
12
|
+
not_q: { type: :output, number: 1 } })
|
11
13
|
create_sub_components
|
12
14
|
link_inputs
|
13
15
|
link_outputs
|
@@ -24,38 +26,35 @@ module Circuits
|
|
24
26
|
|
25
27
|
private
|
26
28
|
|
27
|
-
attr_reader :
|
29
|
+
attr_reader :nor_r, :nor_s, :sub_components
|
28
30
|
|
29
31
|
def create_sub_components
|
30
|
-
@
|
31
|
-
@
|
32
|
-
@sub_components = [@
|
32
|
+
@nor_r = Nor.new
|
33
|
+
@nor_s = Nor.new
|
34
|
+
@sub_components = [@nor_r, @nor_s]
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_input_count
|
38
|
+
2
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_output_count
|
42
|
+
2
|
33
43
|
end
|
34
44
|
|
35
45
|
def link_inputs
|
36
|
-
|
37
|
-
|
46
|
+
nor_r[:a].set self[:r]
|
47
|
+
nor_s[:a].set self[:s]
|
38
48
|
end
|
39
49
|
|
40
50
|
def link_outputs
|
41
|
-
self[:q].set
|
42
|
-
self[:not_q].set
|
51
|
+
self[:q].set nor_r[:out]
|
52
|
+
self[:not_q].set nor_s[:out]
|
43
53
|
end
|
44
54
|
|
45
55
|
def link_sub_components
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def set_defaults
|
51
|
-
@input_count = 2
|
52
|
-
@output_count = 2
|
53
|
-
@port_mappings = {
|
54
|
-
r: { type: :input, number: 0 },
|
55
|
-
s: { type: :input, number: 1 },
|
56
|
-
q: { type: :output, number: 0 },
|
57
|
-
not_q: { type: :output, number: 1 }
|
58
|
-
}
|
56
|
+
nor_r[:b].set nor_s[:out]
|
57
|
+
nor_s[:b].set nor_r[:out]
|
59
58
|
end
|
60
59
|
end
|
61
60
|
end
|
@@ -4,16 +4,20 @@ module Circuits
|
|
4
4
|
module Component
|
5
5
|
# Logical XNOR Operator
|
6
6
|
class Xnor < Base
|
7
|
-
def initialize(opts = {})
|
8
|
-
@input_count = 2
|
9
|
-
@output_count = 1
|
10
|
-
super opts
|
11
|
-
end
|
12
|
-
|
13
7
|
# Sets the output to be the result of a logical XNOR of the inputs
|
14
8
|
def tick
|
15
9
|
self[:out].set(!inputs.map(&:get).inject(:^))
|
16
10
|
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def default_input_count
|
15
|
+
2
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_output_count
|
19
|
+
1
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -4,16 +4,20 @@ module Circuits
|
|
4
4
|
module Component
|
5
5
|
# Logical XOR Operator
|
6
6
|
class Xor < Base
|
7
|
-
def initialize(opts = {})
|
8
|
-
@input_count = 2
|
9
|
-
@output_count = 1
|
10
|
-
super opts
|
11
|
-
end
|
12
|
-
|
13
7
|
# Sets the output to be the result of a logical XOR of the inputs
|
14
8
|
def tick
|
15
9
|
self[:out].set(inputs.map(&:get).inject(:^))
|
16
10
|
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def default_input_count
|
15
|
+
2
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_output_count
|
19
|
+
1
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -6,6 +6,7 @@ module Circuits
|
|
6
6
|
# Creates the output
|
7
7
|
# @param opts [Hash] Options to create the Output with
|
8
8
|
# @option opts [Boolean] :state The initial state of the Output
|
9
|
+
# @option opts [Input, Output] :terminal The terminal to read from
|
9
10
|
def initialize(opts = {})
|
10
11
|
@next_state = opts[:terminal] || opts[:state] || false
|
11
12
|
tock
|
@@ -18,7 +19,7 @@ module Circuits
|
|
18
19
|
end
|
19
20
|
|
20
21
|
# The next state
|
21
|
-
# @param [Boolean, Terminal]
|
22
|
+
# @param [Boolean, Terminal] state The terminal or state to output
|
22
23
|
def set(state)
|
23
24
|
@next_state = state
|
24
25
|
end
|
data/lib/circuits/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -58,7 +58,7 @@ describe Circuits::Component::And do
|
|
58
58
|
|
59
59
|
[3, 4, 8].each do |n|
|
60
60
|
context "with #{n} inputs" do
|
61
|
-
subject { Circuits::Component::And.new
|
61
|
+
subject { Circuits::Component::And.new input_count: n }
|
62
62
|
|
63
63
|
before do
|
64
64
|
n.times { |x| subject.inputs[x].set inputs[x] }
|
@@ -2,100 +2,52 @@ require 'spec_helper'
|
|
2
2
|
require 'circuits/component/base'
|
3
3
|
|
4
4
|
# Mock component to include Circuits::Component::Base
|
5
|
-
class
|
6
|
-
def
|
7
|
-
|
8
|
-
@output_count = 1
|
9
|
-
super opts
|
5
|
+
class MockComponent1 < Circuits::Component::Base
|
6
|
+
def default_input_count
|
7
|
+
1
|
10
8
|
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe Circuits::Component::Base do
|
14
|
-
context 'when using defaults' do
|
15
|
-
subject { MockComponent.new }
|
16
|
-
|
17
|
-
it 'has one input' do
|
18
|
-
expect(subject.inputs.count).to eq(1)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'has one output' do
|
22
|
-
expect(subject.outputs.count).to eq(1)
|
23
|
-
end
|
24
9
|
|
25
|
-
|
26
|
-
|
27
|
-
let(:new_output) { double('new_output') }
|
28
|
-
|
29
|
-
before do
|
30
|
-
subject[:in] = new_input
|
31
|
-
subject[:out] = new_output
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'has the new input available as :in' do
|
35
|
-
expect(subject[:in]).to eq(new_input)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'has the new output available as :out' do
|
39
|
-
expect(subject[:out]).to eq(new_output)
|
40
|
-
end
|
41
|
-
end
|
10
|
+
def default_output_count
|
11
|
+
1
|
42
12
|
end
|
13
|
+
end
|
43
14
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
expect(subject.inputs.count).to eq(2)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'has one output' do
|
52
|
-
expect(subject.outputs.count).to eq(2)
|
53
|
-
end
|
15
|
+
# Mock component to include Circuits::Component::Base
|
16
|
+
class MockComponent2 < Circuits::Component::Base
|
17
|
+
def default_input_count
|
18
|
+
2
|
54
19
|
end
|
55
20
|
|
56
|
-
|
57
|
-
|
58
|
-
|
21
|
+
def default_output_count
|
22
|
+
2
|
23
|
+
end
|
24
|
+
end
|
59
25
|
|
60
|
-
|
26
|
+
describe Circuits::Component::Base do
|
27
|
+
describe '#[]' do
|
28
|
+
context 'one input and one output' do
|
29
|
+
subject { MockComponent1.new }
|
61
30
|
|
62
|
-
|
63
|
-
|
64
|
-
expect { subject.tick }.to raise_error(NotImplementedError)
|
31
|
+
it 'has the input available as :in' do
|
32
|
+
expect(subject[:in]).to eq(subject.inputs[0])
|
65
33
|
end
|
66
|
-
end
|
67
34
|
|
68
|
-
|
69
|
-
|
70
|
-
expect(outputs[0]).to receive(:tock)
|
71
|
-
subject.tock
|
35
|
+
it 'has the output available as :out' do
|
36
|
+
expect(subject[:out]).to eq(subject.outputs[0])
|
72
37
|
end
|
73
38
|
end
|
74
39
|
|
75
|
-
|
76
|
-
|
77
|
-
it 'has the input available as :in' do
|
78
|
-
expect(subject[:in]).to eq(inputs[0])
|
79
|
-
end
|
40
|
+
context 'two inputs and two outputs' do
|
41
|
+
subject { MockComponent2.new }
|
80
42
|
|
81
|
-
|
82
|
-
|
83
|
-
|
43
|
+
it 'has the inputs available as :a and :b' do
|
44
|
+
expect(subject[:a]).to eq(subject.inputs[0])
|
45
|
+
expect(subject[:b]).to eq(subject.inputs[1])
|
84
46
|
end
|
85
47
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
it 'has the inputs available as :a and :b' do
|
91
|
-
expect(subject[:a]).to eq(inputs[0])
|
92
|
-
expect(subject[:b]).to eq(inputs[1])
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'has the outputs available as :c and :d' do
|
96
|
-
expect(subject[:c]).to eq(outputs[0])
|
97
|
-
expect(subject[:d]).to eq(outputs[1])
|
98
|
-
end
|
48
|
+
it 'has the outputs available as :c and :d' do
|
49
|
+
expect(subject[:c]).to eq(subject.outputs[0])
|
50
|
+
expect(subject[:d]).to eq(subject.outputs[1])
|
99
51
|
end
|
100
52
|
end
|
101
53
|
end
|
@@ -57,7 +57,7 @@ describe Circuits::Component::Nand do
|
|
57
57
|
end
|
58
58
|
[3, 4, 8].each do |n|
|
59
59
|
context "with #{n} inputs" do
|
60
|
-
subject { Circuits::Component::Nand.new
|
60
|
+
subject { Circuits::Component::Nand.new input_count: n }
|
61
61
|
|
62
62
|
before do
|
63
63
|
n.times { |x| subject.inputs[x].set inputs[x] }
|
@@ -57,7 +57,7 @@ describe Circuits::Component::Nor do
|
|
57
57
|
end
|
58
58
|
[3, 4, 8].each do |n|
|
59
59
|
context "with #{n} inputs" do
|
60
|
-
subject { Circuits::Component::Nor.new
|
60
|
+
subject { Circuits::Component::Nor.new input_count: n }
|
61
61
|
|
62
62
|
before do
|
63
63
|
n.times { |x| subject.inputs[x].set inputs[x] }
|
@@ -57,7 +57,7 @@ describe Circuits::Component::Or do
|
|
57
57
|
end
|
58
58
|
[3, 4, 8].each do |n|
|
59
59
|
context "with #{n} inputs" do
|
60
|
-
subject { Circuits::Component::Or.new
|
60
|
+
subject { Circuits::Component::Or.new input_count: n }
|
61
61
|
|
62
62
|
before do
|
63
63
|
n.times { |x| subject.inputs[x].set inputs[x] }
|
@@ -58,7 +58,7 @@ describe Circuits::Component::Xnor do
|
|
58
58
|
context 'when the number of inputs is even' do
|
59
59
|
[2, 4, 8].each do |n|
|
60
60
|
context "with #{n} inputs" do
|
61
|
-
subject { Circuits::Component::Xnor.new
|
61
|
+
subject { Circuits::Component::Xnor.new input_count: n }
|
62
62
|
|
63
63
|
before do
|
64
64
|
n.times { |x| subject.inputs[x].set inputs[x] }
|
@@ -107,7 +107,7 @@ describe Circuits::Component::Xnor do
|
|
107
107
|
context 'when the number of inputs is odd' do
|
108
108
|
[3, 5, 7].each do |n|
|
109
109
|
context "with #{n} inputs" do
|
110
|
-
subject { Circuits::Component::Xnor.new
|
110
|
+
subject { Circuits::Component::Xnor.new input_count: n }
|
111
111
|
|
112
112
|
before do
|
113
113
|
n.times { |x| subject.inputs[x].set inputs[x] }
|
@@ -58,7 +58,7 @@ describe Circuits::Component::Xor do
|
|
58
58
|
context 'when the number of inputs is even' do
|
59
59
|
[2, 4, 8].each do |n|
|
60
60
|
context "with #{n} inputs" do
|
61
|
-
subject { Circuits::Component::Xor.new
|
61
|
+
subject { Circuits::Component::Xor.new input_count: n }
|
62
62
|
|
63
63
|
before do
|
64
64
|
n.times { |x| subject.inputs[x].set inputs[x] }
|
@@ -107,7 +107,7 @@ describe Circuits::Component::Xor do
|
|
107
107
|
context 'when the number of inputs is odd' do
|
108
108
|
[3, 5, 7].each do |n|
|
109
109
|
context "with #{n} inputs" do
|
110
|
-
subject { Circuits::Component::Xor.new
|
110
|
+
subject { Circuits::Component::Xor.new input_count: n }
|
111
111
|
|
112
112
|
before do
|
113
113
|
n.times { |x| subject.inputs[x].set inputs[x] }
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'circuits/terminal/input'
|
3
|
+
|
4
|
+
describe Circuits::Terminal::Input do
|
5
|
+
describe '#get' do
|
6
|
+
context 'when given no state' do
|
7
|
+
subject { Circuits::Terminal::Input.new }
|
8
|
+
|
9
|
+
it 'is false' do
|
10
|
+
expect(subject.get).to eq(false)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#set' do
|
16
|
+
let(:state) { double('state') }
|
17
|
+
|
18
|
+
context 'when given a state' do
|
19
|
+
subject { Circuits::Terminal::Input.new(state: state) }
|
20
|
+
|
21
|
+
it 'has that state' do
|
22
|
+
subject.set state
|
23
|
+
expect(subject.get).to eq(state)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when given an input' do
|
28
|
+
let(:input) { Circuits::Terminal::Input.new(state: state) }
|
29
|
+
|
30
|
+
subject { Circuits::Terminal::Input.new }
|
31
|
+
|
32
|
+
it 'has the input state' do
|
33
|
+
subject.set input
|
34
|
+
expect(subject.get).to eq(state)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when given an output' do
|
39
|
+
let(:output) { Circuits::Terminal::Output.new(state: state) }
|
40
|
+
|
41
|
+
subject { Circuits::Terminal::Input.new }
|
42
|
+
|
43
|
+
it 'has the output state' do
|
44
|
+
subject.set output
|
45
|
+
expect(subject.get).to eq(state)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'circuits/terminal/output'
|
3
|
+
|
4
|
+
describe Circuits::Terminal::Output do
|
5
|
+
describe '#get' do
|
6
|
+
let(:state) { double('state') }
|
7
|
+
|
8
|
+
context 'when given no state' do
|
9
|
+
subject { Circuits::Terminal::Output.new }
|
10
|
+
|
11
|
+
it 'is false' do
|
12
|
+
expect(subject.get).to eq(false)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when given a state' do
|
17
|
+
subject { Circuits::Terminal::Output.new(state: state) }
|
18
|
+
|
19
|
+
it 'has that state' do
|
20
|
+
expect(subject.get).to eq(state)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when given an input' do
|
25
|
+
let(:input) { Circuits::Terminal::Input.new(state: state) }
|
26
|
+
|
27
|
+
subject { Circuits::Terminal::Output.new(terminal: input) }
|
28
|
+
|
29
|
+
it 'has the input state' do
|
30
|
+
expect(subject.get).to eq(state)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when given an output' do
|
35
|
+
let(:output) { Circuits::Terminal::Output.new(state: state) }
|
36
|
+
|
37
|
+
subject { Circuits::Terminal::Output.new(terminal: output) }
|
38
|
+
|
39
|
+
it 'has the output state' do
|
40
|
+
expect(subject.get).to eq(state)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#set' do
|
46
|
+
let(:state_1) { double('state_1') }
|
47
|
+
let(:state_2) { double('state_2') }
|
48
|
+
|
49
|
+
subject { Circuits::Terminal::Output.new(state: state_1) }
|
50
|
+
|
51
|
+
context 'when given a state' do
|
52
|
+
it 'gets does not get set immediately' do
|
53
|
+
subject.set state_2
|
54
|
+
expect(subject.get).to eq(state_1)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when given an input' do
|
59
|
+
let(:input) { Circuits::Terminal::Input.new(state: state_2) }
|
60
|
+
|
61
|
+
it 'gets does not get set immediately' do
|
62
|
+
subject.set input
|
63
|
+
expect(subject.get).to eq(state_1)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when given an output' do
|
68
|
+
let(:output) { Circuits::Terminal::Output.new(state: state_2) }
|
69
|
+
|
70
|
+
it 'gets does not get set immediately' do
|
71
|
+
subject.set output
|
72
|
+
expect(subject.get).to eq(state_1)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#tock' do
|
78
|
+
let(:state_1) { double('state_1') }
|
79
|
+
let(:state_2) { double('state_2') }
|
80
|
+
|
81
|
+
subject { Circuits::Terminal::Output.new(state: state_1) }
|
82
|
+
|
83
|
+
context 'when given a state' do
|
84
|
+
it 'updates the state' do
|
85
|
+
subject.set state_2
|
86
|
+
subject.tock
|
87
|
+
expect(subject.get).to eq(state_2)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'when given an input' do
|
92
|
+
let(:input) { Circuits::Terminal::Input.new(state: state_2) }
|
93
|
+
|
94
|
+
it 'updates the state' do
|
95
|
+
subject.set input
|
96
|
+
subject.tock
|
97
|
+
expect(subject.get).to eq(state_2)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'when given an output' do
|
102
|
+
let(:output) { Circuits::Terminal::Output.new(state: state_2) }
|
103
|
+
|
104
|
+
it 'updates the state' do
|
105
|
+
subject.set output
|
106
|
+
subject.tock
|
107
|
+
expect(subject.get).to eq(state_2)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
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.8.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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -148,6 +148,8 @@ files:
|
|
148
148
|
- spec/unit/circuits/component/sr_nor_spec.rb
|
149
149
|
- spec/unit/circuits/component/xnor_spec.rb
|
150
150
|
- spec/unit/circuits/component/xor_spec.rb
|
151
|
+
- spec/unit/circuits/terminal/input_spec.rb
|
152
|
+
- spec/unit/circuits/terminal/output_spec.rb
|
151
153
|
homepage: https://github.com/meringu/circuits
|
152
154
|
licenses:
|
153
155
|
- MIT
|
@@ -184,3 +186,5 @@ test_files:
|
|
184
186
|
- spec/unit/circuits/component/sr_nor_spec.rb
|
185
187
|
- spec/unit/circuits/component/xnor_spec.rb
|
186
188
|
- spec/unit/circuits/component/xor_spec.rb
|
189
|
+
- spec/unit/circuits/terminal/input_spec.rb
|
190
|
+
- spec/unit/circuits/terminal/output_spec.rb
|