From 6e01323e84559e2b633db07ac2d1208e360e25b1 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 22 Oct 2022 12:10:19 +0200 Subject: [PATCH] Tests: Add tests for srand, atol and atoll --- tests/libc/Test.c | 6 ++++ tests/libc/stdlib.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/tests/libc/Test.c b/tests/libc/Test.c index 92bf3ba9..a8156ee9 100644 --- a/tests/libc/Test.c +++ b/tests/libc/Test.c @@ -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); } \ No newline at end of file diff --git a/tests/libc/stdlib.c b/tests/libc/stdlib.c index e2ea4e52..0900b1f3 100644 --- a/tests/libc/stdlib.c +++ b/tests/libc/stdlib.c @@ -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(); } \ No newline at end of file