Luna/tests/libc/stdlib.c

91 lines
1.2 KiB
C

#include "Test.h"
#include <stdlib.h>
DEFINE_TEST(atoi)
{
START_TEST(atoi);
const char* str = "42";
int num = atoi(str);
EXPECT_EQ(num, 42);
str = "-56";
num = atoi(str);
EXPECT_EQ(num, -56);
str = "Not a number";
num = atoi(str);
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();
}