Welcome to the ft_printf Tester! This tool is designed to rigorously test your custom implementation of the ft_printf function against the standard printf function. With comprehensive test cases, color-coded output, and a detailed summary, this tester ensures your implementation is accurate and reliable.
This project originated from a fellow student, and we've worked together to improve it further. We hope it serves as a valuable resource for others in their journey with ft_printf.
- π― Features
- π» Requirements
- βοΈ Installation
- π Usage
- π§ͺ Test Coverage
- π Understanding the Output
- π§ Compilation Options
- π€ Contributing
- π License
- Comprehensive Test Suite: Tests a wide range of format specifiers and edge cases to ensure your
ft_printfbehaves as expected. - π’π₯ Color-Coded Output: Easy-to-read results, with green for passed tests π’ and red for failed tests π₯.
- π Summary Report: A final summary showing the total number of passed and failed tests.
- π Extensible: Add new test cases easily by modifying
main.c.
- A working implementation of the
ft_printffunction. - A C compiler like
gcc. - The
libftprintf.astatic library file generated from yourft_printfimplementation (if you usedlibft).
git clone [email protected]:kitearuba/printf_basic_tester.git printf-tester
cd printf-testerEnsure you have compiled your ft_printf implementation and generated the libftprintf.a file in the root directory.
Place main.c, libftprintf.a, and your header files (ft_printf.h, libft.h) in the appropriate directories.
Depending on whether or not you used libft in your project, follow the appropriate compilation steps:
If your ft_printf implementation relies on functions from the libft library:
gcc printf_main_tester.c -I./include/ -I./libft/ -L. -lftprintf -o testerIf your ft_printf implementation does not rely on the libft library:
gcc printf_main_tester.c -I./include/ -L. -lftprintf -o tester./testerThis will execute all the tests and print the results directly in your terminal with color-coded output for easy review.
The tester includes a variety of test cases designed to thoroughly assess your ft_printf implementation:
- Basic Characters (
%c): Tests the printing of standard characters likeA. - Null Character: Tests how
ft_printfhandles the null character (\0). - Special Characters: Includes newline (
\n), tab (\t), and other escape sequences to ensure correct handling.
- Basic Strings (
%s): Simple strings to check standard output. - Empty Strings: Ensures your implementation handles empty strings (
"") correctly. - Long Strings: Tests the ability to handle and correctly print long strings.
- Special Characters in Strings: Includes escape sequences within strings to check for correct interpretation.
- Valid Pointers (
%p): Tests the correct printing of memory addresses. - NULL Pointers: Ensures
ft_printfhandlesNULLpointers correctly, typically printing(nil)or an equivalent representation.
- Positive Integers (
%dand%i): Verifies correct printing of standard positive integers. - Negative Integers: Tests the handling of negative values.
- Edge Cases: Includes
INT_MAXandINT_MINto check for boundary conditions.
- Standard Unsigned Integers (
%u): Verifies the correct printing of unsigned integers. - Edge Cases: Includes
UINT_MAXto ensure that your implementation handles the upper boundary of unsigned integers.
- Lowercase Hex (
%x): Tests the conversion of integers to lowercase hexadecimal. - Uppercase Hex (
%X): Tests the conversion of integers to uppercase hexadecimal. - Zero Value: Ensures correct handling of zero in hexadecimal format.
- NULL with
%s: Tests howft_printfhandlesNULLpointers with the%sformat specifier, which should typically print(null)or an equivalent. - Escape Sequences: Tests various escape sequences (like
\\n,\\t,\\r) to ensure correct output. - Complex Format Strings: Combines various specifiers in one format string to ensure
ft_printfhandles complex scenarios correctly.
- π’ PASS: The output of
ft_printfmatches the output ofprintf. - π₯ FAIL: The outputs do not match, indicating an issue.
π’ PASS: Basic %c
π₯ FAIL: Null %c
...
Summary:
π’ Passed: 20
π₯ Failed: 2After all tests are executed, you'll see a summary showing how many tests passed and how many failed. This helps you quickly assess the overall accuracy of your ft_printf implementation.
If your ft_printf implementation does not rely on the libft library, you can compile the tester without linking libft by omitting the -I./libft/ and relying solely on the necessary includes for ft_printf.
gcc main.c -I./include/ -L. -lftprintf -o testerThis will ensure that your tester is correctly set up even if you did not incorporate the libft library into your project.
We welcome contributions! If you find a bug, have suggestions for improvement, or want to add additional test cases, feel free to open an issue or submit a pull request.
- Fork the Repository
- Create a New Branch
git checkout -b feature-or-fix
- Commit Your Changes
git commit -m "Add feature or fix" - Push to Your Branch
git push origin feature-or-fix
- Open a Pull Request
This project is licensed under the MIT License. For more details, see the LICENSE file.
Ensure your terminal supports ANSI escape codes for the color coding to display correctly. Most modern terminals do, but if you encounter issues, consider testing in a different terminal environment.