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.
 
 

101 lines
2.4 KiB

#ifdef TEST
#include "unity.h"
#include "logarithmus.h"
#include "exponent.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_ln_with_positive_number(void){
double r1, r2, r3;
r1 = logN(1.0, 0.000001);
r2 = logN(10.0, 0.000001);
r3 = logN(2.5, 0.000001);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0, r1);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.302585, r2);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.916290, r3);
}
void test_ln_with_zero_and_negative_numbers(void){
double r1, r2, r3;
r1 = logN(0.0, 0.000001);
r2 = logN(-1.0, 0.000001);
r3 = logN(-2.5, 0.000001);
TEST_ASSERT_EQUAL_DOUBLE(-1.0, r1);
TEST_ASSERT_EQUAL_DOUBLE(-1.0, r2);
TEST_ASSERT_EQUAL_DOUBLE(-1.0, r3);
}
void test_logarithmic_function_with_edge_cases(void){
double r1, r2, r3, r4;
r1 = logX(0, 10.0);
r2 = logX(-1.0, 9.0);
r3 = logX(1.0, 18.0);
r4 = logX(3.0, 0.0);
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);
}
void test_logarithmic_function_with_integers(void){
double r1, r2, r3, r4;
r1 = logX(0.5, 48.0);
r2 = logX(2.0, 8.0);
r3 = logX(3.2, 18.0);
r4 = logX(6.0, 36.0);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, -5.584962, r1);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 3.0, r2);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.484950, r3);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.0, r4);
}
void test_logarithmic_function_with_decimals(void){
double r1, r2, r3, r4;
r1 = logX(0.1289, 26.5);
r2 = logX(7.64, 8.314);
r3 = logX(3.0, 2.4587);
r4 = logX(9.0, 94.6584);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, -1.599607, r1);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 1.041577, r2);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.818881, r3);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.070919, r4);
}
void test_logarithmic_function_to_base_10(void){
double r1, r2, r3, r4, r5, r6;
r1 = logDec(100.0);
r2 = logDec(100.6479);
r3 = logDec(10.587);
r4 = logDec(4.341);
r5 = logDec(0.34979);
r6 = logDec(1.0);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.0, r1);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 2.002804, r2);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 1.024772, r3);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.637589, r4);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, -0.456192, r5);
TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.0, r6);
}
#endif // TEST