Browse Source

Add Test for Negative Exponents

master
fdai7848 11 months ago
parent
commit
807d1b7b6b
  1. 6
      src/exponent.c
  2. 16
      test/test_exponent.c

6
src/exponent.c

@ -1,3 +1,5 @@
#include <stdio.h>
#include "exponent.h"
int expI(unsigned int e, int num){
@ -16,6 +18,8 @@ float expIN(int e, int num){
if(e>0){
return (float) expI(e, num);
}else{
return 1.0 / (float) expI(e, num);
printf("%d, %d\n", e, num);
printf("%f\n", 1.0 / (float) expI((e*-1), num));
return (1.0 / (float) expI((e*-1), num));
}
}

16
test/test_exponent.c

@ -24,5 +24,21 @@ void test_IntegerExponent_ForPositiveExponent(void){
TEST_ASSERT_EQUAL_INT(625, r3);
}
void test_IntegerExponent_ForNegativeExponent(void){
float r1, r2, r3;
r1 = expIN(-1, 2);
r2 = expIN(-3, -3);
r3 = expIN(-2, -2);
printf("Result 1: %d\n", r1);
printf("Result 2: %d\n", r2);
printf("Result 3: %d\n", r3);
TEST_ASSERT_EQUAL_FLOAT(0.5, r1);
TEST_ASSERT_EQUAL_FLOAT(-0.0370370373, r2);
TEST_ASSERT_EQUAL_FLOAT(0.25, r3);
}
#endif // TEST
Loading…
Cancel
Save