Test function bug fix and more testcases

This commit is contained in:
Timo Schmidt 2023-05-03 21:33:34 +02:00
parent e919a48b34
commit a99516268a
2 changed files with 87 additions and 36 deletions

View File

@ -22,33 +22,59 @@ exit -- "${exit_status}"
#include <stdio.h>
#include <unistd.h>
#define test(out_prefix, expected_string, func, ...) \
#define test(inp, func, ...) \
do { \
fprintf(stderr, "Case:%s:%s", out_prefix, expected_string); \
fflush(stderr); \
int old_stderr_fd = dup(2); \
dup2(1, 2); \
fprintf(stdout, "Case:%s:", out_prefix); \
fprintf(stdout, "Case:%s:", inp); \
fflush(stdout); \
func(__VA_ARGS__); \
fflush(stderr); \
fflush(stdout); \
dup2(old_stderr_fd, 2); \
} while(0)
#define expect(inp, func, ...) \
do { \
int old_stdout_fd = dup(1); \
dup2(2, 1); \
fprintf(stderr, "Case:%s:", inp); \
fflush(stderr); \
func(__VA_ARGS__); \
fflush(stderr); \
fflush(stdout); \
dup2(old_stdout_fd, 1); \
} while(0)
// Don't delete above this comment
#include <ctype.h>
int ft_isalpha(int c);
int main(){
test( "'a'", "1\n", printf, "%d\n", ft_isalpha('a'));
test( "'A'", "1\n", printf, "%d\n", ft_isalpha('A'));
test( "'m'", "1\n", printf, "%d\n", ft_isalpha('m'));
test( "'M'", "1\n", printf, "%d\n", ft_isalpha('M'));
test( "'z'", "1\n", printf, "%d\n", ft_isalpha('z'));
test( "'Z'", "1\n", printf, "%d\n", ft_isalpha('Z'));
test( "0", "0\n", printf, "%d\n", ft_isalpha(0));
test( "1", "0\n", printf, "%d\n", ft_isalpha(1));
test("'a' - 1", "0\n", printf, "%d\n", ft_isalpha('a' - 1));
test("'A' - 1", "0\n", printf, "%d\n", ft_isalpha('A' - 1));
test("'z' + 1", "0\n", printf, "%d\n", ft_isalpha('z' + 1));
test("'Z' + 1", "0\n", printf, "%d\n", ft_isalpha('Z' + 1));
test( "'a'", printf, "%d\n", ft_isalpha('a'));
expect( "'a'", printf, "%d\n", isalpha('a'));
test( "'A'", printf, "%d\n", ft_isalpha('A'));
expect( "'A'", printf, "%d\n", isalpha('A'));
test( "'m'", printf, "%d\n", ft_isalpha('m'));
expect( "'m'", printf, "%d\n", isalpha('m'));
test( "'M'", printf, "%d\n", ft_isalpha('M'));
expect( "'M'", printf, "%d\n", isalpha('M'));
test( "'z'", printf, "%d\n", ft_isalpha('z'));
expect( "'z'", printf, "%d\n", isalpha('z'));
test( "'Z'", printf, "%d\n", ft_isalpha('Z'));
expect( "'Z'", printf, "%d\n", isalpha('Z'));
test( "0", printf, "%d\n", ft_isalpha(0));
expect( "0", printf, "%d\n", isalpha(0));
test( "1", printf, "%d\n", ft_isalpha(1));
expect( "1", printf, "%d\n", isalpha(1));
test( "'a' - 1", printf, "%d\n", ft_isalpha('a' - 1));
expect("'a' - 1", printf, "%d\n", isalpha('a' - 1));
test( "'A' - 1", printf, "%d\n", ft_isalpha('A' - 1));
expect("'A' - 1", printf, "%d\n", isalpha('A' - 1));
test( "'z' + 1", printf, "%d\n", ft_isalpha('z' + 1));
expect("'z' + 1", printf, "%d\n", isalpha('z' + 1));
test( "'Z' + 1", printf, "%d\n", ft_isalpha('Z' + 1));
expect("'Z' + 1", printf, "%d\n", isalpha('Z' + 1));
return 0;
}

View File

@ -22,36 +22,61 @@ exit -- "${exit_status}"
#include <stdio.h>
#include <unistd.h>
#define test(out_prefix, expected_string, func, ...) \
#define test(inp, func, ...) \
do { \
fprintf(stderr, "Case:%s:%s", out_prefix, expected_string); \
fflush(stderr); \
int old_stderr_fd = dup(2); \
dup2(1, 2); \
fprintf(stdout, "Case:%s:", out_prefix); \
fprintf(stdout, "Case:%s:", inp); \
fflush(stdout); \
func(__VA_ARGS__); \
fflush(stderr); \
fflush(stdout); \
dup2(old_stderr_fd, 2); \
} while(0)
#define expect(inp, func, ...) \
do { \
int old_stdout_fd = dup(1); \
dup2(2, 1); \
fprintf(stderr, "Case:%s:", inp); \
fflush(stderr); \
func(__VA_ARGS__); \
fflush(stderr); \
fflush(stdout); \
dup2(old_stdout_fd, 1); \
} while(0)
// Don't delete above this comment
#include <ctype.h>
int ft_isdigit(int c);
int main(){
test("'0'", "1\n", printf, "%d\n", ft_isdigit('0'));
test("'1'", "1\n", printf, "%d\n", ft_isdigit('1'));
test("'2'", "1\n", printf, "%d\n", ft_isdigit('2'));
test("'3'", "1\n", printf, "%d\n", ft_isdigit('3'));
test("'4'", "1\n", printf, "%d\n", ft_isdigit('4'));
test("'5'", "1\n", printf, "%d\n", ft_isdigit('5'));
test("'6'", "1\n", printf, "%d\n", ft_isdigit('6'));
test("'7'", "1\n", printf, "%d\n", ft_isdigit('7'));
test("'8'", "1\n", printf, "%d\n", ft_isdigit('8'));
test("'9'", "1\n", printf, "%d\n", ft_isdigit('9'));
test( "0", "0\n", printf, "%d\n", ft_isdigit(0));
test( "1", "0\n", printf, "%d\n", ft_isdigit(1));
test("127", "0\n", printf, "%d\n", ft_isdigit(127));
test("255", "0\n", printf, "%d\n", ft_isdigit(255));
test( "-1", "0\n", printf, "%d\n", ft_isdigit(-1));
test( "'0'", printf, "%d\n", ft_isdigit('0'));
expect("'0'", printf, "%d\n", isdigit('0'));
test( "'1'", printf, "%d\n", ft_isdigit('1'));
expect("'1'", printf, "%d\n", isdigit('1'));
test( "'2'", printf, "%d\n", ft_isdigit('2'));
expect("'2'", printf, "%d\n", isdigit('2'));
test( "'3'", printf, "%d\n", ft_isdigit('3'));
expect("'3'", printf, "%d\n", isdigit('3'));
test( "'4'", printf, "%d\n", ft_isdigit('4'));
expect("'4'", printf, "%d\n", isdigit('4'));
test( "'5'", printf, "%d\n", ft_isdigit('5'));
expect("'5'", printf, "%d\n", isdigit('5'));
test( "'6'", printf, "%d\n", ft_isdigit('6'));
expect("'6'", printf, "%d\n", isdigit('6'));
test( "'7'", printf, "%d\n", ft_isdigit('7'));
expect("'7'", printf, "%d\n", isdigit('7'));
test( "'8'", printf, "%d\n", ft_isdigit('8'));
expect("'8'", printf, "%d\n", isdigit('8'));
test( "'9'", printf, "%d\n", ft_isdigit('9'));
expect("'9'", printf, "%d\n", isdigit('9'));
test( "0", printf, "%d\n", ft_isdigit(0));
expect("0", printf, "%d\n", isdigit(0));
test( "1", printf, "%d\n", ft_isdigit(1));
expect("1", printf, "%d\n", isdigit(1));
test( "127", printf, "%d\n", ft_isdigit(127));
expect("127", printf, "%d\n", isdigit(127));
return 0;
j
}