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.

109 lines
2.4 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_Exponent_with_positive_number(void){
  47. double r1, r2, r3;
  48. r1 = exponential(0.0);
  49. r2 = exponential(1.0);
  50. r3 = exponential(2.0);
  51. TEST_ASSERT_EQUAL_DOUBLE(1.0, r1);
  52. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 2.718282, r2);
  53. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 7.389056, r3);
  54. }
  55. void test_Exponent_with_negative_number(void){
  56. double r1, r2, r3;
  57. r1 = exponential(-1.0);
  58. r2 = exponential(-2.0);
  59. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.367879, r1);
  60. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.135335, r2);
  61. }
  62. void test_ln_with_positive_number(void){
  63. double r1, r2, r3;
  64. r1 = logN(1.0, 0.000001);
  65. r2 = logN(10.0, 0.000001);
  66. r3 = logN(2.5, 0.000001);
  67. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0, r1);
  68. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.302585, r2);
  69. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.916290, r3);
  70. }
  71. void test_ln_with_zero_and_negative_numbers(void){
  72. double r1, r2, r3;
  73. r1 = logN(0.0, 0.000001);
  74. r2 = logN(-1.0, 0.000001);
  75. r3 = logN(-2.5, 0.000001);
  76. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r1);
  77. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r2);
  78. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r3);
  79. }
  80. #endif // TEST