-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bit_matrix_unit_test.rb
executable file
·119 lines (96 loc) · 2.47 KB
/
Bit_matrix_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/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_matrix.rb'
require 'test/unit'
class Bit_matrixUnitTest < Test::Unit::TestCase
def test_to_s
Bit_matrix.set_binary_output
assert_equal("0000\n0000\n0000\n", Bit_matrix.new(3,4).to_s)
Bit_matrix.set_hex_output
assert_equal("0\n0\n0\n", Bit_matrix.new(3,4).to_s)
end
def test_row_reduce
Bit_matrix.set_binary_output
a = Bit_matrix.new(4,4)
assert_equal("0000\n0000\n0000\n0000\n", a.to_s)
a.row_reduce_below
assert_equal("0000\n0000\n0000\n0000\n", a.to_s)
a.row_echelon_form
assert_equal("0000\n0000\n0000\n0000\n", a.to_s)
a = Bit_matrix.new(4,4)
a[0][0] = 1
a[0][1] = 1
a[1][0] = 1
a[3][2] = 1
assert_equal("0011\n0001\n0000\n0100\n", a.to_s)
a.row_reduce_below
assert_equal("0011\n0010\n0100\n0000\n", a.to_s)
a.row_echelon_form
assert_equal("0001\n0010\n0100\n0000\n", a.to_s)
#assert_equal("0000\n0000\n0000\n", Bit_matrix.new(3,4).to_s)
#Bit_matrix.set_hex_output
#assert_equal("0\n0\n0\n", Bit_matrix.new(3,4).to_s)
end
def test_rank
Bit_matrix.set_binary_output
a = Bit_matrix.new(4,4)
assert_equal(0, a.rank)
a[1][0] = 1
a[0][1] = 1
assert_equal(2, a.rank)
a = Bit_matrix.new(4,4)
assert_equal(0, a.rank)
a[0][0] = 1
a[1][1] = 1
a[2][2] = 1
a[3][3] = 1
assert_equal(4, a.rank)
end
def test_rank_rr
Bit_matrix.set_binary_output
a = Bit_matrix.new(4,4)
assert_equal(0, a.rank_rr)
a[0][0] = 1
a[1][3] = 1
assert_equal(2, a.rank_rr)
end
def test_kernel_basis
Bit_matrix.set_binary_output
a = Bit_matrix.new(4,4)
assert_equal(0, a.rank_rr)
a[0][0] = 1
a[1][1] = 1
a[2][2] = 1
a[3][3] = 1
assert_equal(nil, a.kernel_basis)
a = Bit_matrix.new(4,4)
assert_equal(0, a.rank_rr)
a[0][0] = 1
a[1][1] = 1
a[2][2] = 1
assert_equal("1000\n", a.kernel_basis.to_s)
a = Bit_matrix.new(4,4)
assert_equal(0, a.rank_rr)
a[0][0] = 1
a[1][1] = 1
a[3][3] = 1
assert_equal("0100\n", a.kernel_basis.to_s)
a = Bit_matrix.new(4,4)
assert_equal(0, a.rank_rr)
a[0][0] = 1
a[2][2] = 1
a[3][3] = 1
assert_equal("0010\n", a.kernel_basis.to_s)
a = Bit_matrix.new(4,4)
assert_equal(0, a.rank_rr)
a[1][1] = 1
a[2][2] = 1
a[3][3] = 1
assert_equal("0001\n", a.kernel_basis.to_s)
end
end