} END_TEST

/****** Character of "m" or "M" should have symbol "M" and value of 1000 ******/
START_TEST(initialize_roman_digit_with_m_or_M_returns_symbol_M_value_1000) {
   RomanDigit rd1 = newRomanDigit('m');
   RomanDigit rd2 = newRomanDigit('M');

   ck_assert(rd1.Symbol == 'M');
   ck_assert(rd2.Symbol == 'M');
   ck_assert_int_eq(rd1.Value, 1000);
   ck_assert_int_eq(rd2.Value, 1000);
} END_TEST
} END_TEST

/******* Character of "c" or "C" should have symbol "C" and value of 100 ******/
START_TEST(initialize_roman_digit_with_c_or_C_returns_symbol_C_value_100) {
   RomanDigit rd1 = newRomanDigit('c');
   RomanDigit rd2 = newRomanDigit('C');

   ck_assert(rd1.Symbol == 'C');
   ck_assert(rd2.Symbol == 'C');
   ck_assert_int_eq(rd1.Value, 100);
   ck_assert_int_eq(rd2.Value, 100);
} END_TEST
} END_TEST

/******* Character of "d" or "D" should have symbol "D" and value of 500 ******/
START_TEST(initialize_roman_digit_with_d_or_D_returns_symbol_D_value_500) {
   RomanDigit rd1 = newRomanDigit('d');
   RomanDigit rd2 = newRomanDigit('D');

   ck_assert(rd1.Symbol == 'D');
   ck_assert(rd2.Symbol == 'D');
   ck_assert_int_eq(rd1.Value, 500);
   ck_assert_int_eq(rd2.Value, 500);
} END_TEST
} END_TEST

/******** Character of "l" or "L" should have symbol "L" and value of 50 ******/
START_TEST(initialize_roman_digit_with_l_or_L_returns_symbol_L_value_50) {
   RomanDigit rd1 = newRomanDigit('l');
   RomanDigit rd2 = newRomanDigit('L');

   ck_assert(rd1.Symbol == 'L');
   ck_assert(rd2.Symbol == 'L');
   ck_assert_int_eq(rd1.Value, 50);
   ck_assert_int_eq(rd2.Value, 50);
} END_TEST
} END_TEST

/******** Character of "x" or "X" should have symbol "X" and value of 10 ******/
START_TEST(initialize_roman_digit_with_x_or_X_returns_symbol_X_value_10) {
   RomanDigit rd1 = newRomanDigit('x');
   RomanDigit rd2 = newRomanDigit('X');

   ck_assert(rd1.Symbol == 'X');
   ck_assert(rd2.Symbol == 'X');
   ck_assert_int_eq(rd1.Value, 10);
   ck_assert_int_eq(rd2.Value, 10);
} END_TEST
} END_TEST

/******** Character of "v" or "V" should have symbol "V" and value of 5 *******/
START_TEST(initialize_roman_digit_with_v_or_V_returns_symbol_V_value_5) {
   RomanDigit rd1 = newRomanDigit('v');
   RomanDigit rd2 = newRomanDigit('V');

   ck_assert(rd1.Symbol == 'V');
   ck_assert(rd2.Symbol == 'V');
   ck_assert_int_eq(rd1.Value, 5);
   ck_assert_int_eq(rd2.Value, 5);
} END_TEST
} END_TEST

/******** Character of "i" or "I" should have symbol "I" and value of 1 *******/
START_TEST(initialize_roman_digit_with_i_or_I_returns_symbol_I_value_1) {
   RomanDigit rd1 = newRomanDigit('i');
   RomanDigit rd2 = newRomanDigit('I');

   ck_assert(rd1.Symbol == 'I');
   ck_assert(rd2.Symbol == 'I');
   ck_assert_int_eq(rd1.Value, 1);
   ck_assert_int_eq(rd2.Value, 1);
} END_TEST
Beispiel #8
0
RomanNumber newRomanNumber(char *number) {
   RomanNumber returnValue;
   int idx;

   returnValue.Size = 0;
   for (idx = 0; number[idx] != '\0'; idx++) {
      RomanDigit rd = newRomanDigit(number[idx]);

      if (rd.Value == 0) {
         returnValue.Size = 0;
         returnValue.Digit[0] = rd;
         return returnValue;
      } else {
         returnValue.Digit[returnValue.Size] = rd;

         if (returnValue.Size > 0)
            if (returnValue.Digit[returnValue.Size].Value > returnValue.Digit[returnValue.Size-1].Value)
               returnValue.Digit[returnValue.Size-1].Value *= -1;

         returnValue.Size++;
      }
   }

   /* Add a Nulle Value on the end to embark zero value in calculations */
   returnValue.Digit[returnValue.Size].Symbol = 'N';
   returnValue.Digit[returnValue.Size].Value = 0;
   return returnValue;
}
} END_TEST

/*********** Test to insure values other than IVXLCD or M will fail ***********/
START_TEST(initialize_roman_digit_with_invalid_value_returns_symbol_Null_value_0) {
   RomanDigit rd1 = newRomanDigit('A');

   ck_assert(rd1.Symbol == 'N');
   ck_assert_int_eq(rd1.Value, 0);
} END_TEST
} END_TEST

/*******************************************************************************
 * Create Data Structure to Represent a Roman Number                           *
 ******************************************************************************/

/************** Create Data Structure to Represent a Roman Number *************/
START_TEST(create_data_structure_to_represent_a_roman_number) {
   RomanDigit rd = newRomanDigit('M');
   RomanNumber rn;
  
   rn.Size = 1;
   rn.Digit[0] = rd;

   ck_assert_int_eq(rn.Size, 1);
   ck_assert(rn.Digit[0].Symbol == 'M');
   ck_assert_int_eq(rn.Digit[0].Value, 1000);
} END_TEST