add test for equal

This commit is contained in:
hugogogo
2026-05-14 13:42:25 +02:00
parent 7b5aa97c0c
commit 201f2fa0ce
3 changed files with 16 additions and 15 deletions

View File

@@ -3,7 +3,6 @@
## todo
- if no "=" sign return error
- doing gcd for int values, and not for double values
- double is nearly_equal_0

View File

@@ -220,7 +220,9 @@ void lexerize(const char *input, s_token *tokens)
int tokens_count;
int input_pos;
int token_size;
bool has_equal;
has_equal = false;
tokens_count = 0;
input_pos = 0;
while (input[input_pos])
@@ -288,6 +290,7 @@ void lexerize(const char *input, s_token *tokens)
}
else if (token_is_equal(input, input_pos, &token_size))
{
has_equal = true;
tokens[tokens_count].type = TOKEN_EQUAL;
tokens[tokens_count].tag = TOKEN_NO_TAG;
tokens[tokens_count].value_char = '=';
@@ -305,6 +308,9 @@ void lexerize(const char *input, s_token *tokens)
input_pos += token_size;
}
if (!has_equal)
stop_errors("the input polynomial does not contains an equal sign, it's an expression not an equation.\n");
tokens[tokens_count].type = TOKEN_END;
tokens[tokens_count].tag = TOKEN_NO_TAG;
tokens[tokens_count].value_char = '\0';

View File

@@ -73,12 +73,10 @@ run_test() {
fi
fi
# If check_error is true, verify if the output contains an error message or non-zero exit code
if [[ "$check_error" == "error" ]]; then
if [[ $exit_code -ne 0 || "$out" == *"Error"* ]]; then
printf $B_GREEN"PASS$RESET\n"
printf $B_GREEN"PASS$RESET (Input: '%s')\n" "$input"
else
printf $B_RED"FAIL$RESET\n"
printf " "$B_WHITE"Input:$RESET '%s'\n" "$input"
@@ -90,7 +88,7 @@ run_test() {
else
# Compare with expected output
if [[ "$out" == "$expected" ]]; then
printf $B_GREEN"PASS$RESET\n"
printf $B_GREEN"PASS$RESET (Input: '%s')\n" "$input"
else
printf $B_RED"FAIL$RESET\n"
printf " "$B_WHITE"Input:$RESET '%s'\n" "$input"
@@ -136,8 +134,8 @@ Discriminant is strictly positive, the two solutions are:
run_test \
"4. flag -e" \
'-e "3 * x^2 + 2 * x - 7 * x^4 = 1 * x^4"' "\
" \
'-e "3 * x^2 + 2 * x - 7 * x^4 = 1 * x^4"' \
"" \
error
run_test \
@@ -160,8 +158,8 @@ Discriminant is strictly negative, the two complex solutions are:
run_test \
"7. float exponent" \
"3.4 * x^2 + 1 * x^1 - 2.0 * x^0 = 5 * x^1.2" "\
" \
"3.4 * x^2 + 1 * x^1 - 2.0 * x^0 = 5 * x^1.2" \
"" \
error
run_test \
@@ -280,12 +278,10 @@ The solution is:
0.75"
run_test \
"23. degree 2" \
"3x^2" "\
Reduced form: 0 * x^0 + 0 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Discriminant is equal to zero, the solution is:
0"
"23. degree 2 without [=]" \
"3x^2" \
"" \
error
run_test \
"24. degree 2" \