5 * Created by Christian Brunschen on 12/05/2008.
6 * Copyright 2008 Google UK. All rights reserved.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
21 #include "BitMatrixTest.h"
28 CPPUNIT_TEST_SUITE_REGISTRATION(BitMatrixTest);
30 BitMatrixTest::BitMatrixTest() {
34 void BitMatrixTest::testGetSet() {
35 size_t bits = numeric_limits<unsigned int>::digits;
36 BitMatrix matrix(bits + 1);
37 CPPUNIT_ASSERT_EQUAL(bits + 1, matrix.getDimension());
38 for (size_t i = 0; i < bits + 1; i++) {
39 for (size_t j = 0; j < bits + 1; j++) {
45 for (size_t i = 0; i < bits + 1; i++) {
46 for (size_t j = 0; j < bits + 1; j++) {
47 CPPUNIT_ASSERT_EQUAL(i * j % 3 == 0, matrix.get(i, j));
52 void BitMatrixTest::testSetRegion() {
54 matrix.setRegion(1, 1, 3, 3);
55 for (int i = 0; i < 5; i++) {
56 for (int j = 0; j < 5; j++) {
57 CPPUNIT_ASSERT_EQUAL(i >= 1 && i <= 3 && j >= 1 && j <= 3,
63 void BitMatrixTest::testGetBits() {
67 unsigned int* bits = matrix.getBits();
68 CPPUNIT_ASSERT_EQUAL(1u, bits[0]);
69 CPPUNIT_ASSERT_EQUAL(8u, bits[1]);
72 void BitMatrixTest::testGetRow1() {
74 const int height = 76;
75 runBitMatrixGetRowTest(width, height);
78 void BitMatrixTest::testGetRow2() {
79 const int width = 320;
80 const int height = 320;
81 runBitMatrixGetRowTest(width, height);
84 void BitMatrixTest::testGetRow3() {
86 const int height = 23;
87 runBitMatrixGetRowTest(width, height);
90 void BitMatrixTest::runBitMatrixGetRowTest(int width, int height) {
91 BitMatrix mat(width, height);
92 for (int y = 0; y < height; y++) {
93 for (int x = 0; x < width; x++) {
94 if ((rand() & 0x01) != 0) {
99 Ref<BitArray> row(new BitArray(width));
100 for (int y = 0; y < height; y++) {
101 row = mat.getRow(y, row);
102 for (int x = 0; x < width; x++) {
103 CPPUNIT_ASSERT_EQUAL(row->get(x), mat.get(x,y));