RomanNumber rnAdd(RomanNumber number1, RomanNumber number2) { RomanNumber returnValue; rnRemoveSubtractive(&number1); rnRemoveSubtractive(&number2); returnValue = rnConcatinate(number1, number2); rnSort(&returnValue); rnConsolidate(&returnValue); rnRewriteSubtractive(&returnValue); return returnValue; }
RomanNumber rnSubtract(RomanNumber number1, RomanNumber number2) { rnRemoveSubtractive(&number1); rnRemoveSubtractive(&number2); rnEliminateDuplicates(&number1, &number2); while (number2.Size > 0) { rnBreakdownDigit(&number1, &number2); rnEliminateDuplicates(&number1, &number2); } rnConsolidate(&number1); rnRewriteSubtractive(&number1); return number1; }
} END_TEST /*************** Testing Remove Subtractive with complex value ****************/ START_TEST(substitute_for_any_subtractives_complex_subtractive_value) { RomanNumber rn = newRomanNumber("MCMXCIX"); rnRemoveSubtractive(&rn); ck_assert_str_eq("MDCCCCLXXXXVIIII", to_string(rn)); } END_TEST
} END_TEST /* Testing a simple number consisting of only a single value needing conversion */ START_TEST(substitute_for_any_subtractives_simple_subtractive_value) { RomanNumber rn = newRomanNumber("IV"); rnRemoveSubtractive(&rn); ck_assert_str_eq("IIII", to_string(rn)); } END_TEST
} END_TEST /*** A single digit can not be out of order, so it should not change value ****/ START_TEST(substitute_for_any_subtractives_single_digit_value) { RomanNumber rn = newRomanNumber("I"); rnRemoveSubtractive(&rn); ck_assert_str_eq("I", to_string(rn)); } END_TEST
} END_TEST /********* Testing Remove Subtractive with static and changing values *********/ /** Also testing subtractive value two values above subtractor instead of one */ START_TEST(substitute_for_any_subtractives_with_changing_and_nonchanging_values) { RomanNumber rn = newRomanNumber("XIX"); rnRemoveSubtractive(&rn); ck_assert_str_eq("XVIIII", to_string(rn)); } END_TEST
} END_TEST /******************************************************************************* * Substitute for any subtractives in value * ******************************************************************************/ /******* Create a function to rewrite value into additive only notation *******/ START_TEST(substitute_for_any_subtractives_in_value) { RomanNumber rn = newRomanNumber("MDCLXVI"); char *before, *after; before = to_string(rn); rnRemoveSubtractive(&rn); after = to_string(rn); ck_assert_str_eq(before, after); } END_TEST