static void test_plus_returns_sum() { Expression *five = dollar( 5 ); Expression *addend_five = dollar( 5 ); Expression *result = plus( five, addend_five ); Sum *sum = ( Sum * ) result->value; assert_true( equal( money_from( five ), money_from( sum->augend ) ) ); assert_true( equal( money_from( addend_five ), money_from( sum->addend ) ) ); free_expression( five ); free_expression( addend_five ); free_expression( result ); delete_all_rates(); }
static void test_equal() { Money *five_dollar1 = money_from( dollar( 5 ) ); Money *five_dollar2 = money_from( dollar( 5 ) ); Money *six_dollar = money_from( dollar( 6 ) ); Money *five_franc = money_from( franc( 5 ) ); assert_true( equal( five_dollar1, five_dollar2 ) ); assert_false( equal( five_dollar1, six_dollar ) ); assert_false( equal( five_dollar1, five_franc ) ); free( five_dollar1 ); free( five_dollar2 ); free( six_dollar ); free( five_franc ); }
static void test_multiply_dollar_5x2() { Expression *five = dollar( 5 ); Expression *product = multiply( five, 2 ); Expression *ten = dollar( 10 ); assert_true( equal( reduce( product, USD ), money_from( ten ) ) ); free( five ); free( product ); free( ten ); }
static void test_multiply_dollar_5x3x3() { Expression *five = dollar( 5 ); Expression *product = multiply( multiply( five, 3 ), 3 ); Expression *fortyfive = dollar( 45 ); assert_true( equal( reduce( product, USD ), money_from( fortyfive ) ) ); free( five ); free( product ); free( fortyfive ); }
static void test_reduce_different_currency() { Expression *two_franc = franc( 2 ); Expression *one_dollar = dollar( 1 ); add_rate( CHF, USD, 2 ); Money *result = reduce( two_franc, USD ); assert_true( equal( result, money_from( one_dollar ) ) ); free_expression( two_franc ); free_expression( one_dollar ); free_money( result ); delete_all_rates(); }
static void test_multiply_dollar_5x2() { Expression *five = dollar( 5 ); Expression *product = multiply( five, 2 ); Expression *ten = dollar( 10 ); Money *reduced = reduce( product, USD ); assert_true( equal( reduced, money_from( ten ) ) ); free_expression( five ); free_expression( product ); free_expression( ten ); free_money( reduced ); delete_all_rates(); }
static void test_simple_addition() { Expression *five = dollar( 5 ); Expression *addend_five = dollar( 5 ); Expression *ten = dollar( 10 ); Expression *sum = plus( five, addend_five ); Money *reduced = reduce( sum, USD ); assert_true( equal( money_from( ten ), reduced ) ); free( five ); free( addend_five ); free( sum ); free( reduced ); free( ten ); }
static void test_reduce_sum() { Expression *three_usd = dollar( 3 ); Expression *four_usd = dollar( 4 ); Expression *seven_usd = dollar( 7 ); Expression *exp = plus( three_usd, four_usd ); Money *result = reduce( exp , USD ); assert_true( equal( result , money_from( seven_usd ) ) ); free_expression( three_usd ); free_expression( four_usd ); free_expression( seven_usd ); free_expression( exp ); free_money( result ); delete_all_rates(); }
static void test_multiply_dollar_5x3x3() { Expression *five = dollar( 5 ); Expression *product1 = multiply( five, 3 ); Expression *product2 = multiply( product1, 3 ); Expression *fortyfive = dollar( 45 ); Money *reduced = reduce( product2, USD ); assert_true( equal( reduced, money_from( fortyfive ) ) ); free_expression( five ); free_expression( product1 ); free_expression( product2 ); free_expression( fortyfive ); free_money( reduced ); delete_all_rates(); }
static void test_mixed_addition() { Expression *five_bucks = dollar( 5 ); Expression *ten_francs = franc( 10 ); Expression *ten_usd = dollar( 10 ); add_rate( CHF, USD, 2 ); Expression *exp = plus( five_bucks, ten_francs ); Money *result = reduce( exp, USD ); assert_true( equal( money_from( ten_usd ), result ) ); free_expression( five_bucks ); free_expression( ten_francs ); free_expression( ten_usd ); free_expression( exp ); free_money( result ); delete_all_rates(); }
static void test_multiple_addition() { Expression *five_bucks = dollar( 5 ); Expression *ten_francs = franc( 10 ); Expression *fifteen_bucks = dollar( 15 ); add_rate( CHF, USD, 2 ); Expression *exp1 = plus( five_bucks, ten_francs ); Expression *exp2 = plus( exp1, five_bucks ); Money *result = reduce( exp2, USD ); assert_true( equal( money_from( fifteen_bucks ), result ) ); free_expression( five_bucks ); free_expression( ten_francs ); free_expression( fifteen_bucks ); free_expression( exp1 ); free_expression( exp2 ); free_money( result ); delete_all_rates(); }
static void test_equal() { Expression *five_dollar1 = dollar( 5 ); Expression *five_dollar2 = dollar( 5 ); Expression *six_dollar = dollar( 6 ); Expression *five_franc = franc( 5 ); assert_true( equal( money_from( five_dollar1 ), money_from( five_dollar2 ) ) ); assert_false( equal( money_from( five_dollar1 ), money_from( six_dollar ) ) ); assert_false( equal( money_from( five_dollar1 ), money_from( five_franc ) ) ); free_expression( five_dollar1 ); free_expression( five_dollar2 ); free_expression( six_dollar ); free_expression( five_franc ); delete_all_rates(); }
static void test_currency() { assert_int_equal( USD, currency_of( money_from( dollar( 1 ) ) ) ); assert_int_equal( CHF, currency_of( money_from( franc( 1 ) ) ) ); }