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.

82 lines
1.9 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "logarithmus.h"
  4. #include "exponent.h"
  5. void setUp(void)
  6. {
  7. }
  8. void tearDown(void)
  9. {
  10. }
  11. void test_ln_with_positive_number(void){
  12. double r1, r2, r3;
  13. r1 = logN(1.0, 0.000001);
  14. r2 = logN(10.0, 0.000001);
  15. r3 = logN(2.5, 0.000001);
  16. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0, r1);
  17. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.302585, r2);
  18. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.916290, r3);
  19. }
  20. void test_ln_with_zero_and_negative_numbers(void){
  21. double r1, r2, r3;
  22. r1 = logN(0.0, 0.000001);
  23. r2 = logN(-1.0, 0.000001);
  24. r3 = logN(-2.5, 0.000001);
  25. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r1);
  26. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r2);
  27. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r3);
  28. }
  29. void test_logarithmic_function_with_edge_cases(void){
  30. double r1, r2, r3, r4;
  31. r1 = logX(0, 10.0);
  32. r2 = logX(-1.0, 9.0);
  33. r3 = logX(1.0, 18.0);
  34. r4 = logX(3.0, 0.0);
  35. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r1);
  36. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r2);
  37. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r3);
  38. TEST_ASSERT_EQUAL_DOUBLE(-1.0, r4);
  39. }
  40. void test_logarithmic_function_with_integers(void){
  41. double r1, r2, r3, r4;
  42. r1 = logX(0.5, 48.0);
  43. r2 = logX(2.0, 8.0);
  44. r3 = logX(3.2, 18.0);
  45. r4 = logX(6.0, 36.0);
  46. TEST_ASSERT_DOUBLE_WITHIN(0.000001, -5.584962, r1);
  47. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 3.0, r2);
  48. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.484950, r3);
  49. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.0, r4);
  50. }
  51. void test_logarithmic_function_with_decimals(void){
  52. double r1, r2, r3, r4;
  53. r1 = logX(0.1289, 26.5);
  54. r2 = logX(7.64, 8.314);
  55. r3 = logX(3.0, 2.4587);
  56. r4 = logX(9.0, 94.6584);
  57. TEST_ASSERT_DOUBLE_WITHIN(0.000001, -1.599607, r1);
  58. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 1.041577, r2);
  59. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.818881, r3);
  60. TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.070919, r4);
  61. }
  62. #endif // TEST