Browse Source

add tests for edge cases

master
fdai7848 11 months ago
parent
commit
18200c9252
  1. 12
      src/exponent.c
  2. 16
      test/test_exponent.c

12
src/exponent.c

@ -24,21 +24,27 @@ double expI(double e, double num){
double expIN(double e, double num){ double expIN(double e, double num){
if(absD(e) - ((int) absD(e)) < 0.000001){ if(absD(e) - ((int) absD(e)) < 0.000001){
if(e>0.0){
if(e>=0.0){
return expI(e, num); return expI(e, num);
} }
else{ else{
if (num == 0.0){
return -1.0;
}
return (1.0 / expI((e*-1), num)); return (1.0 / expI((e*-1), num));
} }
}else if(num > 0.0){ }else if(num > 0.0){
if(e>0.0){
if(e>=0.0){
return exponential(e*logN(num, 0.00000001)); return exponential(e*logN(num, 0.00000001));
} }
else{ else{
if (num == 0.0){
return -1.0;
}
return (1.0 / exponential((-1*e)*logN(num, 0.00000001))); return (1.0 / exponential((-1*e)*logN(num, 0.00000001)));
} }
} }
return -1;
return -1.0;
} }
unsigned long long fac(int x){ unsigned long long fac(int x){

16
test/test_exponent.c

@ -84,6 +84,22 @@ void test_DoubleDecimalBase_for_negative_decimal_exponent(void){
TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.000964, r3); TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.000964, r3);
} }
void test_exponent_edge_case(void){
float r1, r2, r3, r4, r5;
r1 = expIN(0, 2);
r2 = expIN(0, 0);
r3 = expIN(2, 0);
r4 = expIN(-3, 0);
r5 = expIN(0.5, -3);
TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.0, r1);
TEST_ASSERT_DOUBLE_WITHIN(0.0001, 1.0, r2);
TEST_ASSERT_DOUBLE_WITHIN(0.0001, 0.0, r3);
TEST_ASSERT_DOUBLE_WITHIN(0.0001, -1.0, r4);
TEST_ASSERT_DOUBLE_WITHIN(0.0001, -1.0, r5);
}
void test_Exponent_with_positive_number(void){ void test_Exponent_with_positive_number(void){
double r1, r2, r3; double r1, r2, r3;

Loading…
Cancel
Save