fsfifo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1873cb49b135d37167ccf99dee689680af2db32e
4
- data.tar.gz: 7f444b3acba163fcaf2a559c715531829bc36cc6
3
+ metadata.gz: b9dc3e26674507e180ce5280b2aa6c31c1db4e14
4
+ data.tar.gz: 45da0f1bae15b7929970b23d836ace16c2a1913c
5
5
  SHA512:
6
- metadata.gz: c392f2a447179efda3885bef1599ba26826890fc5a326f000bfec3b46f96f3c0126312d23a78610e5562b8c3a3c4d08cccdee3b7f38ad10148609d67a0770cdb
7
- data.tar.gz: f05d3151607942b4fceb4638e91200813140182ac67d8976fa672d3defe7ed0ec84d6b45e45fc1a88f8a1edfddb3e6c2f3dff6ae2e04d29735f6ed62a5e48109
6
+ metadata.gz: bd1a6df5f7946b5e8f6008212c980f22cefbb23909688a5b8458c5e0edd21ea2561d773eca5c650bd601b0fe5301f86ad70d36b724e602fd696b61289dd1e4b0
7
+ data.tar.gz: ffcd0b4dd87d295e8e2ced48d7743eec75d862765b1f4bac3dffb6f50afbdf57e4a5e171d095f53c3721d097a59ed89e3c9e98a649877c26248e031955648b64
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/fsfifo.gemspec ADDED
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "fsfifo"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["YAMAMOTO, Masayuki"]
12
+ s.date = "2013-07-31"
13
+ s.description = "Fixed size FIFO, LIFO, and Array."
14
+ s.email = "martin.route66.blues+github@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ "Gemfile",
21
+ "LICENSE.txt",
22
+ "Rakefile",
23
+ "ReadMe.md",
24
+ "VERSION",
25
+ "lib/fsfifo.rb",
26
+ "test/helper.rb",
27
+ "test/test_fsfifo.rb"
28
+ ]
29
+ s.homepage = "http://github.com/mephistobooks/fsfifo"
30
+ s.licenses = ["MIT"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = "2.0.6"
33
+ s.summary = "Fixed size FIFO."
34
+
35
+ if s.respond_to? :specification_version then
36
+ s.specification_version = 4
37
+
38
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
39
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
40
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
41
+ s.add_development_dependency(%q<bundler>, ["~> 1.3.5"])
42
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
43
+ s.add_development_dependency(%q<simplecov-rcov>, [">= 0"])
44
+ else
45
+ s.add_dependency(%q<shoulda>, [">= 0"])
46
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
47
+ s.add_dependency(%q<bundler>, ["~> 1.3.5"])
48
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
49
+ s.add_dependency(%q<simplecov-rcov>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
54
+ s.add_dependency(%q<bundler>, ["~> 1.3.5"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
56
+ s.add_dependency(%q<simplecov-rcov>, [">= 0"])
57
+ end
58
+ end
59
+
data/lib/fsfifo.rb CHANGED
@@ -10,28 +10,36 @@
10
10
  #
11
11
  class FSArray < Array
12
12
 
13
+ FSARRAY_SIZE_DEFAULT = 1
13
14
  #
14
15
  # FSArray#new( n )
15
- # FSArray#new( size: n, of_enbl: true, of_proc: Proc.new{...} )
16
+ # FSArray#new( size: n, of_enable: true, of_proc: Proc.new{...} )
16
17
  #
17
- def initialize( args = {} )
18
-
19
- if args.class == Fixnum
20
- args = { size: args, wm_size: args }
21
- end
22
-
18
+ def initialize( _size = FSARRAY_SIZE_DEFAULT,
19
+ size: FSARRAY_SIZE_DEFAULT,
20
+ of_enable: false, of_proc: Proc.new{ raise "Overflow!" },
21
+ uf_enable: false, uf_proc: Proc.new{ raise "Underflow!" },
22
+ push_enable: false, push_proc: Proc.new{},
23
+ wm_size: 1,
24
+ wm_enable: false, wm_proc: Proc.new{ raise "Reached WM!" }
25
+ )
26
+
27
+ raise "Watermark #{wm_size} is out of range[0,#{size}]" if
28
+ wm_size < 0 or wm_size > size
29
+
30
+ size = _size if _size != FSARRAY_SIZE_DEFAULT
23
31
  @opt = {
24
- :size => 1,
25
- :of_enbl => false,
26
- :of_proc => Proc.new{},
27
- :uf_enbl => false,
28
- :uf_proc => Proc.new{},
29
- :push_enbl => false, #TODO.
30
- :push_proc => Proc.new{},
31
- :wm_size => 1,
32
- :wm_enbl => false,
33
- :wm_proc => Proc.new{},
34
- }.merge( args )
32
+ :size => size,
33
+ :of_enable => of_enable,
34
+ :of_proc => of_proc,
35
+ :uf_enable => uf_enable,
36
+ :uf_proc => uf_proc,
37
+ :push_enable => push_enable, #TODO.
38
+ :push_proc => push_proc,
39
+ :wm_size => wm_size,
40
+ :wm_enable => wm_enable,
41
+ :wm_proc => wm_proc,
42
+ }
35
43
 
36
44
  @shifted = nil #TODO.
37
45
 
@@ -41,19 +49,15 @@ class FSArray < Array
41
49
  end
42
50
 
43
51
  #
44
- # Over/underflow callback methods getter/setter, etc.
52
+ # Over/Underflow callback methods getter/setter, etc.
45
53
  #
46
- def of_proc; @opt[:of_proc]; end
47
- def of_proc=( newp ); @opt[:of_proc] = newp; end
48
- def of_enable; @opt[:of_enbl] = true; end
49
- def of_disable; @opt[:of_enbl] = false; end
50
- def of_enable?; @opt[:of_enbl] ; end
51
-
52
- def uf_proc; @opt[:uf_proc]; end
53
- def uf_proc=( newp ); @opt[:uf_proc] = newp; end
54
- def uf_enable; @opt[:uf_enbl] = true; end
55
- def uf_disable; @opt[:uf_enbl] = false; end
56
- def uf_enable?; @opt[:uf_enbl] ; end
54
+ ["o", "u"].each{|which|
55
+ eval("def #{which}f_proc; @opt[:#{which}f_proc]; end")
56
+ eval("def #{which}f_proc=(newp); @opt[:#{which}f_proc] = newp; end")
57
+ eval("def #{which}f_enable?; @opt[:#{which}f_enable]; end")
58
+ eval("def #{which}f_enable; @opt[:#{which}f_enable] = true; end")
59
+ eval("def #{which}f_disable; @opt[:#{which}f_enable] = false; end")
60
+ }
57
61
 
58
62
  #
59
63
  # FIFO and data size-related methods.
@@ -77,14 +81,11 @@ class FSArray < Array
77
81
  # shift and push - main methods of FSFIFO.
78
82
  #
79
83
  def shift
80
- ret = shift_org
81
84
 
82
85
  # callback method when under flow is enabled.
83
- if self.size == 0
84
- if @opt[:uf_enbl]
85
- @opt[:uf_proc].call
86
- end
87
- end
86
+ @opt[:uf_proc].call if self.size == 0 and @opt[:uf_enable]
87
+
88
+ ret = shift_org
88
89
 
89
90
  return ret
90
91
  end
@@ -93,7 +94,7 @@ class FSArray < Array
93
94
 
94
95
  #
95
96
  push_org( obj )
96
-
97
+
97
98
  #
98
99
  of_called = false
99
100
  wm_called = false
@@ -102,13 +103,13 @@ class FSArray < Array
102
103
  shift_org
103
104
 
104
105
  # overflow callback.
105
- if @opt[:of_enbl] and not(of_called)
106
+ if @opt[:of_enable] and not(of_called)
106
107
  @opt[:of_proc].call
107
108
  of_called = true
108
109
  end
109
110
 
110
111
  # TODO.watermark callback.
111
- if @opt[:wm_enbl] and not(wm_called)
112
+ if @opt[:wm_enable] and not(wm_called)
112
113
  @opt[:wm_proc].call
113
114
  wm_called = true
114
115
  else
data/test/test_fsfifo.rb CHANGED
@@ -4,9 +4,6 @@
4
4
  #
5
5
 
6
6
  # Unit Test Lib.
7
- #require "rubygems"
8
- #gem "test-unit"
9
- #require "test/unit"
10
7
  require 'helper'
11
8
  require 'test/unit'
12
9
 
@@ -26,8 +23,8 @@ class TestFSArray < Test::Unit::TestCase
26
23
  @of_proc_called = false
27
24
  @uf_proc_called = false
28
25
 
29
- @fifo.of_proc = Proc.new { p "of called."; @of_proc_called ^= true }
30
- @fifo.uf_proc = Proc.new { p "uf called."; @uf_proc_called ^= true }
26
+ @fifo.of_proc = Proc.new { p "of called."; @of_proc_called = true }
27
+ @fifo.uf_proc = Proc.new { p "uf called."; @uf_proc_called = true }
31
28
  end
32
29
 
33
30
  def teardown
@@ -42,6 +39,10 @@ class TestFSArray < Test::Unit::TestCase
42
39
  assert_equal( 0, ff.size )
43
40
  assert_equal( 10, ff.fifosize )
44
41
 
42
+ ff = FSFIFO.new( 2 )
43
+ assert_equal( 0, ff.size )
44
+ assert_equal( 2, ff.fifosize )
45
+
45
46
  end
46
47
 
47
48
  def test_size
@@ -159,9 +160,26 @@ class TestFSArray < Test::Unit::TestCase
159
160
  end
160
161
 
161
162
  ####
162
-
163
+
164
+ def test_default_uo
165
+
166
+ ff = FSFIFO.new( size: 3, of_enable: true, uf_enable: true )
167
+ assert_equal( 0, ff.size )
168
+ assert_equal( 3, ff.fifosize )
169
+
170
+ ff.push( 1 ); ff.push( 2 ); ff.push( 3 )
171
+ e = assert_raise( RuntimeError ){ ff.push( 4 ); }
172
+
173
+ 3.times { ff.shift; }
174
+ e = assert_raise( RuntimeError ){ ff.shift; }
175
+
176
+ end
177
+
163
178
  def test_of
164
179
 
180
+ assert_equal( 0, @fifo.size )
181
+ assert_equal( 1, @fifo.fifosize )
182
+
165
183
  @fifo.of_enable
166
184
  assert_equal( true, @fifo.of_enable? )
167
185
 
@@ -169,10 +187,12 @@ class TestFSArray < Test::Unit::TestCase
169
187
  @fifo.push( 2 )
170
188
  assert_equal( true, @of_proc_called )
171
189
 
190
+ @of_proc_called = false
172
191
  @fifo.push( 3 )
173
- assert_equal( false, @of_proc_called )
192
+ assert_equal( true, @of_proc_called )
174
193
 
175
194
  @fifo.of_disable
195
+ @of_proc_called = false
176
196
  @fifo.push( 4 )
177
197
  assert_equal( false, @of_proc_called )
178
198
 
@@ -180,17 +200,23 @@ class TestFSArray < Test::Unit::TestCase
180
200
 
181
201
  def test_uf
182
202
 
203
+ assert_equal( 0, @fifo.size )
204
+ assert_equal( 1, @fifo.fifosize )
205
+
183
206
  @fifo.uf_enable
184
207
  assert_equal( true, @fifo.uf_enable? )
185
208
 
209
+ @uf_proc_called = false
186
210
  @fifo.push( 1 )
187
211
  @fifo.shift
188
- assert_equal( true, @uf_proc_called )
189
-
190
- @fifo.push( 2 )
191
- @fifo.shift
192
212
  assert_equal( false, @uf_proc_called )
193
213
 
214
+ @uf_proc_called = false
215
+ @fifo.push( 1 )
216
+ 2.times{ @fifo.shift }
217
+ assert_equal( true, @uf_proc_called )
218
+
219
+ @uf_proc_called = false
194
220
  @fifo.push( 3 )
195
221
  @fifo.uf_disable
196
222
  @fifo.shift
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fsfifo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - YAMAMOTO, Masayuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-31 00:00:00.000000000 Z
11
+ date: 2013-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -93,6 +93,7 @@ files:
93
93
  - Rakefile
94
94
  - ReadMe.md
95
95
  - VERSION
96
+ - fsfifo.gemspec
96
97
  - lib/fsfifo.rb
97
98
  - test/helper.rb
98
99
  - test/test_fsfifo.rb
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  version: '0'
117
118
  requirements: []
118
119
  rubyforge_project:
119
- rubygems_version: 2.0.6
120
+ rubygems_version: 2.1.9
120
121
  signing_key:
121
122
  specification_version: 4
122
123
  summary: Fixed size FIFO.