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.

104 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. void setUp(void)
  7. {
  8. }
  9. void tearDown(void)
  10. {
  11. }
  12. void test_DoubleBase_ForPositiveExponent(void){
  13. int r1, r2, r3;
  14. r1 = p(2.0, -2.0);
  15. r2 = p(3.0, -3.0);
  16. r3 = p(4.0, 5.0);
  17. TEST_ASSERT_EQUAL_INT(4.0, r1);
  18. TEST_ASSERT_EQUAL_INT(-27.0, r2);
  19. TEST_ASSERT_EQUAL_INT(625.0, r3);
  20. }
  21. void test_DoubleBase_ForNegativeExponent(void){
  22. float r1, r2, r3;
  23. r1 = powerD(-1.0, 2.0);
  24. r2 = powerD(-3.0, -3.0);
  25. r3 = powerD(-2.0, -2.0);
  26. TEST_ASSERT_EQUAL_FLOAT(0.5, r1);
  27. TEST_ASSERT_EQUAL_FLOAT(-0.0370370373, r2);
  28. TEST_ASSERT_EQUAL_FLOAT(0.25, r3);
  29. }
  30. void test_DoubleBase_for_positive_decimal_exponent(void){
  31. float r1, r2, r3;
  32. r1 = powerD(0.45, 3.0);
  33. r2 = powerD(0.5, 9.0);
  34. r3 = powerD(0.5, 2.0);
  35. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.639474, r1);
  36. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 3.0, r2);
  37. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.414213, r3);
  38. }
  39. void test_DoubleDecimalBase_for_positive_decimal_exponent(void){
  40. float r1, r2, r3;
  41. r1 = powerD(0.31, 0.413);
  42. r2 = powerD(0.5, 3.13432);
  43. r3 = powerD(0.124, 10.1231);
  44. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.760229, r1);
  45. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.770401, r2);
  46. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.332474, r3);
  47. }
  48. void test_DoubleBase_for_negative_decimal_exponent(void){
  49. float r1, r2, r3;
  50. r1 = powerD(-0.125, 3.0);
  51. r2 = powerD(-0.5, 2.0);
  52. r3 = powerD(-0.12923, 10.0);
  53. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.871685, r1);
  54. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.707106, r2);
  55. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.742625, r3);
  56. }
  57. void test_DoubleDecimalBase_for_negative_decimal_exponent(void){
  58. float r1, r2, r3;
  59. r1 = powerD(-0.5, 6.2315);
  60. r2 = powerD(-0.1937, 9.2309);
  61. r3 = powerD(-2.2145, 22.9983);
  62. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.400593, r1);
  63. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.650177, r2);
  64. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.000964, r3);
  65. }
  66. void test_exponent_edge_case(void){
  67. float r1, r2, r3, r4, r5;
  68. r1 = powerD(0, 2);
  69. r2 = powerD(0, 0);
  70. r3 = powerD(2, 0);
  71. r4 = powerD(-3, 0);
  72. r5 = powerD(0.5, -3);
  73. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.0, r1);
  74. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.0, r2);
  75. TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.0, r3);
  76. TEST_ASSERT_DOUBLE_WITHIN(0.0001, -1.0, r4);
  77. TEST_ASSERT_DOUBLE_WITHIN(0.0001, -1.0, r5);
  78. }
  79. #endif // TEST