You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.1 KiB

12 months ago
12 months ago
12 months ago
  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "exponent.h"
  4. void setUp(void)
  5. {
  6. }
  7. void tearDown(void)
  8. {
  9. }
  10. void test_DoubleBase_ForPositiveExponent(void){
  11. int r1, r2, r3;
  12. r1 = expI(2.0, -2.0);
  13. r2 = expI(3.0, -3.0);
  14. r3 = expI(4.0, 5.0);
  15. TEST_ASSERT_EQUAL_INT(4.0, r1);
  16. TEST_ASSERT_EQUAL_INT(-27.0, r2);
  17. TEST_ASSERT_EQUAL_INT(625.0, r3);
  18. }
  19. void test_DoubleBase_ForNegativeExponent(void){
  20. float r1, r2, r3;
  21. r1 = expIN(-1.0, 2.0);
  22. r2 = expIN(-3.0, -3.0);
  23. r3 = expIN(-2.0, -2.0);
  24. printf("Result 1: %f\n", r1);
  25. printf("Result 2: %f\n", r2);
  26. printf("Result 3: %f\n", r3);
  27. TEST_ASSERT_EQUAL_FLOAT(0.5, r1);
  28. TEST_ASSERT_EQUAL_FLOAT(-0.0370370373, r2);
  29. TEST_ASSERT_EQUAL_FLOAT(0.25, r3);
  30. }
  31. void test_DoubleBase_for_positive_decimal_exponent(void){
  32. float r1, r2, r3;
  33. r1 = expIN(0.45, 3.0);
  34. r2 = expIN(0.5, 9.0);
  35. r3 = expIN(0.5, 2.0);
  36. printf("Result 1: %f\n", r1);
  37. printf("Result 2: %f\n", r2);
  38. printf("\nResult 3: %lf\n\n", r3);
  39. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.639474, r1);
  40. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 3.0, r2);
  41. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.414213, r3);
  42. }
  43. void test_DoubleDecimalBase_for_positive_decimal_exponent(void){
  44. float r1, r2, r3;
  45. r1 = expIN(0.31, 0.413);
  46. r2 = expIN(0.5, 3.13432);
  47. r3 = expIN(0.124, 10.1231);
  48. printf("Result 1: %f\n", r1);
  49. printf("Result 2: %f\n", r2);
  50. printf("\nResult 3: %lf\n\n", r3);
  51. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.760229, r1);
  52. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.770401, r2);
  53. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.332474, r3);
  54. }
  55. void test_Exponent_with_positive_number(void){
  56. double r1, r2, r3;
  57. r1 = exponential(0.0);
  58. r2 = exponential(1.0);
  59. r3 = exponential(2.0);
  60. printf("Result 1: %8.lf\n", r1);
  61. printf("Result 2: %lf\n", r2);
  62. printf("Result 3: %lf\n", r3);
  63. TEST_ASSERT_EQUAL_DOUBLE(1.0, r1);
  64. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 2.718282, r2);
  65. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 7.389056, r3);
  66. }
  67. void test_Exponent_with_negative_number(void){
  68. double r1, r2, r3;
  69. r1 = exponential(-1.0);
  70. r2 = exponential(-2.0);
  71. printf("Result 1: %lf\n", r1);
  72. printf("Result 2: %lf\n", r2);
  73. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.367879, r1);
  74. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.135335, r2);
  75. }
  76. void test_ln_with_positive_number(void){
  77. double r1, r2, r3;
  78. r1 = logN(1.0, 0.000001);
  79. r2 = logN(10.0, 0.000001);
  80. r3 = logN(2.5, 0.000001);
  81. printf("Result 1: %lf\n", r1);
  82. printf("Result 2: %lf\n", r2);
  83. printf("Result 3: %lf\n", r3);
  84. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0, r1);
  85. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.302585, r2);
  86. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.916290, r3);
  87. }
  88. void test_ln_with_zero_and_negative_numbers(void){
  89. double r1, r2, r3;
  90. r1 = logN(0.0, 0.000001);
  91. r2 = logN(-1.0, 0.000001);
  92. r3 = logN(-2.5, 0.000001);
  93. printf("Result 1: %lf\n", r1);
  94. printf("Result 2: %lf\n", r2);
  95. printf("Result 3: %lf\n", r3);
  96. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r1);
  97. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r2);
  98. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r3);
  99. }
  100. #endif // TEST