Tests: Add tests for srand, atol and atoll

This commit is contained in:
apio 2022-10-22 12:10:19 +02:00
parent 59d5e9789e
commit 6e01323e84
2 changed files with 73 additions and 0 deletions

View File

@ -5,6 +5,9 @@ DEFINE_TEST(strnlen);
DEFINE_TEST(strcspn);
DEFINE_TEST(atoi);
DEFINE_TEST(atol);
DEFINE_TEST(atoll);
DEFINE_TEST(srand);
int main()
{
@ -15,4 +18,7 @@ int main()
START_TEST_CASE(stdlib.h);
RUN_TEST(atoi);
RUN_TEST(atol);
RUN_TEST(atoll);
RUN_TEST(srand);
}

View File

@ -20,5 +20,72 @@ DEFINE_TEST(atoi)
EXPECT_EQ(num, 0);
TEST_SUCCESS();
}
DEFINE_TEST(atol)
{
START_TEST(atol);
const char* str = "42";
long num = atol(str);
EXPECT_EQ(num, 42);
str = "-56";
num = atol(str);
EXPECT_EQ(num, -56);
str = "Not a number";
num = atol(str);
EXPECT_EQ(num, 0);
str = "68719476735";
num = atol(str);
EXPECT_EQ(num, 68719476735);
TEST_SUCCESS();
}
DEFINE_TEST(atoll)
{
START_TEST(atoll);
const char* str = "42";
long long num = atoll(str);
EXPECT_EQ(num, 42);
str = "-56";
num = atoll(str);
EXPECT_EQ(num, -56);
str = "Not a number";
num = atoll(str);
EXPECT_EQ(num, 0);
str = "68719476735";
num = atoll(str);
EXPECT_EQ(num, 68719476735);
TEST_SUCCESS();
}
DEFINE_TEST(srand)
{
START_TEST(srand);
srand(5849);
int val = rand();
EXPECT_EQ(val, -1731894882);
TEST_SUCCESS();
}