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.

105 lines
2.4 KiB

11 months ago
11 months ago
11 months ago
11 months ago
  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "exponent.h"
  4. #include "logarithmus.h"
  5. #include "reihen.h"
  6. #include "util.h"
  7. void setUp(void)
  8. {
  9. }
  10. void tearDown(void)
  11. {
  12. }
  13. void test_DoubleBase_ForPositiveExponent(void){
  14. int r1, r2, r3;
  15. r1 = p(2.0, -2.0);
  16. r2 = p(3.0, -3.0);
  17. r3 = p(4.0, 5.0);
  18. TEST_ASSERT_EQUAL_INT(4.0, r1);
  19. TEST_ASSERT_EQUAL_INT(-27.0, r2);
  20. TEST_ASSERT_EQUAL_INT(625.0, r3);
  21. }
  22. void test_DoubleBase_ForNegativeExponent(void){
  23. float r1, r2, r3;
  24. r1 = powerD(-1.0, 2.0);
  25. r2 = powerD(-3.0, -3.0);
  26. r3 = powerD(-2.0, -2.0);
  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 = powerD(0.45, 3.0);
  34. r2 = powerD(0.5, 9.0);
  35. r3 = powerD(0.5, 2.0);
  36. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.639474, r1);
  37. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 3.0, r2);
  38. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.414213, r3);
  39. }
  40. void test_DoubleDecimalBase_for_positive_decimal_exponent(void){
  41. float r1, r2, r3;
  42. r1 = powerD(0.31, 0.413);
  43. r2 = powerD(0.5, 3.13432);
  44. r3 = powerD(0.124, 10.1231);
  45. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.760229, r1);
  46. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.770401, r2);
  47. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.332474, r3);
  48. }
  49. void test_DoubleBase_for_negative_decimal_exponent(void){
  50. float r1, r2, r3;
  51. r1 = powerD(-0.125, 3.0);
  52. r2 = powerD(-0.5, 2.0);
  53. r3 = powerD(-0.12923, 10.0);
  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_DoubleDecimalBase_for_negative_decimal_exponent(void){
  59. float r1, r2, r3;
  60. r1 = powerD(-0.5, 6.2315);
  61. r2 = powerD(-0.1937, 9.2309);
  62. r3 = powerD(-2.2145, 22.9983);
  63. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.400593, r1);
  64. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.650177, r2);
  65. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.000964, r3);
  66. }
  67. void test_exponent_edge_case(void){
  68. float r1, r2, r3, r4, r5;
  69. r1 = powerD(0, 2);
  70. r2 = powerD(0, 0);
  71. r3 = powerD(2, 0);
  72. r4 = powerD(-3, 0);
  73. r5 = powerD(0.5, -3);
  74. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.0, r1);
  75. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.0, r2);
  76. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.0, r3);
  77. TEST_ASSERT_DOUBLE_WITHIN(0.0001, -1.0, r4);
  78. TEST_ASSERT_DOUBLE_WITHIN(0.0001, -1.0, r5);
  79. }
  80. #endif // TEST