Compare commits
No commits in common. "8ca828ebf6e39fb20abd5c4a8f847393a05f8ddd" and "d4f45c5e48620aeabfb99bd0347d32d458177274" have entirely different histories.
8ca828ebf6
...
d4f45c5e48
@ -1,25 +0,0 @@
|
|||||||
.POSIX:
|
|
||||||
|
|
||||||
|
|
||||||
TEST_SRC = $(wildcard tests/*c)
|
|
||||||
TEST_OBJ = $(TEST_SRC:tests/%.c=tests/%.o)
|
|
||||||
SRC = x_ctypes.c
|
|
||||||
OBJ = $(SRC:.c=.o)
|
|
||||||
CFLAGS = -ggdb -Wall -Wextra -I.
|
|
||||||
|
|
||||||
run_testtest: test
|
|
||||||
./test
|
|
||||||
|
|
||||||
test: $(TEST_OBJ) $(OBJ)
|
|
||||||
$(CC) $(CFLAGS) -o $@ $(TEST_OBJ) $(OBJ)
|
|
||||||
|
|
||||||
|
|
||||||
$(OBJ):
|
|
||||||
|
|
||||||
$(TEST_OBJ): $(TEST_SRC)
|
|
||||||
$(CC) $(CFLAGS) -c $(TEST_SRC) -o $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f test $(OBJ) $(TEST_OBJ)
|
|
||||||
|
|
||||||
.PHONY: all clean_all clean install uninstall test
|
|
@ -1,160 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include "x_ctypes.h"
|
|
||||||
|
|
||||||
// printf Formating
|
|
||||||
#define X_RED "\x1B[31m"
|
|
||||||
#define X_GREEN "\x1B[32m"
|
|
||||||
#define X_RST "\x1B[0m"
|
|
||||||
|
|
||||||
// INSERT HEADERS FOR FUNCS
|
|
||||||
|
|
||||||
// SET THE NUMBER OF TESTS
|
|
||||||
#define NUM_TESTS 9
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// DUMMY TEST
|
|
||||||
int fail(){
|
|
||||||
printf("%s... ", __func__);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DEFINE TESTS
|
|
||||||
int test_x_isdigit_with_char_is_ascii_3(){
|
|
||||||
printf("%s... ", __func__);
|
|
||||||
char x = '3';
|
|
||||||
|
|
||||||
if ( x_isdigit(x) ){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_x_isdigit_with_char_is_ascii_l(){
|
|
||||||
printf("%s... ", __func__);
|
|
||||||
char x = 'l';
|
|
||||||
|
|
||||||
if ( !x_isdigit(x) ){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_x_isdigit_with_int_4(){
|
|
||||||
printf("%s... ", __func__);
|
|
||||||
char x = 4;
|
|
||||||
|
|
||||||
if ( x_isdigit(x) ){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_x_isdigit_with_ascii_pound(){
|
|
||||||
printf("%s... ", __func__);
|
|
||||||
|
|
||||||
char x = '#';
|
|
||||||
|
|
||||||
if ( !x_isdigit(x) ){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_x_isnumber_with_ascii_1234(){
|
|
||||||
printf("%s... ", __func__);
|
|
||||||
|
|
||||||
char *str = "1234";
|
|
||||||
|
|
||||||
if ( x_isnumber(str) ){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_x_isnumber_with_ascii_abcd(){
|
|
||||||
printf("%s... ", __func__);
|
|
||||||
|
|
||||||
char *str = "abcd";
|
|
||||||
|
|
||||||
if ( !x_isnumber(str) ){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_x_isnumber_with_ascii_6(){
|
|
||||||
printf("%s... ", __func__);
|
|
||||||
|
|
||||||
char *str = "6";
|
|
||||||
|
|
||||||
if ( x_isnumber(str) ){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_x_isnumber_with_ascii_b(){
|
|
||||||
printf("%s... ", __func__);
|
|
||||||
|
|
||||||
char *str = "b";
|
|
||||||
|
|
||||||
if ( !x_isnumber(str) ){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// END OF TEST DEFINITIONS
|
|
||||||
|
|
||||||
void run_tests(int (**tests)()){
|
|
||||||
int i = 0;
|
|
||||||
int errors = 0;
|
|
||||||
|
|
||||||
for ( i = 0; i < NUM_TESTS; i++ ){
|
|
||||||
printf("Test #%d... ", i);
|
|
||||||
if ( tests[i]() == 0){
|
|
||||||
printf("%spassed%s\n", X_GREEN, X_RST);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("%sfailed%s\n", X_RED, X_RST);
|
|
||||||
errors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Tests completed with %s%d passed%s", X_GREEN, NUM_TESTS - errors, X_RST);
|
|
||||||
printf(" and %s%d failed%s\n", X_RED, errors, X_RST);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
int (*tests[NUM_TESTS])();
|
|
||||||
|
|
||||||
// PASS TESTS INTO ARRAY
|
|
||||||
tests[0] = fail;
|
|
||||||
tests[1] = test_x_isdigit_with_char_is_ascii_3;
|
|
||||||
tests[2] = test_x_isdigit_with_char_is_ascii_l;
|
|
||||||
tests[3] = test_x_isdigit_with_int_4;
|
|
||||||
tests[4] = test_x_isdigit_with_ascii_pound;
|
|
||||||
tests[5] = test_x_isnumber_with_ascii_1234;
|
|
||||||
tests[6] = test_x_isnumber_with_ascii_abcd;
|
|
||||||
tests[7] = test_x_isnumber_with_ascii_6;
|
|
||||||
tests[8] = test_x_isnumber_with_ascii_b;
|
|
||||||
|
|
||||||
|
|
||||||
// END OF PASSING TESTS
|
|
||||||
|
|
||||||
// RUN TESTS
|
|
||||||
run_tests(tests);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int x_isdigit(const char x){
|
|
||||||
if ( x > 48 && x < 57 ){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if ( x > 0 && x < 9 ){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x_isnumber(const char* str){
|
|
||||||
const char * ptr;
|
|
||||||
|
|
||||||
for (ptr = str; *ptr != '\0'; ptr++){
|
|
||||||
if ( !x_isdigit(*ptr) ){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
#ifndef X_CTYPES_H
|
|
||||||
#define X_CTYPES_H
|
|
||||||
|
|
||||||
|
|
||||||
// returns 0 if x is not a digit and 1 if it is
|
|
||||||
int x_isdigit(char x);
|
|
||||||
int x_isnumber(char *str);
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user