2 $:.unshift File.join(File.dirname(__FILE__),'..','lib')
4 # Copyright (C) 2007-2010 Martin A. Hansen.
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # http://www.gnu.org/copyleft/gpl.html
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
24 # This software is part of the Biopieces framework (www.biopieces.org).
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
33 class TestBitArray < Test::Unit::TestCase
35 @ba = BitArray.new(10)
38 def test_BitArray_initialize_raises_on_bad_sizes
39 [ -1, 0, 1.1, "a" ].each do |size|
40 assert_raise(BitArrayError) { BitArray.new(size) }
44 def test_BitArray_initialize_dont_raise_on_ok_sizes
45 [ 1, 10, 1000 ].each do |size|
46 assert_nothing_raised { BitArray.new(size) }
50 def test_BitArray_size_returns_correctly
51 assert_equal(10, @ba.size)
54 def test_BitArray_to_s_returns_correctly
55 assert_equal("0000000000", @ba.to_s)
58 def test_BitArray_bit_set_with_bad_pos_raises
59 [-1, 10, 1.1].each do |pos|
60 assert_raise(BitArrayError) { @ba.bit_set(pos) }
64 def test_BitArray_bit_set
67 (0.upto 9).each do |pos|
70 assert_equal(str, @ba.to_s)
74 def test_BitArray_bit_set_questionmark_with_bad_pos_raises
75 [-1, 10, 1.1].each do |pos|
76 assert_raise(BitArrayError) { @ba.bit_set?(pos) }
80 def test_BitArray_bit_set_questionmark
81 (0.upto 9).each do |pos|
83 assert_equal(true, @ba.bit_set?(pos))
87 def test_BitArray_bits_on_returns_correctly
91 assert_equal(3, @ba.bits_on)
94 def test_BitArray_bits_off_returns_correctly
96 assert_equal(9, @ba.bits_off)
99 def test_BitArray_AND_with_uneven_sizes_raises
100 ba = BitArray.new(11)
101 assert_raise(BitArrayError) { @ba & ba }
104 def test_BitArray_AND_returns_correctly
105 ba = BitArray.new(10)
110 assert_equal( "0000010000", (@ba & ba).to_s)
113 def test_BitArray_OR_with_uneven_sizes_raises
114 ba = BitArray.new(11)
115 assert_raise(BitArrayError) { @ba | ba }
118 def test_BitArray_OR_returns_correctly
119 ba = BitArray.new(10)
124 assert_equal( "0000111000", (@ba | ba).to_s)
127 def test_BitArray_XOR_with_uneven_sizes_raises
128 ba = BitArray.new(11)
129 assert_raise(BitArrayError) { @ba ^ ba }
132 def test_BitArray_XOR_returns_correctly
133 ba = BitArray.new(10)
138 assert_equal( "0000101000", (@ba ^ ba).to_s)