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.

133 lines
3.1 KiB

11 months ago
11 months ago
11 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. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.871685, r1);
  52. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.707106, r2);
  53. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.742625, r3);
  54. }
  55. void test_DoubleDecimalBase_for_negative_decimal_exponent(void){
  56. float r1, r2, r3;
  57. r1 = expIN(-0.5, 6.2315);
  58. r2 = expIN(-0.1937, 9.2309);
  59. r3 = expIN(-2.2145, 22.9983);
  60. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.400593, r1);
  61. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.650177, r2);
  62. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.000964, r3);
  63. }
  64. void test_Exponent_with_positive_number(void){
  65. double r1, r2, r3;
  66. r1 = exponential(0.0);
  67. r2 = exponential(1.0);
  68. r3 = exponential(2.0);
  69. TEST_ASSERT_EQUAL_DOUBLE(1.0, r1);
  70. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 2.718282, r2);
  71. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 7.389056, r3);
  72. }
  73. void test_Exponent_with_negative_number(void){
  74. double r1, r2, r3;
  75. r1 = exponential(-1.0);
  76. r2 = exponential(-2.0);
  77. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.367879, r1);
  78. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.135335, r2);
  79. }
  80. void test_ln_with_positive_number(void){
  81. double r1, r2, r3;
  82. r1 = logN(1.0, 0.000001);
  83. r2 = logN(10.0, 0.000001);
  84. r3 = logN(2.5, 0.000001);
  85. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0, r1);
  86. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.302585, r2);
  87. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.916290, r3);
  88. }
  89. void test_ln_with_zero_and_negative_numbers(void){
  90. double r1, r2, r3;
  91. r1 = logN(0.0, 0.000001);
  92. r2 = logN(-1.0, 0.000001);
  93. r3 = logN(-2.5, 0.000001);
  94. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r1);
  95. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r2);
  96. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r3);
  97. }
  98. #endif // TEST