-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bit_vector_unit_test.rb
executable file
·63 lines (52 loc) · 1.91 KB
/
Bit_vector_unit_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/ruby -Wall
# ================================================================
# Please see LICENSE.txt in the same directory as this file.
# John Kerl
# kerl.john.r@gmail.com
# Copyright (c) 2011
# ================================================================
require 'Bit_vector.rb'
require 'test/unit'
class Bit_vectorUnitTest < Test::Unit::TestCase
def test_to_s
Bit_vector.set_binary_output
assert_equal("0", Bit_vector.new(1).to_s)
assert_equal("00", Bit_vector.new(2).to_s)
assert_equal("000", Bit_vector.new(3).to_s)
assert_equal("0000", Bit_vector.new(4).to_s)
assert_equal("00000", Bit_vector.new(5).to_s)
assert_equal("000000", Bit_vector.new(6).to_s)
Bit_vector.set_hex_output
assert_equal("0", Bit_vector.new(1).to_s)
assert_equal("0", Bit_vector.new(2).to_s)
assert_equal("0", Bit_vector.new(3).to_s)
assert_equal("0", Bit_vector.new(4).to_s)
assert_equal("00", Bit_vector.new(5).to_s)
assert_equal("00", Bit_vector.new(6).to_s)
end
def test_brackets_and_toggle
Bit_vector.set_binary_output
v = Bit_vector.new(8)
assert_equal("00000000", v.to_s)
# xxx note right to left ...
v[0] = 1; assert_equal("00000001", v.to_s)
v[7] = 1; assert_equal("10000001", v.to_s)
v[6] = 1; assert_equal("11000001", v.to_s)
v.toggle_element(6); assert_equal("10000001", v.to_s)
v.toggle_element(6); assert_equal("11000001", v.to_s)
v.toggle_element(6); assert_equal("10000001", v.to_s)
assert_raise(RuntimeError) {v[ 8] = 1}
assert_raise(RuntimeError) {v[ 8] = 0}
assert_raise(RuntimeError) {v[-1] = 1}
assert_raise(RuntimeError) {v[-1] = 0}
end
def test_find_leader_pos
Bit_vector.set_binary_output
v = Bit_vector.new(8)
assert_equal(-1, v.find_leader_pos)
v[0] = 1; assert_equal(0, v.find_leader_pos)
v[4] = 1; assert_equal(0, v.find_leader_pos)
v[5] = 1; assert_equal(0, v.find_leader_pos)
v[0] = 0; assert_equal(4, v.find_leader_pos)
end
end