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.

119 lines
2.9 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "logarithmus.h"
  4. #include "exponent.h"
  5. #include "reihen.h"
  6. void setUp(void)
  7. {
  8. }
  9. void tearDown(void)
  10. {
  11. }
  12. void test_ln_with_positive_number(void){
  13. double r1, r2, r3;
  14. r1 = logN(1.0);
  15. r2 = logN(10.0);
  16. r3 = logN(2.5);
  17. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0, r1);
  18. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.302585, r2);
  19. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.916290, r3);
  20. }
  21. void test_ln_with_zero_and_negative_numbers(void){
  22. double r1, r2, r3;
  23. r1 = logN(0.0);
  24. r2 = logN(-1.0);
  25. r3 = logN(-2.5);
  26. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r1);
  27. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r2);
  28. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r3);
  29. }
  30. void test_logarithmic_function_with_edge_cases(void){
  31. double r1, r2, r3, r4;
  32. r1 = logX(0, 10.0);
  33. r2 = logX(-1.0, 9.0);
  34. r3 = logX(1.0, 18.0);
  35. r4 = logX(3.0, 0.0);
  36. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r1);
  37. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r2);
  38. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r3);
  39. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r4);
  40. }
  41. void test_logarithmic_function_with_integers(void){
  42. double r1, r2, r3, r4;
  43. r1 = logX(0.5, 48.0);
  44. r2 = logX(2.0, 8.0);
  45. r3 = logX(3.2, 18.0);
  46. r4 = logX(6.0, 36.0);
  47. TEST_ASSERT_DOUBLE_WITHIN(0.000001, -5.584962, r1);
  48. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 3.0, r2);
  49. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.484950, r3);
  50. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.0, r4);
  51. }
  52. void test_logarithmic_function_with_decimals(void){
  53. double r1, r2, r3, r4;
  54. r1 = logX(0.1289, 26.5);
  55. r2 = logX(7.64, 8.314);
  56. r3 = logX(3.0, 2.4587);
  57. r4 = logX(9.0, 94.6584);
  58. TEST_ASSERT_DOUBLE_WITHIN(0.000001, -1.599607, r1);
  59. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 1.041577, r2);
  60. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.818881, r3);
  61. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.070919, r4);
  62. }
  63. void test_logarithmic_function_to_base_10(void){
  64. double r1, r2, r3, r4, r5, r6;
  65. r1 = log10(100.0);
  66. r2 = log10(100.6479);
  67. r3 = log10(10.587);
  68. r4 = log10(4.341);
  69. r5 = log10(0.34979);
  70. r6 = log10(1.0);
  71. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.0, r1);
  72. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.002804, r2);
  73. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 1.024772, r3);
  74. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.637589, r4);
  75. TEST_ASSERT_DOUBLE_WITHIN(0.000001, -0.456192, r5);
  76. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.0, r6);
  77. }
  78. void test_logarithmic_function_to_base_2(void){
  79. double r1, r2, r3, r4, r5, r6;
  80. r1 = log2(1024.0);
  81. r2 = log2(1024.8742);
  82. r3 = log2(900.587);
  83. r4 = log2(78.341);
  84. r5 = log2(0.34979);
  85. r6 = log2(1.0);
  86. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 10.0, r1);
  87. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 10.001231, r2);
  88. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 9.814721, r3);
  89. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 6.291695, r4);
  90. TEST_ASSERT_DOUBLE_WITHIN(0.000001, -1.515439, r5);
  91. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.0, r6);
  92. }
  93. #endif // TEST