|
|
@ -7,15 +7,47 @@ |
|
|
|
|
|
|
|
void test_power() |
|
|
|
{ |
|
|
|
/*initializing test values*/ |
|
|
|
int testValues[] = {1,2,3,4,5,6,7,8,9}; |
|
|
|
int expectedValues[] = {1,4,9,16,25,36,49,64,81}; |
|
|
|
|
|
|
|
/*test block 1*/ |
|
|
|
int testValues[] = {1,2,3,4,5,6,7,8,9,10}; |
|
|
|
int expectedValues[] = {1,4,9,16,25,36,49,64,81,100}; |
|
|
|
int length = sizeof(testValues)/sizeof(int); |
|
|
|
/*assertions*/ |
|
|
|
const int exponent = 2; |
|
|
|
for(int i=0;i<length;++i){ |
|
|
|
TEST_ASSERT_EQUAL_INT(expectedValues[i], power(testValues[i],exponent)); |
|
|
|
} |
|
|
|
|
|
|
|
/*test block 2*/ |
|
|
|
int testValues_2[] = {11,12,13,14,15,16,17,18,19,20}; |
|
|
|
int expectedValues_2[] = {121,144,169,196,225,256,289,324,361,400}; |
|
|
|
length = sizeof(testValues_2)/sizeof(int); |
|
|
|
for(int i=0;i<length;++i){ |
|
|
|
TEST_ASSERT_EQUAL_INT(expectedValues_2[i],power(testValues_2[i],exponent)); |
|
|
|
} |
|
|
|
|
|
|
|
/*test block 3*/ |
|
|
|
int testValues_3[] = {1,2,3,4,5,6,7,8,9,10}; |
|
|
|
int expectedValues_3[] = {1,8,27,64,125,216,343,512,729,1000}; |
|
|
|
const int exponent_2 = 3; |
|
|
|
length = sizeof(testValues_3)/sizeof(int); |
|
|
|
for(int i=0;i<length;++i){ |
|
|
|
TEST_ASSERT_EQUAL_INT(expectedValues_3[i],power(testValues_3[i],exponent_2)); |
|
|
|
} |
|
|
|
/*test block 4*/ |
|
|
|
int testValues_4[] = {11,12,13,14,15,16,17,18,19,20}; |
|
|
|
int expectedValues_4[] = {1331,1728,2197,2744,3375,4096,4913,5832,6859,8000}; |
|
|
|
length = sizeof(testValues_4)/sizeof(int); |
|
|
|
for(int i=0;i<length;++i){ |
|
|
|
TEST_ASSERT_EQUAL_INT(expectedValues_4[i],power(testValues_4[i],exponent_2)); |
|
|
|
} |
|
|
|
/*test block 5*/ |
|
|
|
int testValues_5[] = {0,0,19,2,4,5,11,54,32,12,77}; |
|
|
|
int exponents[] = {0,1,2,7,4,2,0,1,2,4,2}; |
|
|
|
int expectedValues_5[] = {-1, 1, 361,128,256,25,1,54,1024,20736,5929}; |
|
|
|
length = sizeof(testValues_5)/sizeof(int); |
|
|
|
for(int i=0;i<length;++i){ |
|
|
|
TEST_ASSERT_EQUAL_INT(expectedValues_5[i], power(testValues_5[i],exponents[i])); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void test_to_string() |
|
|
|