🇪🇸 Español: Existe una versión en español de este documento disponible en README_es.md.
This repository contains a set of Python scripts designed to test, analyze, and measure the performance of the push_swap project from 42.
The scripts automate random number generation, execution of your program, and validation with the checker, providing detailed statistics on the move count.
Ensure you have the following files in the same directory where you execute the scripts:
push_swap: Your compiled executable.checker_linux: The checker binary provided by 42 (make sure it has execution permissions:chmod +x checker_linux).- Python 3: To run the scripts.
Tip 💡: All scripts include shebangs (
#!/usr/bin/env python3). If you give them execution permissions withchmod +x *.py, you can run them directly (e.g.,./performance_analysis.py) without typingpython3.
Note: The scripts are configured to use
./checker_linux. If you wish to use the MacOS checker, you will need to modify the corresponding line in the.pyfiles.
This is the main script for obtaining detailed performance metrics. It calculates the minimum, maximum, average, and standard deviation of moves.
Default usage (runs 100 tests of 100 numbers and 100 tests of 500 numbers):
python3 performance_analysis.pyCustom usage: You can specify the amount of numbers and the number of iterations:
# Syntax: python3 performance_analysis.py [NUMBER_COUNT] [ITERATIONS]
# Example: Analyze 100 numbers with 500 tests
python3 performance_analysis.py 100 500If the program detects failures (KO), it will save the failed cases in ko_cases.txt.
Runs multiple tests increasing the stack size and generates a graph (performance_graph.png) to verify the complexity of your algorithm.
- Requirements: Needs
matplotlib(pip install matplotlib). - Function: Running it creates a graph with average, min, and max moves.
# Default (10 to 500 elements, step 50)
python3 visual_analysis.py
# Custom (e.g., specific range and more samples)
python3 visual_analysis.py --min 5 --max 500 --step 50 --samples 20Performs a basic and quick check.
- Runs 20 global iterations.
- In each iteration, it tests: 100 numbers, 500 numbers, and a random size (6-100).
- It stops immediately if an error is found.
python3 fuzz_test.pyFocuses on intensive testing of small cases and random cases.
- Intensive tests: Sizes from 6 to 20 (50 tests per size).
- Random tests: 100 tests with varied sizes (6-100).
python3 fuzz_test_v2.pyTests special cases and extremes.
- Reverse sorted lists (sizes 6 to 100).
- "Almost sorted" lists (only 2 elements swapped).
python3 fuzz_test_v3.py- Compile your
push_swapproject:make
- Make sure you have
checker_linuxin the root directory. - Run the performance analysis:
python3 performance_analysis.py
The analysis script will give you output like this:
- Min Moves: The best execution (fewest moves).
- Max Moves: The worst execution. Important to know if you pass the evaluation limits.
- Mean (Avg): The average number of moves.
- Std Dev: Standard deviation (how much your results vary; ideally it should be low).
- Runs > Limit: Percentage of tests that exceed the acceptable limit (700 for 100 numbers, 5500 for 500).
Good luck with your evaluation! 🐬
Contributions are highly welcome and are crucial for improving the quality of this test suite! If you encounter any issue, please open an issue in this repository.
- Report an Issue: Open a new Issues tab on GitHub and describe the error you found, including the exact test case that is failing or missing.
- Submit a Pull Request (Optional): If you have created a new test to fix the problem, you can directly submit a Pull Request for us to review and integrate. Your collaboration ensures that this test suite is as robust and complete as possible for the entire community.
This project is licensed under a non-commercial educational use license.
Key Points:
- ✅ Educational use, study, and personal modifications are allowed
- ✅ You can fork this repository for learning purposes
- ❌ Commercial use or monetization is prohibited
- ❌ Redistribution as part of a commercial product is not allowed
For full details, please see the LICENSE file in the repository root.
If you need permission for commercial use, please contact the author at: 05yaqi.liu@gmail.com