| [84d0c30] | 1 | /*
|
|---|
| 2 | * test_colswap.c
|
|---|
| 3 | *
|
|---|
| 4 | * Application to test functionality of mzd_col_swap.
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright (C) 2011 Carlo Wood <carlo@alinoe.com>
|
|---|
| 7 | * RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
|
|---|
| 8 | * Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
|
|---|
| 9 | *
|
|---|
| 10 | * This program is free software: you can redistribute it and/or modify
|
|---|
| 11 | * it under the terms of the GNU General Public License as published by
|
|---|
| 12 | * the Free Software Foundation, either version 2 of the License, or
|
|---|
| 13 | * (at your option) any later version.
|
|---|
| 14 | *
|
|---|
| 15 | * This program is distributed in the hope that it will be useful,
|
|---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 18 | * GNU General Public License for more details.
|
|---|
| 19 | *
|
|---|
| 20 | * You should have received a copy of the GNU General Public License
|
|---|
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 22 | */
|
|---|
| 23 |
|
|---|
| [a6f6c17] | 24 | #include <m4ri/m4ri.h>
|
|---|
| [84d0c30] | 25 |
|
|---|
| 26 | int test_colswap(rci_t c1) {
|
|---|
| 27 | int failure = 0;
|
|---|
| 28 | printf("col_swap c1: %4d", c1);
|
|---|
| 29 | rci_t const rows = 4 * c1 + 1;
|
|---|
| 30 | mzd_t* A = mzd_init(rows, 4 * c1 + 1);
|
|---|
| 31 | mzd_randomize(A);
|
|---|
| 32 | for (int c2 = 0; c2 < c1 && !failure; c2 += 13) {
|
|---|
| 33 | mzd_t* B = mzd_init_window(A, 0, 0, rows, c1 + 1);
|
|---|
| 34 | mzd_t* C = mzd_copy(NULL, B);
|
|---|
| 35 |
|
|---|
| 36 | mzd_col_swap(B, c1, c2);
|
|---|
| 37 | for(int r = 0; r < rows; ++r) {
|
|---|
| 38 | if (mzd_read_bit(C, r, c1) != mzd_read_bit(B, r, c2) || mzd_read_bit(C, r, c2) != mzd_read_bit(B, r, c1)) {
|
|---|
| 39 | ++failure;
|
|---|
| 40 | break;
|
|---|
| 41 | }
|
|---|
| 42 | }
|
|---|
| 43 | mzd_col_swap(B, c2, c1);
|
|---|
| 44 | if (!mzd_equal(B, C)) {
|
|---|
| 45 | ++failure;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | mzd_col_swap_in_rows(B, c1, c2, c2, c1);
|
|---|
| 49 | for(int r = c1; r < c2; ++r) {
|
|---|
| 50 | if (mzd_read_bit(C, r, c1) != mzd_read_bit(B, r, c2) || mzd_read_bit(C, r, c2) != mzd_read_bit(B, r, c1)) {
|
|---|
| 51 | ++failure;
|
|---|
| 52 | break;
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 | mzd_col_swap_in_rows(B, c2, c1, c2, c1);
|
|---|
| 56 | if (!mzd_equal(B, C)) {
|
|---|
| 57 | ++failure;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | mzd_free(C);
|
|---|
| 61 | mzd_free(B);
|
|---|
| 62 | }
|
|---|
| 63 | mzd_free(A);
|
|---|
| 64 | printf(" ");
|
|---|
| 65 | if (failure) {
|
|---|
| 66 | printf("FAILED\n");
|
|---|
| 67 | }
|
|---|
| 68 | else
|
|---|
| 69 | printf("passed\n");
|
|---|
| 70 | return failure;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | int main()
|
|---|
| 74 | {
|
|---|
| 75 | int status = 0;
|
|---|
| 76 |
|
|---|
| 77 | for (int c1 = 1; c1 < 400; c1 += 15) {
|
|---|
| 78 | status += test_colswap(c1);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | if (!status) {
|
|---|
| 82 | printf("All tests passed.\n");
|
|---|
| 83 | } else {
|
|---|
| 84 | printf("TEST FAILED!\n");
|
|---|
| 85 | return 1;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | return 0;
|
|---|
| 89 | }
|
|---|