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.

125 lines
2.8 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. TEST_ASSERT_EQUAL_FLOAT(0.5, r1);
  25. TEST_ASSERT_EQUAL_FLOAT(-0.0370370373, r2);
  26. TEST_ASSERT_EQUAL_FLOAT(0.25, r3);
  27. }
  28. void test_DoubleBase_for_positive_decimal_exponent(void){
  29. float r1, r2, r3;
  30. r1 = expIN(0.45, 3.0);
  31. r2 = expIN(0.5, 9.0);
  32. r3 = expIN(0.5, 2.0);
  33. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.639474, r1);
  34. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 3.0, r2);
  35. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.414213, r3);
  36. }
  37. void test_DoubleDecimalBase_for_positive_decimal_exponent(void){
  38. float r1, r2, r3;
  39. r1 = expIN(0.31, 0.413);
  40. r2 = expIN(0.5, 3.13432);
  41. r3 = expIN(0.124, 10.1231);
  42. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.760229, r1);
  43. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.770401, r2);
  44. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.332474, r3);
  45. }
  46. void test_DoubleBase_for_negative_decimal_exponent(void){
  47. float r1, r2, r3;
  48. r1 = expIN(-0.125, 3.0);
  49. r2 = expIN(-0.5, 2.0);
  50. r3 = expIN(-0.12923, 10.0);
  51. printf("%lf\n",r1);
  52. printf("%lf\n",r2);
  53. printf("%lf\n",r3);
  54. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.871685, r1);
  55. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.707106, r2);
  56. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.742625, r3);
  57. }
  58. void test_Exponent_with_positive_number(void){
  59. double r1, r2, r3;
  60. r1 = exponential(0.0);
  61. r2 = exponential(1.0);
  62. r3 = exponential(2.0);
  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. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.367879, r1);
  72. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.135335, r2);
  73. }
  74. void test_ln_with_positive_number(void){
  75. double r1, r2, r3;
  76. r1 = logN(1.0, 0.000001);
  77. r2 = logN(10.0, 0.000001);
  78. r3 = logN(2.5, 0.000001);
  79. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0, r1);
  80. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.302585, r2);
  81. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.916290, r3);
  82. }
  83. void test_ln_with_zero_and_negative_numbers(void){
  84. double r1, r2, r3;
  85. r1 = logN(0.0, 0.000001);
  86. r2 = logN(-1.0, 0.000001);
  87. r3 = logN(-2.5, 0.000001);
  88. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r1);
  89. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r2);
  90. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r3);
  91. }
  92. #endif // TEST