#ifdef TEST #include "unity.h" #include "exponent.h" void setUp(void) { } void tearDown(void) { } void test_DoubleBase_ForPositiveExponent(void){ int r1, r2, r3; r1 = expI(2.0, -2.0); r2 = expI(3.0, -3.0); r3 = expI(4.0, 5.0); TEST_ASSERT_EQUAL_INT(4.0, r1); TEST_ASSERT_EQUAL_INT(-27.0, r2); TEST_ASSERT_EQUAL_INT(625.0, r3); } void test_DoubleBase_ForNegativeExponent(void){ float r1, r2, r3; r1 = expIN(-1.0, 2.0); r2 = expIN(-3.0, -3.0); r3 = expIN(-2.0, -2.0); printf("Result 1: %f\n", r1); printf("Result 2: %f\n", r2); printf("Result 3: %f\n", r3); TEST_ASSERT_EQUAL_FLOAT(0.5, r1); TEST_ASSERT_EQUAL_FLOAT(-0.0370370373, r2); TEST_ASSERT_EQUAL_FLOAT(0.25, r3); } void test_Exponent_with_positive_number(void){ double r1, r2, r3; r1 = exponential(0.0); r2 = exponential(1.0); r3 = exponential(2.0); printf("Result 1: %8.lf\n", r1); printf("Result 2: %lf\n", r2); printf("Result 3: %lf\n", r3); TEST_ASSERT_EQUAL_DOUBLE(1.0, r1); TEST_ASSERT_DOUBLE_WITHIN(0.0001, 2.718282, r2); TEST_ASSERT_DOUBLE_WITHIN(0.0001, 7.389056, r3); } void test_Exponent_with_negative_number(void){ double r1, r2, r3; r1 = exponential(-1.0); r2 = exponential(-2.0); printf("Result 1: %lf\n", r1); printf("Result 2: %lf\n", r2); TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.367879, r1); TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.135335, r2); } #endif // TEST