File tree Expand file tree Collapse file tree 2 files changed +20
-19
lines changed Expand file tree Collapse file tree 2 files changed +20
-19
lines changed Original file line number Diff line number Diff line change 1
1
class BitArray
2
2
attr_reader :size
3
+ attr_reader :field
3
4
include Enumerable
5
+
4
6
VERSION = "0.0.5"
5
7
ELEMENT_WIDTH = 32
6
8
7
- def initialize ( size , default_value = 0 )
9
+ def initialize ( size , field = nil )
8
10
@size = size
9
- @field = Array . new ( ( ( size - 1 ) / ELEMENT_WIDTH ) + 1 , 0 )
10
- @field . map! { |i | ~i } if ( default_value == 1 )
11
+ @field = field || Array . new ( ( ( size - 1 ) / ELEMENT_WIDTH ) + 1 , 0 )
11
12
end
12
13
13
14
# Set a bit (1/0)
Original file line number Diff line number Diff line change @@ -29,22 +29,22 @@ def test_random_setting_and_unsetting
29
29
end
30
30
end
31
31
32
- def test_random_side_effects
33
- ba2 = BitArray . new ( @public_ba . size , 1 )
34
-
35
- on = ( @public_ba . size / 2 ) . times . collect do
36
- index = rand ( @public_ba . size )
37
- @public_ba [ index ] = 1
38
- ba2 [ index ] = 0
39
- index
40
- end
41
- #assert_equal(@public_ba.to_s, @public_ba.to_s_fast)
42
-
43
- @public_ba . size . times do |i |
44
- assert_equal ( @public_ba [ i ] , on . include? ( i ) ? 1 : 0 )
45
- assert_equal ( ba2 [ i ] , on . include? ( i ) ? 0 : 1 )
46
- end
47
- end
32
+ # def test_random_side_effects
33
+ # ba2 = BitArray.new(@public_ba.size, 1)
34
+ #
35
+ # on = (@public_ba.size / 2).times.collect do
36
+ # index = rand(@public_ba.size)
37
+ # @public_ba[index] = 1
38
+ # ba2[index] = 0
39
+ # index
40
+ # end
41
+ # #assert_equal(@public_ba.to_s, @public_ba.to_s_fast)
42
+ #
43
+ # @public_ba.size.times do |i|
44
+ # assert_equal(@public_ba[i], on.include?(i) ? 1 : 0)
45
+ # assert_equal(ba2[i], on.include?(i) ? 0 : 1)
46
+ # end
47
+ # end
48
48
49
49
def test_multiple_setting
50
50
1 . upto ( 999 ) do |pos |
You can’t perform that action at this time.
0 commit comments