This is a testing script for the Push_swap project at 42 School, developed by rmarrero from 42 Barcelona. The script allows you to evaluate the performance of your push_swap
implementation with different list sizes (3, 5, 100, and 500 numbers) and a configurable number of attempts.
- Push_swap Project: Ensure your
push_swap
project is compiled and ready to use. - Checker: The script uses a
checker
program to verify if the operations performed bypush_swap
are correct. Make sure thechecker
is in the same directory as the script. - Python 3: The script uses a visualization script (
visual.py
) that requires Python 3 to display errors graphically.
- Clone the repository or download the script to your working environment.
- Compile your
push_swap
project:cd /path/to/your/push_swap make re
- Navigate to the tester directory:
cd /path/to/push_swap_tester
- Run the script:
./push_swap_tester.sh [NUMBER_OF_ATTEMPTS]
- If you don't provide a number of attempts, the default value is 1000.
- The script generates random lists of 3 numbers and runs your
push_swap
. - It verifies that the number of moves does not exceed the allowed threshold (2 moves).
- If the result is incorrect, an error visualization is displayed.
- Similar to the 3-number case, but with a threshold of 12 moves.
- Generates random lists of 100 numbers.
- Assigns points based on the average number of moves:
- Less than 700 moves: 5 points.
- Less than 900 moves: 4 points.
- Less than 1100 moves: 3 points.
- Less than 1300 moves: 2 points.
- Less than 1500 moves: 1 point.
- More than 1500 moves: 0 points.
- Generates random lists of 500 numbers.
- Assigns points based on the average number of moves:
- Less than 5500 moves: 5 points.
- Less than 7000 moves: 4 points.
- Less than 8500 moves: 3 points.
- Less than 10000 moves: 2 points.
- Less than 11500 moves: 1 point.
- More than 11500 moves: 0 points.
- If the
checker
detects an error, the script runs a visualizer (visual.py
) to display the failed combination.
- The script includes loading animations and colorful completion messages for a better user experience.
At the end of the execution, the script displays:
- The minimum, maximum, and average number of moves for each list size.
- The points earned in each category.
- A final score based on the accumulated points.
Example output:
--- Final Result ---
Points for 3 numbers: 5
Points for 5 numbers: 5
Points for 100 numbers: 4
Points for 500 numbers: 3
==================================
== Final Score: 17! ==
==================================
- The script stops immediately if an error is detected in any test case.
- You can adjust the number of attempts by passing a different value as an argument when running the script.
- The visualizer (
visual.py
) is optional but helpful for debugging failed combinations.
- Developed by rmarrero from 42 Barcelona.
- Designed for 42 School students to test their
push_swap
projects efficiently.
Enjoy testing your push_swap
! 🚀
This script is designed to test the push_swap
program, which is a sorting algorithm project. The script generates random numbers, runs the push_swap
program with these numbers, and checks the results using the checker
program. It then calculates statistics such as the minimum, maximum, and average number of operations, as well as the success rate.
The script performs the following tasks:
- Generates random numbers within a specified range.
- Runs the
push_swap
program with the generated numbers. - Checks the output of
push_swap
using thechecker
program. - Calculates statistics such as the minimum, maximum, and average number of operations.
- Displays the results in a colored format for better readability.
To use the script, run the following command in your terminal:
./script_name.sh <range> <moves_threshold> [number_of_cases]
Parameter | Description |
---|---|
<range> |
The number of random integers to generate. |
<moves_threshold> |
The maximum number of moves allowed for the push_swap program to be considered successful. |
[number_of_cases] |
(Optional) The number of test cases to run. Default is 10,000. |
-
Input Validation:
- The script checks if the correct number of arguments is provided. If not, it displays a usage message and exits.
-
Random Number Generation:
- For each test case, the script generates a set of random integers within the specified range using
awk
and a unique seed.
- For each test case, the script generates a set of random integers within the specified range using
-
Running
push_swap
:- The generated numbers are passed to the
push_swap
program, and the output is saved totest.txt
.
- The generated numbers are passed to the
-
Checking Results:
- The output of
push_swap
is piped into thechecker
program, which verifies if the sorting was successful. The result is saved tochecker.txt
.
- The output of
-
Statistics Calculation:
- The script calculates the number of operations performed by
push_swap
. - It updates the minimum, maximum, and average number of operations.
- It also tracks the number of successful test cases.
- The script calculates the number of operations performed by
-
Output:
- The script prints the results of each test case in colored text (green for success, red for failure).
- At the end, it displays a summary of the statistics.
The script outputs the following:
-
For each test case:
[OK]
or[KO]
indicating success or failure.- The number of operations performed.
- The current average number of operations.
- The generated numbers.
-
At the end of the script:
- A summary with the minimum, maximum, and average number of operations.
- The success rate (number of successful test cases / total test cases).
push_swap
: The program to be tested. It should be located in the parent directory (../push_swap
).checker
: The program used to verify the output ofpush_swap
. It should be located in the current directory (./checker
).awk
: Used for generating random numbers.wc
: Used to count the number of lines in the output file.
To test push_swap
with 100 random numbers, a move threshold of 700, and 500 test cases, run:
./script_name.sh 100 700 500
[OK] 650 (Promedio: 655) 123 456 789 ...
[KO] 710 (Promedio: 660) 987 654 321 ...
...
Resumen para rango 100:
Mínimo: 600 | Máximo: 720 | Promedio: 655 | Puntos: 480/500
- Ensure that
push_swap
andchecker
are compiled and accessible from the script's location. - The script uses colored output for better readability. If your terminal does not support colors, you may see escape codes instead.