From 201f2fa0ce1bda480a49c8fdf39989c10e5d6084 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Thu, 14 May 2026 13:42:25 +0200 Subject: [PATCH] add test for equal --- README.md | 1 - src/lexer.c | 6 ++++++ tester.sh | 24 ++++++++++-------------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 558ee7e..9895bbd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/lexer.c b/src/lexer.c index 73ea0ba..1ce4413 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -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'; diff --git a/tester.sh b/tester.sh index 2309460..ba4f65f 100644 --- a/tester.sh +++ b/tester.sh @@ -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" \