Branch
Hash :
f8ceb0d2
Author :
Date :
2020-08-28T18:38:00
All test programs are now TAP-ready.
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "../mmask.h"
#include "../mqrspec.h"
static char dot[2] = {'_', '#'};
static char *maskPatterns[4] = {
/* i mod 2 = 0 */
"######"
"______"
"######"
"______"
"######"
"______",
/* ((i div 2) + (j div 3)) mod 2 = 0 */
"###___"
"###___"
"___###"
"___###"
"###___"
"###___",
/* ((ij) mod 2 + (ij) mod 3) mod 2 = 0 */
"######"
"###___"
"##_##_"
"#_#_#_"
"#_##_#"
"#___##",
/* ((ij) mod 3 + (i+j) mod 2) mod 2 = 0 */
"#_#_#_"
"___###"
"#___##"
"_#_#_#"
"###___"
"_###__"
};
static void print_mask(int mask)
{
const int w = 6;
unsigned char frame[w * w], *masked, *p;
int x, y;
memset(frame, 0, w * w);
masked = MMask_makeMaskedFrame(w, frame, mask);
p = masked;
for(y=0; y<w; y++) {
for(x=0; x<w; x++) {
putchar(dot[*p&1]);
p++;
}
printf("\n");
}
printf("\n");
free(masked);
}
static void print_masks(void)
{
int i;
puts("\nPrinting mask patterns.");
for(i=0; i<4; i++) {
print_mask(i);
}
}
static int test_mask(int mask)
{
const int w = 6;
unsigned char frame[w * w], *masked, *p;
char *q;
int x, y;
int err = 0;
memset(frame, 0, w * w);
masked = MMask_makeMaskedFrame(w, frame, mask);
p = masked;
q = maskPatterns[mask];
for(y=0; y<w; y++) {
for(x=0; x<w; x++) {
if(dot[*p&1] != *q) {
err++;
}
p++;
q++;
}
}
free(masked);
return err;
}
static void test_masks(void)
{
int i;
testStart("Mask pattern checks");
for(i=0; i<4; i++) {
assert_zero(test_mask(i), "Mask pattern %d incorrect.\n", i);
}
testFinish();
}
static void test_maskEvaluation(void)
{
static const int w = 11;
unsigned char pattern[w * w];
int i, score;
memset(pattern, 0, w * w);
testStart("Test mask evaluation");
score = MMask_evaluateSymbol(w, pattern);
assert_equal(score, 0, "Mask score caluculation is incorrect. (score=%d (%d expected)\n", score, 0);
for(i=0; i<w; i++) {
pattern[(w-1) * w + i] = 1;
}
score = MMask_evaluateSymbol(w, pattern);
assert_equal(score, 16 + w - 1, "Mask score caluculation is incorrect. (score=%d) (%d expected)\n", score, 16 + w - 1);
for(i=0; i<w; i++) {
pattern[(w-1) * w + i] = 0;
pattern[i * w + w - 1] = 1;
}
score = MMask_evaluateSymbol(w, pattern);
assert_equal(score, 16 + w - 1, "Mask score caluculation is incorrect. (score=%d) (%d expected)\n", score, 16 + w - 1);
for(i=0; i<w; i++) {
pattern[(w-1) * w + i] = 1;
pattern[i * w + w - 1] = 1;
}
score = MMask_evaluateSymbol(w, pattern);
assert_equal(score, 16 * (w - 1) + w - 1, "Mask score caluculation is incorrect. (score=%d) (%d expected)\n", score, 16 * (w - 1) + w - 1);
testFinish();
}
int main(int argc, char **argv)
{
int tests = 2;
testInit(tests);
test_masks();
test_maskEvaluation();
testReport(tests);
if(argc > 1) {
print_masks();
}
return 0;
}