improve tests flags
This commit is contained in:
7
Makefile
7
Makefile
@@ -103,11 +103,12 @@ $(NAME): $(OBJS)
|
|||||||
$(CC) $(OBJS) -o $@ $(LFLAGS)
|
$(CC) $(OBJS) -o $@ $(LFLAGS)
|
||||||
|
|
||||||
run: $(NAME)
|
run: $(NAME)
|
||||||
@echo $(B_PURPLE)"\n---------------------------------------------\n1. degree 2 \n"$(RESET)
|
@echo $(B_PURPLE)"\n---------------------------------------------\nlaunch tests in read-only\n"$(RESET)
|
||||||
-./$(NAME) -b -d "3x² + 5x - 2 = 5x"
|
-@bash tester.sh --run-only -b
|
||||||
|
|
||||||
test: $(NAME)
|
test: $(NAME)
|
||||||
bash tester.sh
|
@echo $(B_PURPLE)"\n---------------------------------------------\nlaunch tests\n"$(RESET)
|
||||||
|
-@bash tester.sh
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM_OBJS)
|
$(RM_OBJS)
|
||||||
|
|||||||
26
src/solver.c
26
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)
|
void solve(const s_polynom *polynom, s_solution *solution)
|
||||||
{
|
{
|
||||||
double a;
|
double power2;
|
||||||
double b;
|
double power1;
|
||||||
double c;
|
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)
|
if (solution->degree == 1)
|
||||||
{
|
{
|
||||||
a = get_coefficient_of_power(1, polynom);
|
solve_degree_1(&solution->solution_degree_1, power1, power0);
|
||||||
b = get_coefficient_of_power(0, polynom);
|
|
||||||
|
|
||||||
solve_degree_1(&solution->solution_degree_1, a, b);
|
|
||||||
}
|
}
|
||||||
else if (solution->degree == 2)
|
else if (solution->degree == 2)
|
||||||
{
|
{
|
||||||
a = get_coefficient_of_power(2, polynom);
|
if (is_nearly_equal_zero(power1))
|
||||||
b = get_coefficient_of_power(1, polynom);
|
{
|
||||||
c = get_coefficient_of_power(0, polynom);
|
// solve_degree_2_pure(&solution->solution_degree_2, power2, power0);
|
||||||
|
}
|
||||||
solve_degree_2(&solution->solution_degree_2, a, b, c);
|
else
|
||||||
|
solve_degree_2(&solution->solution_degree_2, power2, power1, power0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
33
tester.sh
33
tester.sh
@@ -30,16 +30,31 @@ RESET="\e[0m"
|
|||||||
|
|
||||||
NAME="computor"
|
NAME="computor"
|
||||||
BINARY="./$NAME"
|
BINARY="./$NAME"
|
||||||
SKIP_REDUCED=true
|
|
||||||
SKIP_SOLUTION=true
|
|
||||||
|
|
||||||
if [[ ! -x "$BINARY" ]]; then
|
if [[ ! -x "$BINARY" ]]; then
|
||||||
|
|
||||||
echo -e >&2 $B_RED"Error:$RESET binary $B_PURPLE'$BINARY'$RESET not found or not executable."
|
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?"
|
echo >&2 "Did you compile your C program?"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
# TEST LOGIC
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
@@ -50,10 +65,20 @@ run_test() {
|
|||||||
local expected="$3"
|
local expected="$3"
|
||||||
local check_error="${4:-no_error}" # Default: false (compare output)
|
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"
|
printf $B_PURPLE"Test : '%s'$RESET - " "$test_name"
|
||||||
|
|
||||||
# Run the program and capture the output
|
# Run the program and capture the output
|
||||||
out=$(printf "%s" "$input" | "$BINARY" 2>&1)
|
out=$(printf "%s" "$input" | "$BINARY" $FLAGS 2>&1)
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
|
|
||||||
# If SKIP_REDUCED is true, remove the "Reduced form" line from both output and expected
|
# If SKIP_REDUCED is true, remove the "Reduced form" line from both output and expected
|
||||||
|
|||||||
Reference in New Issue
Block a user