circuits 0.2.2 → 0.2.3
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/lib/circuits/component/sr_nand.rb +39 -0
- data/lib/circuits/version.rb +1 -1
- data/lib/circuits.rb +1 -0
- data/spec/unit/circuits/component/sr_nand_spec.rb +68 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmU5NjYyNWJiYjYyMzY4ZmI5ZWIxMjk5MzU2NDM5N2JmOTNmZDNkZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDcwMTg3NmJhZmE4OGY3ZDM4YWZlYjAwZWRhYzRlZmYwZWNlNzZhZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDgxYTQ4MGY0M2EyNTU1YzA2ZTllNDBhYjkyN2Q1MzFhNjg5YWNhOWYwYjVm
|
10
|
+
MmM0MTdiNjA4OTIzMmRlNTkwMDg0YmI3NjExMzQ4ZDc0YTQwMGVlYzBhNTM5
|
11
|
+
MmRjNmRkMTdjYmUyNzc1NWVkMjg1ZDUyMTE1MjlmNzg4YjQyNGI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGE1MDEzZWRiOTRjMWIzMWRkNjg0MTJmNzA4M2JjNDRiZjVhMzQ3MzcxMWNk
|
14
|
+
Mzg0M2JjZGNiZDgzYWFiOWE0ODY1NDA2ZDViODc5MmExZmQxMzAxMTI5NzA3
|
15
|
+
Mzk3Mzk0MDliZTQ2NmIwM2M5YTYwMDFkM2I5ODgxYzE2YTI2ODk=
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'circuits/component'
|
2
|
+
|
3
|
+
module Circuits
|
4
|
+
module Component
|
5
|
+
# SR NAND Latch
|
6
|
+
class SrNand
|
7
|
+
include Component
|
8
|
+
|
9
|
+
def input_count
|
10
|
+
2
|
11
|
+
end
|
12
|
+
|
13
|
+
def output_count
|
14
|
+
2
|
15
|
+
end
|
16
|
+
|
17
|
+
def tick
|
18
|
+
2.times.each do
|
19
|
+
sub_components.each(&:tick)
|
20
|
+
sub_components.each(&:tock)
|
21
|
+
end
|
22
|
+
outputs[0].set nor_1.outputs[0].get
|
23
|
+
outputs[1].set nor_2.outputs[0].get
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :nor_1, :nor_2, :sub_components
|
29
|
+
|
30
|
+
def setup
|
31
|
+
@nor_1 = Nand.new(inputs: [inputs[0]])
|
32
|
+
@nor_2 = Nand.new(inputs: [inputs[1]])
|
33
|
+
@sub_components = [@nor_1, @nor_2]
|
34
|
+
nor_1.inputs << nor_2.outputs[0]
|
35
|
+
nor_2.inputs << nor_1.outputs[0]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/circuits/version.rb
CHANGED
data/lib/circuits.rb
CHANGED
@@ -3,6 +3,7 @@ require 'circuits/component/nand'
|
|
3
3
|
require 'circuits/component/nor'
|
4
4
|
require 'circuits/component/not'
|
5
5
|
require 'circuits/component/or'
|
6
|
+
require 'circuits/component/sr_nand'
|
6
7
|
require 'circuits/component/sr_nor'
|
7
8
|
require 'circuits/component/xnor'
|
8
9
|
require 'circuits/component/xor'
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'circuits/component/sr_nand'
|
3
|
+
|
4
|
+
describe Circuits::Component::SrNand do
|
5
|
+
describe '#tick' do
|
6
|
+
subject { Circuits::Component::SrNand.new }
|
7
|
+
|
8
|
+
context 'is set' do
|
9
|
+
before do
|
10
|
+
subject.inputs[0].set false
|
11
|
+
subject.inputs[1].set true
|
12
|
+
subject.tick
|
13
|
+
subject.tock
|
14
|
+
subject.inputs[0].set true
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'is set' do
|
18
|
+
expect(subject.outputs[0].get).to eq(true)
|
19
|
+
expect(subject.outputs[1].get).to eq(false)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'is stable' do
|
23
|
+
subject.tick
|
24
|
+
subject.tock
|
25
|
+
expect(subject.outputs[0].get).to eq(true)
|
26
|
+
expect(subject.outputs[1].get).to eq(false)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can be reset' do
|
30
|
+
subject.inputs[1].set false
|
31
|
+
subject.tick
|
32
|
+
subject.tock
|
33
|
+
expect(subject.outputs[0].get).to eq(false)
|
34
|
+
expect(subject.outputs[1].get).to eq(true)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'is reset' do
|
39
|
+
before do
|
40
|
+
subject.inputs[0].set true
|
41
|
+
subject.inputs[1].set false
|
42
|
+
subject.tick
|
43
|
+
subject.tock
|
44
|
+
subject.inputs[1].set true
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'is reset' do
|
48
|
+
expect(subject.outputs[0].get).to eq(false)
|
49
|
+
expect(subject.outputs[1].get).to eq(true)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'is stable' do
|
53
|
+
subject.tick
|
54
|
+
subject.tock
|
55
|
+
expect(subject.outputs[0].get).to eq(false)
|
56
|
+
expect(subject.outputs[1].get).to eq(true)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'can be set' do
|
60
|
+
subject.inputs[0].set false
|
61
|
+
subject.tick
|
62
|
+
subject.tock
|
63
|
+
expect(subject.outputs[0].get).to eq(true)
|
64
|
+
expect(subject.outputs[1].get).to eq(false)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circuits
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henry Muru Paenga
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- lib/circuits/component/nor.rb
|
89
89
|
- lib/circuits/component/not.rb
|
90
90
|
- lib/circuits/component/or.rb
|
91
|
+
- lib/circuits/component/sr_nand.rb
|
91
92
|
- lib/circuits/component/sr_nor.rb
|
92
93
|
- lib/circuits/component/xnor.rb
|
93
94
|
- lib/circuits/component/xor.rb
|
@@ -100,6 +101,7 @@ files:
|
|
100
101
|
- spec/unit/circuits/component/nor_spec.rb
|
101
102
|
- spec/unit/circuits/component/not_spec.rb
|
102
103
|
- spec/unit/circuits/component/or_spec.rb
|
104
|
+
- spec/unit/circuits/component/sr_nand_spec.rb
|
103
105
|
- spec/unit/circuits/component/sr_nor_spec.rb
|
104
106
|
- spec/unit/circuits/component/xnor_spec.rb
|
105
107
|
- spec/unit/circuits/component/xor_spec.rb
|
@@ -137,6 +139,7 @@ test_files:
|
|
137
139
|
- spec/unit/circuits/component/nor_spec.rb
|
138
140
|
- spec/unit/circuits/component/not_spec.rb
|
139
141
|
- spec/unit/circuits/component/or_spec.rb
|
142
|
+
- spec/unit/circuits/component/sr_nand_spec.rb
|
140
143
|
- spec/unit/circuits/component/sr_nor_spec.rb
|
141
144
|
- spec/unit/circuits/component/xnor_spec.rb
|
142
145
|
- spec/unit/circuits/component/xor_spec.rb
|