improve tests flags

This commit is contained in:
hugogogo
2026-05-14 21:33:44 +02:00
parent 31469af23f
commit 840f5bcfdf
3 changed files with 47 additions and 19 deletions

View File

@@ -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)

View File

@@ -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);
}
}

View File

@@ -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