Skip to content

Instantly share code, notes, and snippets.

@JeffHoover
Created September 28, 2016 20:24
Show Gist options
  • Save JeffHoover/4a04ac102f7710a406fc4a122635c4b0 to your computer and use it in GitHub Desktop.
Save JeffHoover/4a04ac102f7710a406fc4a122635c4b0 to your computer and use it in GitHub Desktop.
using struct in looping test of arabic-to-roman
#define DATA_COUNT 6
int arabic_values[DATA_COUNT] = { 1, 2, 3, 4, 5, 6};
char *roman_values[DATA_COUNT] = { "I", "II", "III", "IV", "V", "VI"};
typedef struct Roman_Arabic_pair {
char * roman;
int arabic;
} Roman_Arabic_pair;
void check_arabic_to_roman(const Roman_Arabic_pair test_data, const char *actualRoman)
{
ck_assert_msg(strcmp(actualRoman, test_data.roman) == 0,
"\ncompute_arabic_to_roman(%d): expected %s but was %s\n",
test_data.arabic, test_data.roman, actualRoman);
}
START_TEST(arabic_to_roman)
{
char actual_ToRoman_Result[20];
Roman_Arabic_pair expected_roman_arabic_pair =
{ .roman = roman_values[_i], .arabic = arabic_values[_i] };
// compute_arabic_to_roman(arabic_values[_i], actual_ToRoman_Result); // OLD WAY
compute_arabic_to_roman(expected_roman_arabic_pair.arabic, actual_ToRoman_Result);
// check_arabic_to_roman(arabic_values[_i], roman_values[_i], actual_ToRoman_Result); // OLD WAY
check_arabic_to_roman(expected_roman_arabic_pair, actual_ToRoman_Result);
}
END_TEST
TCase *tc_to_roman = tcase_create("ArabicToRoman");
tcase_add_loop_test(tc_to_roman, compute_arabic_to_roman, 0, DATA_COUNT);
suite_add_tcase(suite, tc_to_roman);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment