Implement subtraction in evaluator
This commit is contained in:
@@ -116,6 +116,25 @@ static void sum_of_the_sum_of_4_and_66_and_83_evaluates_to_153(void)
|
||||
ASSERT_EQUAL(153, result);
|
||||
}
|
||||
|
||||
static void subtraction_of_56_from_88_evaluates_to_32(void)
|
||||
{
|
||||
init_memory_pool(&pool);
|
||||
expression_t *operand0 = allocate_expression(&pool);
|
||||
operand0->is_number = true;
|
||||
operand0->number = 88;
|
||||
expression_t *operand1 = allocate_expression(&pool);
|
||||
operand1->is_number = true;
|
||||
operand1->number = 56;
|
||||
expression_t *expression = allocate_expression(&pool);
|
||||
expression->is_number = false;
|
||||
expression->application.operator= OPERATOR_SUBTRACT;
|
||||
expression->application.operands[0] = operand0;
|
||||
expression->application.operands[1] = operand1;
|
||||
|
||||
const int result = evaluate(expression);
|
||||
ASSERT_EQUAL(32, result);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TESTING_BEGIN();
|
||||
@@ -125,5 +144,6 @@ int main(void)
|
||||
RUN_TEST(sum_of_72_and_6_evaluates_to_78);
|
||||
RUN_TEST(sum_of_21_and_the_sum_of_9_and_31_evaluates_to_61);
|
||||
RUN_TEST(sum_of_the_sum_of_4_and_66_and_83_evaluates_to_153);
|
||||
RUN_TEST(subtraction_of_56_from_88_evaluates_to_32);
|
||||
TESTING_END();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user