feat: added tests
This commit is contained in:
parent
a7b7cda496
commit
f3377656e4
6 changed files with 234 additions and 10 deletions
61
tests/output.c
Normal file
61
tests/output.c
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#include "test.h"
|
||||
#include "libft.h"
|
||||
|
||||
TEST(test_putchar) {
|
||||
int ret = ft_putchar('A');
|
||||
ASSERT(ret == 1); // Should print 'A'
|
||||
}
|
||||
|
||||
TEST(test_putstr) {
|
||||
int ret = ft_putstr("Hello");
|
||||
ASSERT(ret == 5); // Should print 'Hello'
|
||||
ret = ft_putstr(NULL);
|
||||
ASSERT(ret == 6 || ret == 0); // Depending on your implementation: "(null)" or nothing
|
||||
}
|
||||
|
||||
TEST(test_putnbr) {
|
||||
int ret = ft_putnbr(42);
|
||||
ASSERT(ret == 2); // Should print "42"
|
||||
ret = ft_putnbr(-1234);
|
||||
ASSERT(ret == 5); // Should print "-1234"
|
||||
}
|
||||
|
||||
TEST(test_putunbr) {
|
||||
int ret = ft_putunbr(12345U);
|
||||
ASSERT(ret == 5); // Should print "12345"
|
||||
}
|
||||
|
||||
TEST(test_puthex) {
|
||||
int ret = ft_puthex(0x2A, 0);
|
||||
ASSERT(ret == 2); // Should print "2a"
|
||||
ret = ft_puthex(0x2A, 1);
|
||||
ASSERT(ret == 2); // Should print "2A"
|
||||
}
|
||||
|
||||
TEST(test_putaddr) {
|
||||
int ret = ft_putaddr(0x1234abcd);
|
||||
ASSERT(ret >= 3); // Should print "0x..." (at least 3 chars)
|
||||
}
|
||||
|
||||
TEST(test_putptr) {
|
||||
int x = 42;
|
||||
int ret = ft_putptr(&x);
|
||||
ASSERT(ret >= 3); // Should print "0x..." (at least 3 chars)
|
||||
}
|
||||
|
||||
TEST(test_printf) {
|
||||
int ret = ft_printf("Hello %s %d %x\n", "world", 42, 255);
|
||||
ASSERT(ret > 0); // Should print "Hello world 42 ff\n"
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
RUN_TEST(test_putchar);
|
||||
RUN_TEST(test_putstr);
|
||||
RUN_TEST(test_putnbr);
|
||||
RUN_TEST(test_putunbr);
|
||||
RUN_TEST(test_puthex);
|
||||
RUN_TEST(test_putaddr);
|
||||
RUN_TEST(test_putptr);
|
||||
RUN_TEST(test_printf);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue