circuits 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWM4NjAyMGY2NDY2OTEwYmUyOTIzNmRmZDJjODJiMGVhYWEyMjJiNQ==
4
+ NGUwZTZhZWY5NmMwMGM2MmEwMDJmNWU3YTgzZjAwMjFjOWRlODA2MA==
5
5
  data.tar.gz: !binary |-
6
- MmM5NTg0ZjU1ZGNiNjM4MjU2OGQ5ZWY0ZmVlZTVhNWZmYTE5YTkzMg==
6
+ MDNjMDhjODE2YjE5NWViNmMxMGE1OWQzNDlmZTk0MGQ5NWZlNjNhZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmJkOTU1ODU4Zjg0OTFkZTdiZWQzMmMxNTYxZWM3ZjY0Yzk5NzA1N2M5Mjk1
10
- YjcxMmM3ZDZmNmRhZDFiYjFlMzBjN2E3NWE2YjhkMjI1MDk1Nzc4Y2FkZTc5
11
- NWI1YzBkMWU4YTFmNTkxNTEzZTlmY2ZhODNhYTY0MzQ4MWFkY2U=
9
+ MjhiZWFiYzE1NGY0MGY1NjgxNjVlNWFkNjJlNjY0NzA1ZTgwYTFjZmU0Y2I2
10
+ OTJjNmI2MTAxYzE4MmMwNjJmMDExZmEzMjg3ZTU3YTM2NDg2MTA5OTRiMmUx
11
+ OGM3MDYwMTVmOTgwNjlkODI5ZTFlNDc5MDdlN2UyNWE5MTMwY2U=
12
12
  data.tar.gz: !binary |-
13
- ZDMyN2E2MzI4ZjhhZjI4MzQ3OGZkNjllNjYxNDljNjBlNWY3MjdiNDQ3M2Fi
14
- NmM3OThkZGMxNjhjMTBiZjBhOTA2OWVkZjNiODhhOWRiNzlkMzE2N2VjYjkz
15
- ZGU0NGY5MmI5ZTE2NWZkYjcyOWI5ZDdlZDg5YTg3OTA2ZDNmODg=
13
+ YzBiODA1NWYyY2U4OGY0MTA4MTM5Y2MxZGZkYzk3YTE3N2M1ZTFlNzExM2Mx
14
+ YjY4Mjk4MTZjNWQxNzVmZjUyMDNiZTc3M2Y3NzRjZDZlY2ZhZDQ2NzZiYjBk
15
+ NTZmZjE1Y2YzOTY0MjU3Y2ZhOTllOWI5ODUwM2YwYTAwOGQ2MGU=
@@ -3,7 +3,7 @@ require 'circuits/component/nand'
3
3
 
4
4
  module Circuits
5
5
  module Component
6
- # Positive edge triggered flip flop
6
+ # Positive edge triggered D-type flip flop
7
7
  class D < Base
8
8
  def initialize
9
9
  super(port_mappings: { d: { type: :input, number: 0 },
@@ -12,6 +12,7 @@ module Circuits
12
12
  not_q: { type: :output, number: 1 } })
13
13
  create_sub_components
14
14
  link_sub_components
15
+ reset
15
16
  end
16
17
 
17
18
  # Computes the outputs based on the inputs and previous state
@@ -75,6 +76,11 @@ module Circuits
75
76
  link_sr_nand_clk
76
77
  link_sr_nand_out
77
78
  end
79
+
80
+ def reset
81
+ tick
82
+ tock
83
+ end
78
84
  end
79
85
  end
80
86
  end
@@ -11,9 +11,8 @@ module Circuits
11
11
  q: { type: :output, number: 0 },
12
12
  not_q: { type: :output, number: 1 } })
13
13
  create_sub_components
14
- link_inputs
15
- link_outputs
16
14
  link_sub_components
15
+ reset
17
16
  end
18
17
 
19
18
  # Computes the outputs based on the inputs and previous state
@@ -42,9 +41,14 @@ module Circuits
42
41
  2
43
42
  end
44
43
 
45
- def link_inputs
46
- nand_s[:a].set self[:not_s]
44
+ def link_nand_r
47
45
  nand_r[:a].set self[:not_r]
46
+ nand_r[:b].set nand_s[:out]
47
+ end
48
+
49
+ def link_nand_s
50
+ nand_s[:a].set self[:not_s]
51
+ nand_s[:b].set nand_r[:out]
48
52
  end
49
53
 
50
54
  def link_outputs
@@ -53,8 +57,16 @@ module Circuits
53
57
  end
54
58
 
55
59
  def link_sub_components
56
- nand_s[:b].set nand_r[:out]
57
- nand_r[:b].set nand_s[:out]
60
+ link_nand_s
61
+ link_nand_r
62
+ link_outputs
63
+ end
64
+
65
+ def reset
66
+ self[:not_s].set true
67
+ tick
68
+ tock
69
+ self[:not_r].set true
58
70
  end
59
71
  end
60
72
  end
@@ -11,9 +11,8 @@ module Circuits
11
11
  q: { type: :output, number: 0 },
12
12
  not_q: { type: :output, number: 1 } })
13
13
  create_sub_components
14
- link_inputs
15
- link_outputs
16
14
  link_sub_components
15
+ reset
17
16
  end
18
17
 
19
18
  # Computes the outputs based on the inputs and previous state
@@ -42,9 +41,14 @@ module Circuits
42
41
  2
43
42
  end
44
43
 
45
- def link_inputs
44
+ def link_nor_r
46
45
  nor_r[:a].set self[:r]
46
+ nor_r[:b].set nor_s[:out]
47
+ end
48
+
49
+ def link_nor_s
47
50
  nor_s[:a].set self[:s]
51
+ nor_s[:b].set nor_r[:out]
48
52
  end
49
53
 
50
54
  def link_outputs
@@ -53,8 +57,16 @@ module Circuits
53
57
  end
54
58
 
55
59
  def link_sub_components
56
- nor_r[:b].set nor_s[:out]
57
- nor_s[:b].set nor_r[:out]
60
+ link_nor_s
61
+ link_nor_r
62
+ link_outputs
63
+ end
64
+
65
+ def reset
66
+ self[:r].set true
67
+ tick
68
+ tock
69
+ self[:r].set false
58
70
  end
59
71
  end
60
72
  end
@@ -1,5 +1,5 @@
1
1
  # Circuits allows you to express logical circuits in code
2
2
  module Circuits
3
3
  # The version of the Circuits gem
4
- VERSION = '0.9.1'
4
+ VERSION = '0.9.2'
5
5
  end
@@ -5,6 +5,20 @@ describe Circuits::Component::D do
5
5
  describe '#tick' do
6
6
  subject { Circuits::Component::D.new }
7
7
 
8
+ context 'it has just been initialized' do
9
+ it 'is unset' do
10
+ expect(subject[:q].get).to eq(false)
11
+ expect(subject[:not_q].get).to eq(true)
12
+ end
13
+
14
+ it 'is stable' do
15
+ subject.tick
16
+ subject.tock
17
+ expect(subject[:q].get).to eq(false)
18
+ expect(subject[:not_q].get).to eq(true)
19
+ end
20
+ end
21
+
8
22
  context 'has just been set' do
9
23
  before do
10
24
  subject[:clk].set false
@@ -5,6 +5,20 @@ describe Circuits::Component::SrNand do
5
5
  describe '#tick' do
6
6
  subject { Circuits::Component::SrNand.new }
7
7
 
8
+ context 'it has just been initialized' do
9
+ it 'is unset' do
10
+ expect(subject[:q].get).to eq(false)
11
+ expect(subject[:not_q].get).to eq(true)
12
+ end
13
+
14
+ it 'is stable' do
15
+ subject.tick
16
+ subject.tock
17
+ expect(subject[:q].get).to eq(false)
18
+ expect(subject[:not_q].get).to eq(true)
19
+ end
20
+ end
21
+
8
22
  context 'is set' do
9
23
  before do
10
24
  subject[:not_s].set false
@@ -5,6 +5,20 @@ describe Circuits::Component::SrNor do
5
5
  describe '#tick' do
6
6
  subject { Circuits::Component::SrNor.new }
7
7
 
8
+ context 'it has just been initialized' do
9
+ it 'is unset' do
10
+ expect(subject[:q].get).to eq(false)
11
+ expect(subject[:not_q].get).to eq(true)
12
+ end
13
+
14
+ it 'is stable' do
15
+ subject.tick
16
+ subject.tock
17
+ expect(subject[:q].get).to eq(false)
18
+ expect(subject[:not_q].get).to eq(true)
19
+ end
20
+ end
21
+
8
22
  context 'is set' do
9
23
  before do
10
24
  subject[:r].set false
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.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Muru Paenga