more docs

This commit is contained in:
Krishna Vedala 2020-07-31 13:49:33 +00:00
parent 98f9ae391f
commit 0f95bd92f9

View File

@ -1,4 +1,3 @@
/** /**
* @file * @file
* @brief Convert a positive integer to string (non-standard function) * @brief Convert a positive integer to string (non-standard function)
@ -52,26 +51,26 @@ char *int_to_string(uint16_t value, char *dest, int base)
static void test() static void test()
{ {
const int MAX_SIZE = 100; const int MAX_SIZE = 100;
for (int i = 1; i <= 100; ++i) char *str1 = (char *)calloc(sizeof(char), MAX_SIZE);
{ char *str2 = (char *)calloc(sizeof(char), MAX_SIZE);
char *str1 = (char *)calloc(sizeof(char), MAX_SIZE);
char *str2 = (char *)calloc(sizeof(char), MAX_SIZE);
for (int i = 1; i <= 100; ++i) /* test 100 random numbers */
{
/* Generate value from 0 to 100 */ /* Generate value from 0 to 100 */
int value = rand() % 100; int value = rand() % 100;
// assert(strcmp(itoa(value, str1, 2), int_to_string(value, str2, 2)) == // assert(strcmp(itoa(value, str1, 2), int_to_string(value, str2, 2)) ==
// 0); // 0);
snprintf(str1, MAX_SIZE, "%o", value); snprintf(str1, MAX_SIZE, "%o", value); //* standard C - to octal */
assert(strcmp(str1, int_to_string(value, str2, 8)) == 0); assert(strcmp(str1, int_to_string(value, str2, 8)) == 0);
snprintf(str1, MAX_SIZE, "%d", value); snprintf(str1, MAX_SIZE, "%d", value); /* standard C - to decimal */
assert(strcmp(str1, int_to_string(value, str2, 10)) == 0); assert(strcmp(str1, int_to_string(value, str2, 10)) == 0);
snprintf(str1, MAX_SIZE, "%x", value); snprintf(str1, MAX_SIZE, "%x", value); /* standard C - to hexadecimal */
assert(strcmp(str1, int_to_string(value, str2, 16)) == 0); assert(strcmp(str1, int_to_string(value, str2, 16)) == 0);
free(str1);
free(str2);
} }
free(str1);
free(str2);
} }
/** Driver Code */ /** Driver Code */