-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.c
95 lines (72 loc) · 1.77 KB
/
test.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stmr.h"
static int assertionCount = 0;
static int errorCount = 0;
static void
assertStem(const char *input, const char *output) {
char *value;
char *result;
char *fixture;
value = strdup(input);
result = strdup(input);
fixture = strdup(output);
result[stem(result, 0, strlen(result) - 1) + 1] = 0;
if (strcmp(fixture, result)) {
errorCount++;
fprintf(stderr, "\033[31m");
fprintf(stderr, " (✖) For `%s`. Expected `%s`, got `%s`", value, fixture, result);
fprintf(stderr, "\033[0m");
fprintf(stderr, "\n");
} else {
printf("\033[32m.\033[0m");
}
assertionCount++;
free(value);
free(fixture);
free(result);
}
int
main() {
FILE *input;
FILE *output;
char *lineIn;
char *lineOut;
size_t lengthIn;
size_t lengthOut;
lineIn = NULL;
lineOut = NULL;
lengthIn = 0;
lengthOut = 0;
input = fopen("fixture/input.txt", "r");
output = fopen("fixture/output.txt", "r");
while (
getline(&lineIn, &lengthIn, input) != -1 &&
getline(&lineOut, &lengthOut, output) != -1
) {
lineIn[strlen(lineIn) - 1] = 0;
lineOut[strlen(lineOut) - 1] = 0;
assertStem(lineIn, lineOut);
}
/**
* These two fixture are treated in `stmr.h`, but
* not covered by the fixtures provided Martin
* Porter.
*/
assertStem("nationalization", "nation");
assertStem("nationalism", "nation");
printf("\n");
if (errorCount != 0) {
printf("\033[31m");
printf("(✖) Failed on %d of %d assertions", errorCount, assertionCount);
printf("\033[0m");
printf("\n");
exit(EXIT_FAILURE);
}
printf("\033[32m");
printf("(✓) Passed %d assertions without errors", assertionCount);
printf("\033[0m");
printf("\n");
return 0;
}