-
Notifications
You must be signed in to change notification settings - Fork 0
/
simplegrade.h
145 lines (121 loc) · 3.28 KB
/
simplegrade.h
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
#ifndef _SIMPLETEST_H_
#define _SIMPLETEST_H_
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define KNRM "\x1B[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
int maxgrade=0;
int currmaxgrade=0;
int grade=0;
/* or else we will calculate it by the running tests */
/* joke is on you if you use negative grades... */
#define MAXGRADE(max) maxgrade=max
int GETGRADE(){
return grade;
}
int GETMAXGRADE(){
if (maxgrade)
return maxgrade;
else return currmaxgrade;
}
void GRADEME(){
if (!maxgrade)
maxgrade = currmaxgrade;
int tmp = (int) ((grade / (float) maxgrade)*100);
if (grade < maxgrade*.7){
printf("You did %s %d %s out of %d -- grade %d/100\n", KRED, grade, KNRM, maxgrade, tmp);
}
else{
printf("You did %s %d %s out of %d -- grade %d/100\n", KGRN, grade, KNRM, maxgrade, tmp);
}
}
void DESCRIBE(char* text);
void WHEN(char* text);
void IF(char* text);
void THEN(char* text);
void DESCRIBE(char* text) {
printf("%s-- %s --%s\n",KCYN, text, KNRM);
}
void WHEN(char* text) {
printf("%s when:%s %s\n",KYEL, KNRM, text);
}
void IF(char* text) {
printf("%s if:%s %s\n",KYEL, KNRM, text);
}
void THEN(char* text) {
printf("%s then:%s %s\n",KYEL, KNRM, text);
}
void isNull(void* ptr, int points) {
currmaxgrade+=points;
if (ptr == NULL) {
printf("%s PASSED!\n%s", KGRN, KNRM);
grade+=points;
} else {
printf("%s NOT PASSED!\n pointer is not null%s\n", KRED, KNRM);
}
}
void isNotNull(void * ptr, int points) {
currmaxgrade+=points;
if (ptr != NULL) {
printf("%s PASSED!\n%s", KGRN, KNRM);
grade+=points;
} else {
printf("%s NOT PASSED!\n pointer is not null%s\n", KRED, KNRM);
}
}
void isGreaterThan(int num, int value, int points) {
currmaxgrade+=points;
if (num > value) {
printf("%s PASSED!\n%s", KGRN, KNRM);
grade+=points;
} else {
printf("%s NOT PASSED!\n got: %d > %d %s\n", KRED, num, value, KNRM);
}
}
void isEqual(int num, int value, int points) {
currmaxgrade+=points;
if (num == value) {
printf("%s PASSED!\n%s", KGRN, KNRM);
grade+=points;
} else {
printf("%s NOT PASSED!\n got: %d == %d %s\n", KRED, num, value, KNRM);
}
}
void isNotEqual(int num, int value, int points) {
currmaxgrade+=points;
if (num != value) {
printf("%s PASSED!\n%s", KGRN, KNRM);
grade+=points;
} else {
printf("%s NOT PASSED!\n got: %d != %d %s\n",KRED, num, value, KNRM);
}
}
void isLesserThan(int num, int value, int points) {
currmaxgrade+=points;
if (num < value) {
printf("%s PASSED!\n%s", KGRN, KNRM);
grade+=points;
} else {
printf("%s NOT PASSED!\n got: %d < %d %s\n",KRED, num, value, KNRM);
}
}
/* because floating points ops are not commutative nor associative */
void isNear(float num, float value, int decimals, int points){
currmaxgrade+=points;
float diff = fabs(num - value);
/* check for nearest integers */
if (diff <= pow(10,(-decimals))) {
printf("%s PASSED!\n%s", KGRN, KNRM);
grade+=points;
}else {
printf("%s NOT PASSED!\n got: %f , expecting %f %s\n",KRED, num, value, KNRM);
}
}
#endif //_SIMPLETEST_H