85 lines
2.2 KiB
C
85 lines
2.2 KiB
C
#include "test_string.h"
|
|
#include "unity.h"
|
|
|
|
#include <string.h>
|
|
|
|
void test_strlen() {
|
|
TEST_ASSERT_EQUAL_INT(4, strlen("test"));
|
|
}
|
|
|
|
void test_strlen_empty() {
|
|
TEST_ASSERT_EQUAL_INT(0, strlen(""));
|
|
}
|
|
|
|
void test_strlen_single_char_string() {
|
|
TEST_ASSERT_EQUAL_INT(1, strlen(" "));
|
|
}
|
|
|
|
void test_strnlen() {
|
|
char test_str[] = "test";
|
|
TEST_ASSERT_EQUAL_INT(4, strnlen(test_str, sizeof(test_str)));
|
|
}
|
|
|
|
void test_strnlen_hit_maxlen() {
|
|
char test_str[] = "test";
|
|
int maxlen = 2;
|
|
TEST_ASSERT_EQUAL_INT(maxlen, strnlen(test_str, maxlen));
|
|
}
|
|
|
|
void test_strnlen_empty() {
|
|
TEST_ASSERT_EQUAL_INT(0, strnlen("", 0));
|
|
}
|
|
|
|
void test_strnlen_single_char_string() {
|
|
TEST_ASSERT_EQUAL_INT(1, strnlen(" ", 1));
|
|
}
|
|
|
|
void test_isdigit() {
|
|
TEST_ASSERT(isdigit('0'));
|
|
TEST_ASSERT(isdigit('1'));
|
|
TEST_ASSERT(isdigit('2'));
|
|
TEST_ASSERT(isdigit('3'));
|
|
TEST_ASSERT(isdigit('4'));
|
|
TEST_ASSERT(isdigit('5'));
|
|
TEST_ASSERT(isdigit('6'));
|
|
TEST_ASSERT(isdigit('7'));
|
|
TEST_ASSERT(isdigit('8'));
|
|
TEST_ASSERT(isdigit('9'));
|
|
}
|
|
|
|
void test_isdigit_not_a_digit() {
|
|
TEST_ASSERT_FALSE(isdigit('0' - 1));
|
|
TEST_ASSERT_FALSE(isdigit('9' + 1));
|
|
}
|
|
|
|
void test_isdigit_alpha_chars() {
|
|
TEST_ASSERT_FALSE(isdigit('a'));
|
|
TEST_ASSERT_FALSE(isdigit('A'));
|
|
}
|
|
|
|
void test_tonumericdigit() {
|
|
TEST_ASSERT_EQUAL_INT(0, tonumericdigit('0'));
|
|
TEST_ASSERT_EQUAL_INT(1, tonumericdigit('1'));
|
|
TEST_ASSERT_EQUAL_INT(2, tonumericdigit('2'));
|
|
TEST_ASSERT_EQUAL_INT(3, tonumericdigit('3'));
|
|
TEST_ASSERT_EQUAL_INT(4, tonumericdigit('4'));
|
|
TEST_ASSERT_EQUAL_INT(5, tonumericdigit('5'));
|
|
TEST_ASSERT_EQUAL_INT(6, tonumericdigit('6'));
|
|
TEST_ASSERT_EQUAL_INT(7, tonumericdigit('7'));
|
|
TEST_ASSERT_EQUAL_INT(8, tonumericdigit('8'));
|
|
TEST_ASSERT_EQUAL_INT(9, tonumericdigit('9'));
|
|
}
|
|
|
|
void test_string() {
|
|
RUN_TEST(test_strlen);
|
|
RUN_TEST(test_strlen_empty);
|
|
RUN_TEST(test_strlen_single_char_string);
|
|
RUN_TEST(test_strnlen);
|
|
RUN_TEST(test_strnlen_hit_maxlen);
|
|
RUN_TEST(test_strnlen_empty);
|
|
RUN_TEST(test_strnlen_single_char_string);
|
|
RUN_TEST(test_isdigit);
|
|
RUN_TEST(test_isdigit_not_a_digit);
|
|
RUN_TEST(test_isdigit_alpha_chars);
|
|
RUN_TEST(test_tonumericdigit);
|
|
} |