#include "../../unity/unity.h" #include #include void setUp(void) { /* Setup code here, or leave empty */ } void tearDown(void) { /* Cleanup code here, or leave empty */ } /* Test that both uppercase 'K' and lowercase 'k' map to power 1. */ void test_suffix_power_k_variants(void) { TEST_ASSERT_EQUAL_INT(1, suffix_power('K')); TEST_ASSERT_EQUAL_INT(1, suffix_power('k')); } /* Test the full set of supported uppercase suffixes map to expected powers. */ void test_suffix_power_all_uppercase(void) { struct { char suf; int expected; } cases[] = { { 'M', 2 }, { 'G', 3 }, { 'T', 4 }, { 'P', 5 }, { 'E', 6 }, { 'Z', 7 }, { 'Y', 8 }, { 'R', 9 }, { 'Q', 10 }, }; for (size_t i = 0; i < sizeof(cases)/sizeof(cases[0]); i++) { TEST_ASSERT_EQUAL_INT(cases[i].expected, suffix_power(cases[i].suf)); } } /* Lowercase variants other than 'k' should not be recognized and return 0. */ void test_suffix_power_lowercase_unrecognized(void) { char lows[] = { 'm', 'g', 't', 'p', 'e', 'z', 'y', 'r', 'q' }; for (size_t i = 0; i < sizeof(lows)/sizeof(lows[0]); i++) { TEST_ASSERT_EQUAL_INT(0, suffix_power(lows[i])); } } /* Invalid characters should return 0. */ void test_suffix_power_invalid_chars(void) { TEST_ASSERT_EQUAL_INT(0, suffix_power('A')); TEST_ASSERT_EQUAL_INT(0, suffix_power('b')); TEST_ASSERT_EQUAL_INT(0, suffix_power('0')); TEST_ASSERT_EQUAL_INT(0, suffix_power(' ')); TEST_ASSERT_EQUAL_INT(0, suffix_power('\0')); TEST_ASSERT_EQUAL_INT(0, suffix_power('\n')); } /* Boundary check: just below/above valid range should return 0. */ void test_suffix_power_boundary_non_suffixes(void) { TEST_ASSERT_EQUAL_INT(0, suffix_power('@')); /* before 'A' */ TEST_ASSERT_EQUAL_INT(0, suffix_power('[')); /* after 'Z' */ TEST_ASSERT_EQUAL_INT(0, suffix_power('`')); /* before 'a' */ TEST_ASSERT_EQUAL_INT(0, suffix_power('{')); /* after 'z' */ } int main(void) { UNITY_BEGIN(); RUN_TEST(test_suffix_power_k_variants); RUN_TEST(test_suffix_power_all_uppercase); RUN_TEST(test_suffix_power_lowercase_unrecognized); RUN_TEST(test_suffix_power_invalid_chars); RUN_TEST(test_suffix_power_boundary_non_suffixes); return UNITY_END(); }