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