circuits 0.3.0 → 0.4.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 +3 -6
- data/lib/circuits/component/nand.rb +3 -6
- data/lib/circuits/component/nor.rb +3 -6
- data/lib/circuits/component/not.rb +3 -6
- data/lib/circuits/component/or.rb +3 -6
- data/lib/circuits/component/sr_nand.rb +19 -14
- data/lib/circuits/component/sr_nor.rb +17 -12
- data/lib/circuits/component/xnor.rb +3 -6
- data/lib/circuits/component/xor.rb +3 -6
- data/lib/circuits/component.rb +81 -22
- data/lib/circuits/terminal.rb +0 -1
- data/lib/circuits/version.rb +1 -1
- data/spec/unit/circuits/component/and_spec.rb +9 -9
- data/spec/unit/circuits/component/nand_spec.rb +9 -9
- data/spec/unit/circuits/component/nor_spec.rb +9 -9
- data/spec/unit/circuits/component/not_spec.rb +3 -3
- data/spec/unit/circuits/component/or_spec.rb +9 -9
- data/spec/unit/circuits/component/sr_nand_spec.rb +20 -20
- data/spec/unit/circuits/component/sr_nor_spec.rb +20 -20
- data/spec/unit/circuits/component/xnor_spec.rb +13 -13
- data/spec/unit/circuits/component/xor_spec.rb +13 -13
- data/spec/unit/circuits/component_spec.rb +81 -41
- data/spec/unit/circuits/terminal/input_spec.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmI1YWI5MTBmZDIyNjQ3MjcxMjk4NDVmNWVjYWNjYjMyNjdmNjAzYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTBkMDBiZTA5YTRkOWMyYzRmMDJiNWYxNzc1ZTEwNjgxMGYyYTdmYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjA4MzkxY2Q5ODc2Mzk5YWM1YjUxYTU2OGFmYWQ4NmM4OTJhMzE4ODdjMzAz
|
10
|
+
YzBhY2YyNDhkMTQ4ZWQzODgyNmM5Njk0MGQ1ZGM2NTZhZmQ3NjY2ZmQ5Nzc4
|
11
|
+
NTc4YTcxZTgzYTdhOGI2OTFlMWRiNTI0NGY3OWE0YTcwNjhhZTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGI2ZDBiYTBkNDlhNTRiNjJkYmNlNjg5OWNkMjk2YWRhMTlmMzVmNmFkNjFm
|
14
|
+
NzFiZDk4ZmMxZTFlYjc5NjI5NTRmMmIwYzRiNDQ3YjlkMDc3MDFmOTZlMmIx
|
15
|
+
ZGI4NTdiZmJkOGEzNTM5ZTVjNGZjMDRjNmI1ZmYzOGZkNzA1ZTM=
|
@@ -12,28 +12,33 @@ module Circuits
|
|
12
12
|
sub_components.each(&:tick)
|
13
13
|
sub_components.each(&:tock)
|
14
14
|
end
|
15
|
-
|
16
|
-
|
15
|
+
self[:q].set nand_1[:out].get
|
16
|
+
self[:not_q].set nand_2[:out].get
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
attr_reader :
|
21
|
+
attr_reader :nand_1, :nand_2, :sub_components
|
22
22
|
|
23
|
-
def
|
24
|
-
2
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
def set_defaults
|
24
|
+
@input_count = 2
|
25
|
+
@output_count = 2
|
26
|
+
@port_mappings = {
|
27
|
+
not_s: { type: :input, number: 0 },
|
28
|
+
not_r: { type: :input, number: 1 },
|
29
|
+
q: { type: :output, number: 0 },
|
30
|
+
not_q: { type: :output, number: 1 }
|
31
|
+
}
|
29
32
|
end
|
30
33
|
|
31
34
|
def setup
|
32
|
-
@
|
33
|
-
@
|
34
|
-
@sub_components = [@
|
35
|
-
|
36
|
-
|
35
|
+
@nand_1 = Nand.new
|
36
|
+
@nand_2 = Nand.new
|
37
|
+
@sub_components = [@nand_1, @nand_2]
|
38
|
+
nand_1[:a] = self[:not_s]
|
39
|
+
nand_2[:a] = self[:not_r]
|
40
|
+
nand_1[:b] = nand_2[:out]
|
41
|
+
nand_2[:b] = nand_1[:out]
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
@@ -12,28 +12,33 @@ module Circuits
|
|
12
12
|
sub_components.each(&:tick)
|
13
13
|
sub_components.each(&:tock)
|
14
14
|
end
|
15
|
-
|
16
|
-
|
15
|
+
self[:q].set nor_1[:out].get
|
16
|
+
self[:not_q].set nor_2[:out].get
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
21
|
attr_reader :nor_1, :nor_2, :sub_components
|
22
22
|
|
23
|
-
def
|
24
|
-
2
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
def set_defaults
|
24
|
+
@input_count = 2
|
25
|
+
@output_count = 2
|
26
|
+
@port_mappings = {
|
27
|
+
r: { type: :input, number: 0 },
|
28
|
+
s: { type: :input, number: 1 },
|
29
|
+
q: { type: :output, number: 0 },
|
30
|
+
not_q: { type: :output, number: 1 }
|
31
|
+
}
|
29
32
|
end
|
30
33
|
|
31
34
|
def setup
|
32
|
-
@nor_1 = Nor.new
|
33
|
-
@nor_2 = Nor.new
|
35
|
+
@nor_1 = Nor.new
|
36
|
+
@nor_2 = Nor.new
|
34
37
|
@sub_components = [@nor_1, @nor_2]
|
35
|
-
nor_1
|
36
|
-
nor_2
|
38
|
+
nor_1[:a] = self[:r]
|
39
|
+
nor_2[:a] = self[:s]
|
40
|
+
nor_1[:b] = nor_2[:out]
|
41
|
+
nor_2[:b] = nor_1[:out]
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
data/lib/circuits/component.rb
CHANGED
@@ -11,11 +11,10 @@ module Circuits
|
|
11
11
|
# @option opts [Array<Input>, FixNum] :inputs The array of inputs to use, or
|
12
12
|
# the number of inputs to create
|
13
13
|
def initialize(opts = {})
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@outputs = output_count.times.collect { Circuits::Terminal::Output.new }
|
14
|
+
set_defaults
|
15
|
+
create_inputs opts
|
16
|
+
create_outputs opts
|
17
|
+
create_port_mappings
|
19
18
|
setup
|
20
19
|
end
|
21
20
|
|
@@ -29,6 +28,33 @@ module Circuits
|
|
29
28
|
outputs.each(&:tock)
|
30
29
|
end
|
31
30
|
|
31
|
+
# Gets the teminal assigned to the port
|
32
|
+
# @param port [Symbol] The symbol that represents the terminal
|
33
|
+
# @return [Input, Output] The terminal
|
34
|
+
def [](port)
|
35
|
+
p = @port_mappings[port]
|
36
|
+
case p[:type]
|
37
|
+
when :input
|
38
|
+
@inputs[p[:number]]
|
39
|
+
when :output
|
40
|
+
@outputs[p[:number]]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Assigns to an input or output
|
45
|
+
# @param port [Symbol] The symbol that represents the terminal
|
46
|
+
# @param terminal [Input, Output] The terminal to assign
|
47
|
+
# @return [Input, Output] The terminal that was passed in
|
48
|
+
def []=(port, terminal)
|
49
|
+
p = @port_mappings[port]
|
50
|
+
case p[:type]
|
51
|
+
when :input
|
52
|
+
@inputs[p[:number]] = terminal
|
53
|
+
when :output
|
54
|
+
@outputs[p[:number]] = terminal
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
32
58
|
# the inputs of this component
|
33
59
|
attr_reader :inputs
|
34
60
|
|
@@ -37,24 +63,57 @@ module Circuits
|
|
37
63
|
|
38
64
|
private
|
39
65
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
66
|
+
def create_inputs(opts)
|
67
|
+
if opts[:inputs].class == Array
|
68
|
+
@inputs = opts[:inputs]
|
69
|
+
@input_count = @inputs.length
|
70
|
+
elsif opts[:inputs].class == Fixnum
|
71
|
+
@input_count = opts[:inputs]
|
72
|
+
end
|
73
|
+
@inputs ||= @input_count.times.collect { Circuits::Terminal::Input.new }
|
74
|
+
end
|
47
75
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
76
|
+
def create_outputs(opts)
|
77
|
+
if opts[:outputs].class == Array
|
78
|
+
@outputs = opts[:outputs]
|
79
|
+
@output_count = @outputs.length
|
80
|
+
elsif opts[:outputs].class == Fixnum
|
81
|
+
@output_count = opts[:outputs]
|
82
|
+
end
|
83
|
+
@outputs ||= @output_count.times.collect do
|
84
|
+
Circuits::Terminal::Output.new
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_port_mappings
|
89
|
+
return @port_mappings unless @port_mappings.nil?
|
90
|
+
@port_mappings = {}
|
91
|
+
input_mappings.each { |x| @port_mappings.merge!(x) }
|
92
|
+
output_mappings.each { |x| @port_mappings.merge!(x) }
|
93
|
+
@port_mappings
|
94
|
+
end
|
95
|
+
|
96
|
+
def input_mappings
|
97
|
+
return [{ in: { type: :input, number: 0 } }] if @input_count == 1
|
98
|
+
@input_count.times.collect do |i|
|
99
|
+
{ num_to_port(i) => { type: :input, number: i } }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def output_mappings
|
104
|
+
return[{ out: { type: :output, number: 0 } }] if @output_count == 1
|
105
|
+
@output_count.times.collect do |i|
|
106
|
+
{ num_to_port(i + @input_count) => { type: :output, number: i } }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def num_to_port(i)
|
111
|
+
(i + 'a'.ord).chr.to_sym
|
112
|
+
end
|
113
|
+
|
114
|
+
def set_defaults
|
115
|
+
fail NotImplementedError
|
116
|
+
end
|
58
117
|
|
59
118
|
def setup
|
60
119
|
end
|
data/lib/circuits/terminal.rb
CHANGED
data/lib/circuits/version.rb
CHANGED
@@ -7,8 +7,8 @@ describe Circuits::Component::And do
|
|
7
7
|
subject { Circuits::Component::And.new }
|
8
8
|
|
9
9
|
before do
|
10
|
-
subject
|
11
|
-
subject
|
10
|
+
subject[:a].set input_1
|
11
|
+
subject[:b].set input_2
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'false + false' do
|
@@ -18,7 +18,7 @@ describe Circuits::Component::And do
|
|
18
18
|
it '= false' do
|
19
19
|
subject.tick
|
20
20
|
subject.tock
|
21
|
-
expect(subject
|
21
|
+
expect(subject[:out].get).to eq(false)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -29,7 +29,7 @@ describe Circuits::Component::And do
|
|
29
29
|
it '= false' do
|
30
30
|
subject.tick
|
31
31
|
subject.tock
|
32
|
-
expect(subject
|
32
|
+
expect(subject[:out].get).to eq(false)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -40,7 +40,7 @@ describe Circuits::Component::And do
|
|
40
40
|
it '= false' do
|
41
41
|
subject.tick
|
42
42
|
subject.tock
|
43
|
-
expect(subject
|
43
|
+
expect(subject[:out].get).to eq(false)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -51,7 +51,7 @@ describe Circuits::Component::And do
|
|
51
51
|
it '= true' do
|
52
52
|
subject.tick
|
53
53
|
subject.tock
|
54
|
-
expect(subject
|
54
|
+
expect(subject[:out].get).to eq(true)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -70,7 +70,7 @@ describe Circuits::Component::And do
|
|
70
70
|
it '= true' do
|
71
71
|
subject.tick
|
72
72
|
subject.tock
|
73
|
-
expect(subject
|
73
|
+
expect(subject[:out].get).to eq(true)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -80,7 +80,7 @@ describe Circuits::Component::And do
|
|
80
80
|
it '= false' do
|
81
81
|
subject.tick
|
82
82
|
subject.tock
|
83
|
-
expect(subject
|
83
|
+
expect(subject[:out].get).to eq(false)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -96,7 +96,7 @@ describe Circuits::Component::And do
|
|
96
96
|
it '= false' do
|
97
97
|
subject.tick
|
98
98
|
subject.tock
|
99
|
-
expect(subject
|
99
|
+
expect(subject[:out].get).to eq(false)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -7,8 +7,8 @@ describe Circuits::Component::Nand do
|
|
7
7
|
subject { Circuits::Component::Nand.new }
|
8
8
|
|
9
9
|
before do
|
10
|
-
subject
|
11
|
-
subject
|
10
|
+
subject[:a].set input_1
|
11
|
+
subject[:b].set input_2
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'false + false' do
|
@@ -18,7 +18,7 @@ describe Circuits::Component::Nand do
|
|
18
18
|
it '= true' do
|
19
19
|
subject.tick
|
20
20
|
subject.tock
|
21
|
-
expect(subject
|
21
|
+
expect(subject[:out].get).to eq(true)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -29,7 +29,7 @@ describe Circuits::Component::Nand do
|
|
29
29
|
it '= true' do
|
30
30
|
subject.tick
|
31
31
|
subject.tock
|
32
|
-
expect(subject
|
32
|
+
expect(subject[:out].get).to eq(true)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -40,7 +40,7 @@ describe Circuits::Component::Nand do
|
|
40
40
|
it '= true' do
|
41
41
|
subject.tick
|
42
42
|
subject.tock
|
43
|
-
expect(subject
|
43
|
+
expect(subject[:out].get).to eq(true)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -51,7 +51,7 @@ describe Circuits::Component::Nand do
|
|
51
51
|
it '= false' do
|
52
52
|
subject.tick
|
53
53
|
subject.tock
|
54
|
-
expect(subject
|
54
|
+
expect(subject[:out].get).to eq(false)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -69,7 +69,7 @@ describe Circuits::Component::Nand do
|
|
69
69
|
it '= false' do
|
70
70
|
subject.tick
|
71
71
|
subject.tock
|
72
|
-
expect(subject
|
72
|
+
expect(subject[:out].get).to eq(false)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -79,7 +79,7 @@ describe Circuits::Component::Nand do
|
|
79
79
|
it '= true' do
|
80
80
|
subject.tick
|
81
81
|
subject.tock
|
82
|
-
expect(subject
|
82
|
+
expect(subject[:out].get).to eq(true)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -95,7 +95,7 @@ describe Circuits::Component::Nand do
|
|
95
95
|
it '= true' do
|
96
96
|
subject.tick
|
97
97
|
subject.tock
|
98
|
-
expect(subject
|
98
|
+
expect(subject[:out].get).to eq(true)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -7,8 +7,8 @@ describe Circuits::Component::Nor do
|
|
7
7
|
subject { Circuits::Component::Nor.new }
|
8
8
|
|
9
9
|
before do
|
10
|
-
subject
|
11
|
-
subject
|
10
|
+
subject[:a].set input_1
|
11
|
+
subject[:b].set input_2
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'false + false' do
|
@@ -18,7 +18,7 @@ describe Circuits::Component::Nor do
|
|
18
18
|
it '= true' do
|
19
19
|
subject.tick
|
20
20
|
subject.tock
|
21
|
-
expect(subject
|
21
|
+
expect(subject[:out].get).to eq(true)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -29,7 +29,7 @@ describe Circuits::Component::Nor do
|
|
29
29
|
it '= false' do
|
30
30
|
subject.tick
|
31
31
|
subject.tock
|
32
|
-
expect(subject
|
32
|
+
expect(subject[:out].get).to eq(false)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -40,7 +40,7 @@ describe Circuits::Component::Nor do
|
|
40
40
|
it '= false' do
|
41
41
|
subject.tick
|
42
42
|
subject.tock
|
43
|
-
expect(subject
|
43
|
+
expect(subject[:out].get).to eq(false)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -51,7 +51,7 @@ describe Circuits::Component::Nor do
|
|
51
51
|
it '= false' do
|
52
52
|
subject.tick
|
53
53
|
subject.tock
|
54
|
-
expect(subject
|
54
|
+
expect(subject[:out].get).to eq(false)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -69,7 +69,7 @@ describe Circuits::Component::Nor do
|
|
69
69
|
it '= false' do
|
70
70
|
subject.tick
|
71
71
|
subject.tock
|
72
|
-
expect(subject
|
72
|
+
expect(subject[:out].get).to eq(false)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -79,7 +79,7 @@ describe Circuits::Component::Nor do
|
|
79
79
|
it '= true' do
|
80
80
|
subject.tick
|
81
81
|
subject.tock
|
82
|
-
expect(subject
|
82
|
+
expect(subject[:out].get).to eq(true)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -95,7 +95,7 @@ describe Circuits::Component::Nor do
|
|
95
95
|
it '= false' do
|
96
96
|
subject.tick
|
97
97
|
subject.tock
|
98
|
-
expect(subject
|
98
|
+
expect(subject[:out].get).to eq(false)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -5,7 +5,7 @@ describe Circuits::Component::Not do
|
|
5
5
|
describe '#tick' do
|
6
6
|
subject { Circuits::Component::Not.new }
|
7
7
|
|
8
|
-
before { subject
|
8
|
+
before { subject[:in].set input }
|
9
9
|
|
10
10
|
context '!false' do
|
11
11
|
let(:input) { false }
|
@@ -13,7 +13,7 @@ describe Circuits::Component::Not do
|
|
13
13
|
it '= true' do
|
14
14
|
subject.tick
|
15
15
|
subject.tock
|
16
|
-
expect(subject
|
16
|
+
expect(subject[:out].get).to eq(true)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -23,7 +23,7 @@ describe Circuits::Component::Not do
|
|
23
23
|
it '= false' do
|
24
24
|
subject.tick
|
25
25
|
subject.tock
|
26
|
-
expect(subject
|
26
|
+
expect(subject[:out].get).to eq(false)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -7,8 +7,8 @@ describe Circuits::Component::Or do
|
|
7
7
|
subject { Circuits::Component::Or.new }
|
8
8
|
|
9
9
|
before do
|
10
|
-
subject
|
11
|
-
subject
|
10
|
+
subject[:a].set input_1
|
11
|
+
subject[:b].set input_2
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'false + false' do
|
@@ -18,7 +18,7 @@ describe Circuits::Component::Or do
|
|
18
18
|
it '= false' do
|
19
19
|
subject.tick
|
20
20
|
subject.tock
|
21
|
-
expect(subject
|
21
|
+
expect(subject[:out].get).to eq(false)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -29,7 +29,7 @@ describe Circuits::Component::Or do
|
|
29
29
|
it '= true' do
|
30
30
|
subject.tick
|
31
31
|
subject.tock
|
32
|
-
expect(subject
|
32
|
+
expect(subject[:out].get).to eq(true)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -40,7 +40,7 @@ describe Circuits::Component::Or do
|
|
40
40
|
it '= true' do
|
41
41
|
subject.tick
|
42
42
|
subject.tock
|
43
|
-
expect(subject
|
43
|
+
expect(subject[:out].get).to eq(true)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -51,7 +51,7 @@ describe Circuits::Component::Or do
|
|
51
51
|
it '= true' do
|
52
52
|
subject.tick
|
53
53
|
subject.tock
|
54
|
-
expect(subject
|
54
|
+
expect(subject[:out].get).to eq(true)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -69,7 +69,7 @@ describe Circuits::Component::Or do
|
|
69
69
|
it '= true' do
|
70
70
|
subject.tick
|
71
71
|
subject.tock
|
72
|
-
expect(subject
|
72
|
+
expect(subject[:out].get).to eq(true)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -79,7 +79,7 @@ describe Circuits::Component::Or do
|
|
79
79
|
it '= false' do
|
80
80
|
subject.tick
|
81
81
|
subject.tock
|
82
|
-
expect(subject
|
82
|
+
expect(subject[:out].get).to eq(false)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -95,7 +95,7 @@ describe Circuits::Component::Or do
|
|
95
95
|
it '= true' do
|
96
96
|
subject.tick
|
97
97
|
subject.tock
|
98
|
-
expect(subject
|
98
|
+
expect(subject[:out].get).to eq(true)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -7,61 +7,61 @@ describe Circuits::Component::SrNand do
|
|
7
7
|
|
8
8
|
context 'is set' do
|
9
9
|
before do
|
10
|
-
subject
|
11
|
-
subject
|
10
|
+
subject[:not_s].set false
|
11
|
+
subject[:not_r].set true
|
12
12
|
subject.tick
|
13
13
|
subject.tock
|
14
|
-
subject
|
14
|
+
subject[:not_s].set true
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'is set' do
|
18
|
-
expect(subject
|
19
|
-
expect(subject
|
18
|
+
expect(subject[:q].get).to eq(true)
|
19
|
+
expect(subject[:not_q].get).to eq(false)
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'is stable' do
|
23
23
|
subject.tick
|
24
24
|
subject.tock
|
25
|
-
expect(subject
|
26
|
-
expect(subject
|
25
|
+
expect(subject[:q].get).to eq(true)
|
26
|
+
expect(subject[:not_q].get).to eq(false)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'can be reset' do
|
30
|
-
subject
|
30
|
+
subject[:not_r].set false
|
31
31
|
subject.tick
|
32
32
|
subject.tock
|
33
|
-
expect(subject
|
34
|
-
expect(subject
|
33
|
+
expect(subject[:q].get).to eq(false)
|
34
|
+
expect(subject[:not_q].get).to eq(true)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
context 'is reset' do
|
39
39
|
before do
|
40
|
-
subject
|
41
|
-
subject
|
40
|
+
subject[:not_s].set true
|
41
|
+
subject[:not_r].set false
|
42
42
|
subject.tick
|
43
43
|
subject.tock
|
44
|
-
subject
|
44
|
+
subject[:not_r].set true
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'is reset' do
|
48
|
-
expect(subject
|
49
|
-
expect(subject
|
48
|
+
expect(subject[:q].get).to eq(false)
|
49
|
+
expect(subject[:not_q].get).to eq(true)
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'is stable' do
|
53
53
|
subject.tick
|
54
54
|
subject.tock
|
55
|
-
expect(subject
|
56
|
-
expect(subject
|
55
|
+
expect(subject[:q].get).to eq(false)
|
56
|
+
expect(subject[:not_q].get).to eq(true)
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'can be set' do
|
60
|
-
subject
|
60
|
+
subject[:not_s].set false
|
61
61
|
subject.tick
|
62
62
|
subject.tock
|
63
|
-
expect(subject
|
64
|
-
expect(subject
|
63
|
+
expect(subject[:q].get).to eq(true)
|
64
|
+
expect(subject[:not_q].get).to eq(false)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -7,61 +7,61 @@ describe Circuits::Component::SrNor do
|
|
7
7
|
|
8
8
|
context 'is set' do
|
9
9
|
before do
|
10
|
-
subject
|
11
|
-
subject
|
10
|
+
subject[:r].set false
|
11
|
+
subject[:s].set true
|
12
12
|
subject.tick
|
13
13
|
subject.tock
|
14
|
-
subject
|
14
|
+
subject[:s].set false
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'is set' do
|
18
|
-
expect(subject
|
19
|
-
expect(subject
|
18
|
+
expect(subject[:q].get).to eq(true)
|
19
|
+
expect(subject[:not_q].get).to eq(false)
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'is stable' do
|
23
23
|
subject.tick
|
24
24
|
subject.tock
|
25
|
-
expect(subject
|
26
|
-
expect(subject
|
25
|
+
expect(subject[:q].get).to eq(true)
|
26
|
+
expect(subject[:not_q].get).to eq(false)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'can be reset' do
|
30
|
-
subject
|
30
|
+
subject[:r].set true
|
31
31
|
subject.tick
|
32
32
|
subject.tock
|
33
|
-
expect(subject
|
34
|
-
expect(subject
|
33
|
+
expect(subject[:q].get).to eq(false)
|
34
|
+
expect(subject[:not_q].get).to eq(true)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
context 'is reset' do
|
39
39
|
before do
|
40
|
-
subject
|
41
|
-
subject
|
40
|
+
subject[:r].set true
|
41
|
+
subject[:s].set false
|
42
42
|
subject.tick
|
43
43
|
subject.tock
|
44
|
-
subject
|
44
|
+
subject[:r].set false
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'is reset' do
|
48
|
-
expect(subject
|
49
|
-
expect(subject
|
48
|
+
expect(subject[:q].get).to eq(false)
|
49
|
+
expect(subject[:not_q].get).to eq(true)
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'is stable' do
|
53
53
|
subject.tick
|
54
54
|
subject.tock
|
55
|
-
expect(subject
|
56
|
-
expect(subject
|
55
|
+
expect(subject[:q].get).to eq(false)
|
56
|
+
expect(subject[:not_q].get).to eq(true)
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'can be set' do
|
60
|
-
subject
|
60
|
+
subject[:s].set true
|
61
61
|
subject.tick
|
62
62
|
subject.tock
|
63
|
-
expect(subject
|
64
|
-
expect(subject
|
63
|
+
expect(subject[:q].get).to eq(true)
|
64
|
+
expect(subject[:not_q].get).to eq(false)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -7,8 +7,8 @@ describe Circuits::Component::Xnor do
|
|
7
7
|
subject { Circuits::Component::Xnor.new }
|
8
8
|
|
9
9
|
before do
|
10
|
-
subject
|
11
|
-
subject
|
10
|
+
subject[:a].set input_1
|
11
|
+
subject[:b].set input_2
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'false + false' do
|
@@ -18,7 +18,7 @@ describe Circuits::Component::Xnor do
|
|
18
18
|
it '= true' do
|
19
19
|
subject.tick
|
20
20
|
subject.tock
|
21
|
-
expect(subject
|
21
|
+
expect(subject[:out].get).to eq(true)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -29,7 +29,7 @@ describe Circuits::Component::Xnor do
|
|
29
29
|
it '= false' do
|
30
30
|
subject.tick
|
31
31
|
subject.tock
|
32
|
-
expect(subject
|
32
|
+
expect(subject[:out].get).to eq(false)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -40,7 +40,7 @@ describe Circuits::Component::Xnor do
|
|
40
40
|
it '= false' do
|
41
41
|
subject.tick
|
42
42
|
subject.tock
|
43
|
-
expect(subject
|
43
|
+
expect(subject[:out].get).to eq(false)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -51,7 +51,7 @@ describe Circuits::Component::Xnor do
|
|
51
51
|
it '= true' do
|
52
52
|
subject.tick
|
53
53
|
subject.tock
|
54
|
-
expect(subject
|
54
|
+
expect(subject[:out].get).to eq(true)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -70,7 +70,7 @@ describe Circuits::Component::Xnor do
|
|
70
70
|
it '= true' do
|
71
71
|
subject.tick
|
72
72
|
subject.tock
|
73
|
-
expect(subject
|
73
|
+
expect(subject[:out].get).to eq(true)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -80,7 +80,7 @@ describe Circuits::Component::Xnor do
|
|
80
80
|
it '= true' do
|
81
81
|
subject.tick
|
82
82
|
subject.tock
|
83
|
-
expect(subject
|
83
|
+
expect(subject[:out].get).to eq(true)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -96,7 +96,7 @@ describe Circuits::Component::Xnor do
|
|
96
96
|
it '= false' do
|
97
97
|
subject.tick
|
98
98
|
subject.tock
|
99
|
-
expect(subject
|
99
|
+
expect(subject[:out].get).to eq(false)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -119,7 +119,7 @@ describe Circuits::Component::Xnor do
|
|
119
119
|
it '= false' do
|
120
120
|
subject.tick
|
121
121
|
subject.tock
|
122
|
-
expect(subject
|
122
|
+
expect(subject[:out].get).to eq(false)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -129,7 +129,7 @@ describe Circuits::Component::Xnor do
|
|
129
129
|
it '= true' do
|
130
130
|
subject.tick
|
131
131
|
subject.tock
|
132
|
-
expect(subject
|
132
|
+
expect(subject[:out].get).to eq(true)
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
@@ -145,7 +145,7 @@ describe Circuits::Component::Xnor do
|
|
145
145
|
it '= true' do
|
146
146
|
subject.tick
|
147
147
|
subject.tock
|
148
|
-
expect(subject
|
148
|
+
expect(subject[:out].get).to eq(true)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
@@ -163,7 +163,7 @@ describe Circuits::Component::Xnor do
|
|
163
163
|
it '= false' do
|
164
164
|
subject.tick
|
165
165
|
subject.tock
|
166
|
-
expect(subject
|
166
|
+
expect(subject[:out].get).to eq(false)
|
167
167
|
end
|
168
168
|
end
|
169
169
|
end
|
@@ -7,8 +7,8 @@ describe Circuits::Component::Xor do
|
|
7
7
|
subject { Circuits::Component::Xor.new }
|
8
8
|
|
9
9
|
before do
|
10
|
-
subject
|
11
|
-
subject
|
10
|
+
subject[:a].set input_1
|
11
|
+
subject[:b].set input_2
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'false + false' do
|
@@ -18,7 +18,7 @@ describe Circuits::Component::Xor do
|
|
18
18
|
it '= false' do
|
19
19
|
subject.tick
|
20
20
|
subject.tock
|
21
|
-
expect(subject
|
21
|
+
expect(subject[:out].get).to eq(false)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -29,7 +29,7 @@ describe Circuits::Component::Xor do
|
|
29
29
|
it '= true' do
|
30
30
|
subject.tick
|
31
31
|
subject.tock
|
32
|
-
expect(subject
|
32
|
+
expect(subject[:out].get).to eq(true)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -40,7 +40,7 @@ describe Circuits::Component::Xor do
|
|
40
40
|
it '= true' do
|
41
41
|
subject.tick
|
42
42
|
subject.tock
|
43
|
-
expect(subject
|
43
|
+
expect(subject[:out].get).to eq(true)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -51,7 +51,7 @@ describe Circuits::Component::Xor do
|
|
51
51
|
it '= false' do
|
52
52
|
subject.tick
|
53
53
|
subject.tock
|
54
|
-
expect(subject
|
54
|
+
expect(subject[:out].get).to eq(false)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -70,7 +70,7 @@ describe Circuits::Component::Xor do
|
|
70
70
|
it '= false' do
|
71
71
|
subject.tick
|
72
72
|
subject.tock
|
73
|
-
expect(subject
|
73
|
+
expect(subject[:out].get).to eq(false)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -80,7 +80,7 @@ describe Circuits::Component::Xor do
|
|
80
80
|
it '= false' do
|
81
81
|
subject.tick
|
82
82
|
subject.tock
|
83
|
-
expect(subject
|
83
|
+
expect(subject[:out].get).to eq(false)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -96,7 +96,7 @@ describe Circuits::Component::Xor do
|
|
96
96
|
it '= true' do
|
97
97
|
subject.tick
|
98
98
|
subject.tock
|
99
|
-
expect(subject
|
99
|
+
expect(subject[:out].get).to eq(true)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -119,7 +119,7 @@ describe Circuits::Component::Xor do
|
|
119
119
|
it '= true' do
|
120
120
|
subject.tick
|
121
121
|
subject.tock
|
122
|
-
expect(subject
|
122
|
+
expect(subject[:out].get).to eq(true)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -129,7 +129,7 @@ describe Circuits::Component::Xor do
|
|
129
129
|
it '= false' do
|
130
130
|
subject.tick
|
131
131
|
subject.tock
|
132
|
-
expect(subject
|
132
|
+
expect(subject[:out].get).to eq(false)
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
@@ -145,7 +145,7 @@ describe Circuits::Component::Xor do
|
|
145
145
|
it '= false' do
|
146
146
|
subject.tick
|
147
147
|
subject.tock
|
148
|
-
expect(subject
|
148
|
+
expect(subject[:out].get).to eq(false)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
@@ -163,7 +163,7 @@ describe Circuits::Component::Xor do
|
|
163
163
|
it '= true' do
|
164
164
|
subject.tick
|
165
165
|
subject.tock
|
166
|
-
expect(subject
|
166
|
+
expect(subject[:out].get).to eq(true)
|
167
167
|
end
|
168
168
|
end
|
169
169
|
end
|
@@ -2,73 +2,113 @@ require 'spec_helper'
|
|
2
2
|
require 'circuits/component'
|
3
3
|
|
4
4
|
# Mock component to include Circuits::Component for function accessability
|
5
|
-
class
|
5
|
+
class MockComponent1
|
6
6
|
include Circuits::Component
|
7
7
|
|
8
|
-
def
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
def mock_input_count
|
13
|
-
input_count
|
14
|
-
end
|
15
|
-
|
16
|
-
def mock_output_count
|
17
|
-
output_count
|
8
|
+
def set_defaults
|
9
|
+
@input_count = 1
|
10
|
+
@output_count = 1
|
18
11
|
end
|
12
|
+
end
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
# Mock component to include Circuits::Component for function accessability
|
15
|
+
class MockComponent2
|
16
|
+
include Circuits::Component
|
23
17
|
end
|
24
18
|
|
25
19
|
describe Circuits::Component do
|
26
|
-
|
20
|
+
context 'when using defaults' do
|
21
|
+
subject { MockComponent1.new }
|
27
22
|
|
28
|
-
|
23
|
+
it 'has one input' do
|
24
|
+
expect(subject.inputs.count).to eq(1)
|
25
|
+
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
expect { subject.mock_input_count }.to raise_error(NotImplementedError)
|
27
|
+
it 'has one output' do
|
28
|
+
expect(subject.outputs.count).to eq(1)
|
33
29
|
end
|
34
|
-
end
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
describe '#[]=' do
|
32
|
+
let(:new_input) { double('new_input') }
|
33
|
+
let(:new_output) { double('new_output') }
|
34
|
+
|
35
|
+
before do
|
36
|
+
subject[:in] = new_input
|
37
|
+
subject[:out] = new_output
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'has the new input available as :in' do
|
41
|
+
expect(subject[:in]).to eq(new_input)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'has the new output available as :out' do
|
45
|
+
expect(subject[:out]).to eq(new_output)
|
46
|
+
end
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
42
|
-
|
43
|
-
|
44
|
-
|
50
|
+
context 'when specifying input and output count' do
|
51
|
+
subject { MockComponent1.new(inputs: 2, outputs: 2) }
|
52
|
+
|
53
|
+
it 'has one input' do
|
54
|
+
expect(subject.inputs.count).to eq(2)
|
45
55
|
end
|
46
|
-
end
|
47
56
|
|
48
|
-
|
49
|
-
|
50
|
-
expect(outputs[0]).to receive(:tock)
|
51
|
-
subject.tock
|
57
|
+
it 'has one output' do
|
58
|
+
expect(subject.outputs.count).to eq(2)
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
55
|
-
|
56
|
-
|
57
|
-
|
62
|
+
context 'when supplying inputs and outputs' do
|
63
|
+
let(:inputs) { [double('input')] }
|
64
|
+
let(:outputs) { [double('output')] }
|
65
|
+
|
66
|
+
subject { MockComponent1.new(inputs: inputs, outputs: outputs) }
|
67
|
+
|
68
|
+
describe '#tick' do
|
69
|
+
it 'raises NotImplementedError' do
|
70
|
+
expect { subject.tick }.to raise_error(NotImplementedError)
|
71
|
+
end
|
58
72
|
end
|
59
73
|
|
60
|
-
|
61
|
-
it '
|
62
|
-
expect
|
74
|
+
describe '#tock' do
|
75
|
+
it 'tocks the outputs' do
|
76
|
+
expect(outputs[0]).to receive(:tock)
|
77
|
+
subject.tock
|
63
78
|
end
|
64
79
|
end
|
65
80
|
|
66
|
-
|
67
|
-
|
68
|
-
it
|
69
|
-
expect(subject
|
81
|
+
describe '#[]' do
|
82
|
+
context 'one input and one output' do
|
83
|
+
it 'has the input available as :in' do
|
84
|
+
expect(subject[:in]).to eq(inputs[0])
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'has the output available as :out' do
|
88
|
+
expect(subject[:out]).to eq(outputs[0])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'two inputs and two outputs' do
|
93
|
+
let(:inputs) { [double('input_1'), double('input_2')] }
|
94
|
+
let(:outputs) { [double('output_1'), double('output_2')] }
|
95
|
+
|
96
|
+
it 'has the inputs available as :a and :b' do
|
97
|
+
expect(subject[:a]).to eq(inputs[0])
|
98
|
+
expect(subject[:b]).to eq(inputs[1])
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'has the outputs available as :c and :d' do
|
102
|
+
expect(subject[:c]).to eq(outputs[0])
|
103
|
+
expect(subject[:d]).to eq(outputs[1])
|
70
104
|
end
|
71
105
|
end
|
72
106
|
end
|
73
107
|
end
|
108
|
+
|
109
|
+
context 'when you do not override #set_defaults' do
|
110
|
+
it 'raises NotImplementedError' do
|
111
|
+
expect { MockComponent2.new }.to raise_error(NotImplementedError)
|
112
|
+
end
|
113
|
+
end
|
74
114
|
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.4.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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|