From 840f5bcfdf41e6278a7a6852c8ebd475c244cab4 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Thu, 14 May 2026 21:33:44 +0200 Subject: [PATCH] improve tests flags --- Makefile | 7 ++++--- src/solver.c | 26 ++++++++++++++------------ tester.sh | 33 +++++++++++++++++++++++++++++---- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 8d7c398..73861e6 100644 --- a/Makefile +++ b/Makefile @@ -103,11 +103,12 @@ $(NAME): $(OBJS) $(CC) $(OBJS) -o $@ $(LFLAGS) run: $(NAME) - @echo $(B_PURPLE)"\n---------------------------------------------\n1. degree 2 \n"$(RESET) - -./$(NAME) -b -d "3x² + 5x - 2 = 5x" + @echo $(B_PURPLE)"\n---------------------------------------------\nlaunch tests in read-only\n"$(RESET) + -@bash tester.sh --run-only -b test: $(NAME) - bash tester.sh + @echo $(B_PURPLE)"\n---------------------------------------------\nlaunch tests\n"$(RESET) + -@bash tester.sh clean: $(RM_OBJS) diff --git a/src/solver.c b/src/solver.c index 9111745..dfd8e9d 100644 --- a/src/solver.c +++ b/src/solver.c @@ -122,23 +122,25 @@ static void solve_degree_2(s_solution_degree_2 *solution, double a, double b, do void solve(const s_polynom *polynom, s_solution *solution) { - double a; - double b; - double c; + double power2; + double power1; + double power0; + + power2 = get_coefficient_of_power(2, polynom); + power1 = get_coefficient_of_power(1, polynom); + power0 = get_coefficient_of_power(0, polynom); if (solution->degree == 1) { - a = get_coefficient_of_power(1, polynom); - b = get_coefficient_of_power(0, polynom); - - solve_degree_1(&solution->solution_degree_1, a, b); + solve_degree_1(&solution->solution_degree_1, power1, power0); } else if (solution->degree == 2) { - a = get_coefficient_of_power(2, polynom); - b = get_coefficient_of_power(1, polynom); - c = get_coefficient_of_power(0, polynom); - - solve_degree_2(&solution->solution_degree_2, a, b, c); + if (is_nearly_equal_zero(power1)) + { + // solve_degree_2_pure(&solution->solution_degree_2, power2, power0); + } + else + solve_degree_2(&solution->solution_degree_2, power2, power1, power0); } } diff --git a/tester.sh b/tester.sh index ba4f65f..9418b4d 100644 --- a/tester.sh +++ b/tester.sh @@ -30,16 +30,31 @@ RESET="\e[0m" NAME="computor" BINARY="./$NAME" -SKIP_REDUCED=true -SKIP_SOLUTION=true if [[ ! -x "$BINARY" ]]; then - echo -e >&2 $B_RED"Error:$RESET binary $B_PURPLE'$BINARY'$RESET not found or not executable." echo >&2 "Did you compile your C program?" exit 1 fi +# flags +SKIP_REDUCED=false +SKIP_SOLUTION=false +RUN_ONLY=false +FLAGS="" # default empty + +# Parse command-line arguments +while [[ "$#" -gt 0 ]]; do + case $1 in + --skip-reduced) SKIP_REDUCED=true ;; + --skip-solution) SKIP_SOLUTION=true ;; + --run-only) RUN_ONLY=true ;; + -b) FLAGS="$FLAGS -b" ;; # append -b to FLAGS + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift +done + # ---------------------------------------------------------------------- # TEST LOGIC # ---------------------------------------------------------------------- @@ -50,10 +65,20 @@ run_test() { local expected="$3" local check_error="${4:-no_error}" # Default: false (compare output) + # If RUN_ONLY is true, skip all test logic and just run the binary + if [[ "$RUN_ONLY" == "true" ]]; then + printf $B_PURPLE"Running: '%s'$RESET\n" "$test_name" + printf "Input: '%s'\n" "$input" + printf "Output:\n" + printf "%s" "$input" | "$BINARY" $FLAGS 2>&1 + printf "\n" + return + fi + printf $B_PURPLE"Test : '%s'$RESET - " "$test_name" # Run the program and capture the output - out=$(printf "%s" "$input" | "$BINARY" 2>&1) + out=$(printf "%s" "$input" | "$BINARY" $FLAGS 2>&1) exit_code=$? # If SKIP_REDUCED is true, remove the "Reduced form" line from both output and expected