Skip to content

Instantly share code, notes, and snippets.

@gbarrancos
Created April 28, 2011 21:48
Show Gist options
  • Save gbarrancos/947422 to your computer and use it in GitHub Desktop.
Save gbarrancos/947422 to your computer and use it in GitHub Desktop.
An example of a CuTest-based unit test
#include <stdlib.h>
#include <stdio.h>
#include "CuTest.h"
#include "../ep2_gustavob.h"
/********* Infix to Postfix Conversion *********/
void test_single_expr (CuTest* testContext) {
char actual[BUF_SIZE];
char *expression = "(5 + 5)";
char *expected = "5 5 + ";
infix_to_postfix(expression, actual);
CuAssertStrEquals(testContext, expected, actual);
}
void test_parens_multi_expr (CuTest* testContext) {
char actual[BUF_SIZE];
char *expression = "(5 * (((9 + 8) * (4 * 6)) + 7))";
char *expected = "5 9 8 + 4 6 * * 7 + * ";
infix_to_postfix(expression, actual);
CuAssertStrEquals(testContext, expected, actual);
}
void test_multi_digit_numbers_expr(CuTest* testContext) {
char actual[BUF_SIZE];
char *expression = "((20 * 3) * (10 + 10)) / 2))";
char *expected = "20 3 * 10 10 + * 2 / ";
infix_to_postfix(expression, actual);
CuAssertStrEquals(testContext, expected, actual);
}
CuSuite* test_suite() {
CuSuite* suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_single_expr);
SUITE_ADD_TEST(suite,test_parens_multi_expr);
SUITE_ADD_TEST(suite, test_multi_digit_numbers_expr);
return suite;
}
void all_tests()
{
CuString *output = CuStringNew();
CuSuite* suite = CuSuiteNew();
CuSuiteAddSuite(suite, test_suite());
CuSuiteRun(suite);
CuSuiteSummary(suite, output);
CuSuiteDetails(suite, output);
printf("%s\n", output->buffer);
}
int main()
{
all_tests();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment