add test for equal
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
## todo
|
## todo
|
||||||
|
|
||||||
- if no "=" sign return error
|
- if no "=" sign return error
|
||||||
- doing gcd for int values, and not for double values
|
|
||||||
- double is nearly_equal_0
|
- double is nearly_equal_0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -220,7 +220,9 @@ void lexerize(const char *input, s_token *tokens)
|
|||||||
int tokens_count;
|
int tokens_count;
|
||||||
int input_pos;
|
int input_pos;
|
||||||
int token_size;
|
int token_size;
|
||||||
|
bool has_equal;
|
||||||
|
|
||||||
|
has_equal = false;
|
||||||
tokens_count = 0;
|
tokens_count = 0;
|
||||||
input_pos = 0;
|
input_pos = 0;
|
||||||
while (input[input_pos])
|
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))
|
else if (token_is_equal(input, input_pos, &token_size))
|
||||||
{
|
{
|
||||||
|
has_equal = true;
|
||||||
tokens[tokens_count].type = TOKEN_EQUAL;
|
tokens[tokens_count].type = TOKEN_EQUAL;
|
||||||
tokens[tokens_count].tag = TOKEN_NO_TAG;
|
tokens[tokens_count].tag = TOKEN_NO_TAG;
|
||||||
tokens[tokens_count].value_char = '=';
|
tokens[tokens_count].value_char = '=';
|
||||||
@@ -305,6 +308,9 @@ void lexerize(const char *input, s_token *tokens)
|
|||||||
input_pos += token_size;
|
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].type = TOKEN_END;
|
||||||
tokens[tokens_count].tag = TOKEN_NO_TAG;
|
tokens[tokens_count].tag = TOKEN_NO_TAG;
|
||||||
tokens[tokens_count].value_char = '\0';
|
tokens[tokens_count].value_char = '\0';
|
||||||
|
|||||||
24
tester.sh
24
tester.sh
@@ -73,12 +73,10 @@ run_test() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# If check_error is true, verify if the output contains an error message or non-zero exit code
|
# If check_error is true, verify if the output contains an error message or non-zero exit code
|
||||||
if [[ "$check_error" == "error" ]]; then
|
if [[ "$check_error" == "error" ]]; then
|
||||||
if [[ $exit_code -ne 0 || "$out" == *"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
|
else
|
||||||
printf $B_RED"FAIL$RESET\n"
|
printf $B_RED"FAIL$RESET\n"
|
||||||
printf " "$B_WHITE"Input:$RESET '%s'\n" "$input"
|
printf " "$B_WHITE"Input:$RESET '%s'\n" "$input"
|
||||||
@@ -90,7 +88,7 @@ run_test() {
|
|||||||
else
|
else
|
||||||
# Compare with expected output
|
# Compare with expected output
|
||||||
if [[ "$out" == "$expected" ]]; then
|
if [[ "$out" == "$expected" ]]; then
|
||||||
printf $B_GREEN"PASS$RESET\n"
|
printf $B_GREEN"PASS$RESET (Input: '%s')\n" "$input"
|
||||||
else
|
else
|
||||||
printf $B_RED"FAIL$RESET\n"
|
printf $B_RED"FAIL$RESET\n"
|
||||||
printf " "$B_WHITE"Input:$RESET '%s'\n" "$input"
|
printf " "$B_WHITE"Input:$RESET '%s'\n" "$input"
|
||||||
@@ -136,8 +134,8 @@ Discriminant is strictly positive, the two solutions are:
|
|||||||
|
|
||||||
run_test \
|
run_test \
|
||||||
"4. flag -e" \
|
"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
|
error
|
||||||
|
|
||||||
run_test \
|
run_test \
|
||||||
@@ -160,8 +158,8 @@ Discriminant is strictly negative, the two complex solutions are:
|
|||||||
|
|
||||||
run_test \
|
run_test \
|
||||||
"7. float exponent" \
|
"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
|
error
|
||||||
|
|
||||||
run_test \
|
run_test \
|
||||||
@@ -280,12 +278,10 @@ The solution is:
|
|||||||
0.75"
|
0.75"
|
||||||
|
|
||||||
run_test \
|
run_test \
|
||||||
"23. degree 2" \
|
"23. degree 2 without [=]" \
|
||||||
"3x^2" "\
|
"3x^2" \
|
||||||
Reduced form: 0 * x^0 + 0 * x^1 + 3 * x^2 = 0
|
"" \
|
||||||
Polynomial degree: 2
|
error
|
||||||
Discriminant is equal to zero, the solution is:
|
|
||||||
0"
|
|
||||||
|
|
||||||
run_test \
|
run_test \
|
||||||
"24. degree 2" \
|
"24. degree 2" \
|
||||||
|
|||||||
Reference in New Issue
Block a user