implement tests
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "comparison.h"
|
||||
#include "../print/print.h"
|
||||
|
||||
@@ -13,7 +12,17 @@ int comparisonTest(char* name, int x, int y, int expected, int result) {
|
||||
}
|
||||
}
|
||||
|
||||
int boolTest(char* name, bool a, bool b, bool expected, bool result) {
|
||||
int boolTestOne(char* name, bool x, bool expected, bool result) {
|
||||
if (expected == result) {
|
||||
bool_succPrefixOne(name, x, expected, result);
|
||||
return 0;
|
||||
} else {
|
||||
bool_errPrefixOne(name, x, expected, result);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int boolTestTwo(char* name, bool a, bool b, bool expected, bool result) {
|
||||
if (expected == result) {
|
||||
bool_succInfixTwo(name, a, b, expected, result);
|
||||
return 0;
|
||||
@@ -55,8 +64,16 @@ void runComparisonTests() {
|
||||
comparisonTest(">=", 0, 1, 0, gte(0, 1));
|
||||
comparisonTest(">=", 0, 0, 1, gte(0, 0));
|
||||
|
||||
boolTest("&&", true, true, true, and(true, true));
|
||||
boolTest("&&", true, false, false, and(true, false));
|
||||
boolTest("&&", false, true, false, and(false, true));
|
||||
boolTest("&&", false, false, false, and(false, false));
|
||||
boolTestTwo("&&", true, true, true, and(true, true));
|
||||
boolTestTwo("&&", true, false, false, and(true, false));
|
||||
boolTestTwo("&&", false, true, false, and(false, true));
|
||||
boolTestTwo("&&", false, false, false, and(false, false));
|
||||
|
||||
boolTestTwo("||", true, true, true, or(true, true));
|
||||
boolTestTwo("||", true, false, true, or(true, false));
|
||||
boolTestTwo("||", false, true, true, or(false, true));
|
||||
boolTestTwo("||", false, false, false, or(false, false));
|
||||
|
||||
boolTestOne("!", true, false, not(true));
|
||||
boolTestOne("!", false, true, not(false));
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include "print.h"
|
||||
|
||||
char* printBool(bool a) {
|
||||
if (a == true) {
|
||||
return "true";
|
||||
}
|
||||
return "false";
|
||||
}
|
||||
|
||||
void succInfixTwo(char* name, int x, int y, int expected, int result) {
|
||||
incSuccess();
|
||||
printf("\033[0;32mSUCCESS:\t%d %s %d\tGOT: %d\tExpected: %d\033[0;0m\n", x, name, y, result, expected);
|
||||
@@ -42,20 +48,22 @@ void errPrefixTwo(char* name, int x, int y, int expected, int result) {
|
||||
printf("\033[0;31mERROR:\t\t%s(%d, %d)\tGOT: %d\tExpected: %d\033[0;0m\n", name, x, y, result, expected);
|
||||
}
|
||||
|
||||
void bool_succPrefixTwo(char* name, bool a, bool b, bool expected, bool result) {
|
||||
void bool_succPrefixOne(char* name, bool x, bool expected, bool result) {
|
||||
incSuccess();
|
||||
printf("\033[0;32mSUCCESS:\t%s(%s, %s)\tGOT: %s\tExpected: %s\033[0;0m\n", name, printBool(a), printBool(b), printBool(result), printBool(expected));
|
||||
printf("\033[0;32mSUCCESS:\t%s%s\tGOT: %s\tExpected: %s\033[0;0m\n", name, printBool(x), printBool(result), printBool(expected));
|
||||
}
|
||||
|
||||
void bool_errPrefixTwo(char* name, bool a, bool b, bool expected, bool result) {
|
||||
void bool_errPrefixOne(char* name, bool x, bool expected, bool result) {
|
||||
incFailure();
|
||||
printf("\033[0;32mSUCCESS:\t%s(%s, %s)\tGOT: %s\tExpected: %s\033[0;0m\n", name, printBool(a), printBool(b), printBool(result), printBool(expected));
|
||||
|
||||
printf("\033[0;31mERROR:\t\t%s%s\tGOT: %s\tExpected: %s\033[0;0m\n", name, printBool(x), printBool(result), printBool(expected));
|
||||
}
|
||||
|
||||
char* printBool(bool a) {
|
||||
if (a == true) {
|
||||
return "true";
|
||||
}
|
||||
return "false";
|
||||
void bool_succInfixTwo(char* name, bool a, bool b, bool expected, bool result) {
|
||||
incSuccess();
|
||||
printf("\033[0;32mSUCCESS:\t%s %s %s\tGOT: %s\tExpected: %s\033[0;0m\n", printBool(a), name, printBool(b), printBool(result), printBool(expected));
|
||||
}
|
||||
|
||||
void bool_errInfixTwo(char* name, bool a, bool b, bool expected, bool result) {
|
||||
incFailure();
|
||||
printf("\033[0;31mERROR:\t\t%s %s %s\tGOT: %s\tExpected: %s\033[0;0m\n", printBool(a), name, printBool(b), printBool(result), printBool(expected));
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
void incSuccess();
|
||||
void incFailure();
|
||||
|
||||
@@ -6,11 +8,15 @@ void err(char* name, int expected, int result);
|
||||
|
||||
void succPrefixOne(char* name, int x, int expected, int result);
|
||||
void errPrefixOne(char* name, int x, int expected, int result);
|
||||
|
||||
void succPrefixTwo(char* name, int x, int y, int expected, int result);
|
||||
void errPrefixTwo(char* name, int x, int y, int expected, int result);
|
||||
|
||||
void succInfixTwo(char* name, int x, int y, int expected, int result);
|
||||
void errInfixTwo(char* name, int x, int y, int expected, int result);
|
||||
|
||||
void bool_succPrefixOne(char* name, bool x, bool expected, bool result);
|
||||
void bool_errPrefixOne(char* name, bool x, bool expected, bool result);
|
||||
|
||||
void bool_succInfixTwo(char* name, bool x, bool y, bool expected, bool result);
|
||||
void bool_errInfixTwo(char* name, bool x, bool y, bool expected, bool result);
|
||||
|
||||
@@ -171,7 +171,7 @@ function or(a, b) {
|
||||
}
|
||||
|
||||
function not(a) {
|
||||
return (!a);
|
||||
return !a;
|
||||
}
|
||||
|
||||
add(1, 1);
|
||||
|
||||
Reference in New Issue
Block a user