-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
54 lines (43 loc) · 1.1 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cs50.h"
static int assertionCount = 0;
static int errorCount = 0;
static void
stringTest(const string str, const char *arr_of_chars) {
if (strcmp(str, arr_of_chars)) {
errorCount++;
fprintf(stderr, "\033[31m");
fprintf(stderr," (✖) Error :(");
fprintf(stderr, "\n\033[0m");
fprintf(stderr, "\n");
} else {
printf("\033[32m (✓) Test passed\033[0m\n");
}
assertionCount++;
}
int
main() {
// Simple test comparing type `string` with `char*`
stringTest("abranhe", "abranhe");
stringTest("carlos", "carlos");
stringTest("james", "james");
stringTest("cs50", "cs50");
stringTest("abraham", "abraham");
// Log total errors.
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);
}
// Or, log total successes.
printf("\033[32m");
printf("(✓) Passed %d assertions without errors", assertionCount);
printf("\033[0m");
printf("\n");
return 0;
}