source: CIVL/examples/omp/m4ri/tests/test_misc.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * test_misc.c
3 *
4 * Testing small helper functions.
5 *
6 * Copyright (C) 2011 Martin Albrecht <martinralbrecht@googlemail.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <stdarg.h>
23#include <m4ri/m4ri.h>
24
25#define b(n) (m4ri_one<<(n))
26
27int test_spread_and_shrink(const word to, const int length, ...) {
28 word from = 0xFF;
29 rci_t *Q = (rci_t*)calloc(sizeof(rci_t),length);
30 va_list l;
31 va_start(l,length);
32 for(size_t i=0; i<length; i++) {
33 Q[i] = va_arg(l, size_t);
34 }
35
36 const word res = m4ri_spread_bits(from, Q, length, 0);
37 const word pre = m4ri_shrink_bits(res, Q, length, 0);
38
39 free(Q);
40 va_end(l);
41
42 if (pre != (b(length)-1)) {
43 return 1;
44 }
45 if (res != to) {
46 return 1;
47 }
48 return 0;
49}
50
51int test_png(rci_t m, rci_t n) {
52 int ret = 0;
53#if __M4RI_HAVE_LIBPNG
54 printf("png: m: %4d, n: %4d", m, n);
55
56 const char *fn = "test_misc__test_png.png";
57
58 mzd_t *A = mzd_init(m,n);
59 mzd_randomize(A);
60 mzd_to_png(A, fn, 0, NULL, 0);
61 mzd_t *B = mzd_from_png(fn, 0);
62
63 ret += mzd_cmp(A,B);
64
65 remove(fn);
66 mzd_free(B);
67 mzd_free(A);
68
69 if(ret==0) {
70 printf(" ... passed\n");
71 } else {
72 printf(" ... FAILED\n");
73 }
74#endif
75 return ret;
76}
77
78
79int main(int argc, char *argv[]) {
80 int status = 0;
81
82 status += test_spread_and_shrink( b(1)|b(0), 2, 0,1);
83 status += test_spread_and_shrink( b(2)|b(0), 2, 0,2);
84 status += test_spread_and_shrink( b(3)|b(1), 2, 1,3);
85 status += test_spread_and_shrink( b(3)|b(2), 2, 2,3);
86 status += test_spread_and_shrink( b(2)|b(1)|b(0), 3, 0,1,2);
87 status += test_spread_and_shrink( b(3)|b(2)|b(0), 3, 0,2,3);
88 status += test_spread_and_shrink( b(4)|b(3)|b(1), 3, 1,3,4);
89 status += test_spread_and_shrink( b(5)|b(3)|b(2), 3, 2,3,5);
90
91 status += test_png(1,1);
92 status += test_png(16,15);
93 status += test_png(32,32);
94 status += test_png(63,63);
95 status += test_png(64,64);
96 status += test_png(113,114);
97 status += test_png(125,102);
98 status += test_png(126,12);
99 status += test_png(128,200);
100
101 if (!status) {
102 printf("All tests passed.\n");
103 } else {
104 printf("TEST FAILED!\n");
105 return 1;
106 }
107 return 0;
108}
109
Note: See TracBrowser for help on using the repository browser.