From fa9fb28309e241890cf5f1f0cfc07b2ad4dfbe99 Mon Sep 17 00:00:00 2001 From: fdai7848 Date: Fri, 2 Feb 2024 15:57:58 +0100 Subject: [PATCH] add tests for edge cases and add fix for log function --- src/logarithmus.c | 2 +- src/logarithmus.h | 2 ++ test/test_logarithmus.c | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/logarithmus.c b/src/logarithmus.c index a7abbbb..8dbfd7a 100644 --- a/src/logarithmus.c +++ b/src/logarithmus.c @@ -5,7 +5,7 @@ #include "exponent.h" double logX(double b, double a){ - if(b == 1.0 || b < 0.0){ + if(b == 1.0 || b <= 0.0 || a <= 0.0){ return -1.0; } return(logN(a, 0.000001)/logN(b, 0.000001)); diff --git a/src/logarithmus.h b/src/logarithmus.h index 4294276..68b011f 100644 --- a/src/logarithmus.h +++ b/src/logarithmus.h @@ -3,5 +3,7 @@ double logN(double x, double eps); double logX(double b, double a); +double logDec(double a); +double logBin(double a); #endif // logarithmus.h \ No newline at end of file diff --git a/test/test_logarithmus.c b/test/test_logarithmus.c index 6c056d8..e8fedfe 100644 --- a/test/test_logarithmus.c +++ b/test/test_logarithmus.c @@ -37,5 +37,24 @@ void test_ln_with_zero_and_negative_numbers(void){ TEST_ASSERT_EQUAL_DOUBLE(-1.0, r3); } +void test_logarithmic_function_with_edge_cases(void){ + double r1, r2, r3, r4; + + r1 = logX(0, 10); + r2 = logX(-1.0, 9); + r3 = logX(1, 18); + r4 = logX(3, 0); + + printf("%lf\n", r1); + printf("%lf\n", r2); + printf("%lf\n", r3); + printf("%lf\n", r4); + + TEST_ASSERT_EQUAL_DOUBLE(-1.0, r1); + TEST_ASSERT_EQUAL_DOUBLE(-1.0, r2); + TEST_ASSERT_EQUAL_DOUBLE(-1.0, r3); + TEST_ASSERT_EQUAL_DOUBLE(-1.0, r4); +} + #endif // TEST \ No newline at end of file