aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-21 20:04:37 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-21 20:04:37 +0100
commita41bf1c4c3e7e4b4642bee5f6e5aafbdb8f29773 (patch)
treec0fc9a878ed4a1c1feba18830828842efbfe1f17
parentaaba527e44d763c83d0109e833150d4c0e6d4e56 (diff)
downloadpush_swap-a41bf1c4c3e7e4b4642bee5f6e5aafbdb8f29773.tar.gz
push_swap-a41bf1c4c3e7e4b4642bee5f6e5aafbdb8f29773.tar.bz2
push_swap-a41bf1c4c3e7e4b4642bee5f6e5aafbdb8f29773.zip
Removed buged feature in sort and added short test script
-rw-r--r--src/push_swap/sort.c7
-rwxr-xr-xtest.sh77
2 files changed, 77 insertions, 7 deletions
diff --git a/src/push_swap/sort.c b/src/push_swap/sort.c
index 4804591..e1a9bca 100644
--- a/src/push_swap/sort.c
+++ b/src/push_swap/sort.c
@@ -88,13 +88,6 @@ static void push_swap_qsort_rec(t_stack *main, t_stack *tmp, int main_frame, int
{
if (frame_length(main, main_frame) < 2)
return ;
- if (frame_length(main, main_frame) == 2)
- {
- if (main->tag == STACK_A ? stack_peek(main) > main->elements[stack_length(main) - 1] :
- stack_peek(main) < main->elements[stack_length(main) - 1])
- stack_swap(main);
- return ;
- }
push_swap_qsort_partition(main, tmp, main_frame);
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..1c7fa9b
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+if [ $# -lt 1 ]; then
+ echo "Usage $0 test_number [start] [end]"
+ exit
+fi
+
+if [ $1 = "--error" ]; then
+ echo -n "No arguments: "
+ if [ $(./checker)="" ]; then
+ echo -n "\033[32m[OK]\033[0m "
+ else
+ echo -n "\033[32m[KO]\033[0m "
+ fi
+ if [ $(./push_swap)="" ]; then
+ echo "\033[32m[OK]\033[0m"
+ else
+ echo "\033[32m[KO]\033[0m"
+ fi
+
+ echo -n "Not digit character "
+ if [ ! $(./checker 1 2 3 four)="Error\n" ]; then
+ echo -n "\033[32m[OK]\033[0m "
+ else
+ echo -n "\033[32m[KO]\033[0m "
+ fi
+ if [ ! $(./checker -1 2 3-3)="Error\n" ]; then
+ echo -n "\033[32m[OK]\033[0m "
+ else
+ echo -n "\033[32m[KO]\033[0m "
+ fi
+ if [ ! $(./checker 1_000 23 0 -1)="Error\n" ]; then
+ echo -n "\033[32m[OK]\033[0m "
+ else
+ echo -n "\033[32m[KO]\033[0m "
+ fi
+
+ exit
+fi
+
+test_nb=$1
+
+if [ -z $2 ]; then
+ start=1
+else
+ start=$2
+fi
+
+if [ -z $3 ]; then
+ end=100
+else
+ end=$3
+fi
+
+for i in $(seq 1 $test_nb); do
+ arg=$(./random_stack.rb $start $end)
+ echo $arg
+ result=$(./push_swap $arg | ./checker $arg)
+
+ case $result in
+ OK)
+ echo -n "\033[32m.\033[0m"
+ ;;
+ KO)
+ echo -n "\033[31m!\033[0m"
+ echo "Test $i failed with: $arg" >> result.log
+ ;;
+ Error)
+ echo -n "\033[31m!\033[0m"
+ echo "Test $i failed due to parsing error with: $arg" >> result.log
+ ;;
+ *)
+ echo "Unexpected output"
+ exit
+ ;;
+ esac
+done