core: all int is now num
This commit is contained in:
parent
1b878db8fe
commit
85a5b567b2
@ -1,13 +1,10 @@
|
||||
atoi(str)
|
||||
aton(str)
|
||||
{
|
||||
local i = 0;
|
||||
local sign = 0;
|
||||
local out = 0;
|
||||
|
||||
loop {
|
||||
if ([str + i] == '-')
|
||||
sign = sign == 0;
|
||||
else if ([str + i] != '+')
|
||||
if ([str + i] != '+')
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
@ -17,7 +14,5 @@ atoi(str)
|
||||
out = out * 10 + [str + i] - '0';
|
||||
i++;
|
||||
}
|
||||
if (sign)
|
||||
return (0 - out);
|
||||
return out;
|
||||
}
|
9
tests/aton.🗿
Normal file
9
tests/aton.🗿
Normal file
@ -0,0 +1,9 @@
|
||||
main()
|
||||
{
|
||||
name = "aton";
|
||||
|
||||
test_num(aton("33"), 33, "");
|
||||
test_num(aton(""), 0, "");
|
||||
test_num(aton("40"), 40, "");
|
||||
test_num(aton("1"), 1, "");
|
||||
}
|
@ -7,13 +7,13 @@ main()
|
||||
name = "galloc";
|
||||
|
||||
ptr1 = galloc(1);
|
||||
test_int(ptr1, heap + LOCATION_DATA, "");
|
||||
test_num(ptr1, heap + LOCATION_DATA, "");
|
||||
free(ptr1);
|
||||
|
||||
ptr1 = galloc(1);
|
||||
test_int(ptr1, heap + LOCATION_DATA, "alloc after free");
|
||||
test_num(ptr1, heap + LOCATION_DATA, "alloc after free");
|
||||
free(ptr1);
|
||||
|
||||
ptr2 = galloc(0x9000);
|
||||
test_int(ptr2, 0, "alloc too big");
|
||||
test_num(ptr2, 0, "alloc too big");
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ main()
|
||||
{
|
||||
name = "strchri";
|
||||
|
||||
test_int(strchri("bozoman", 'm'), 4, "");
|
||||
test_int(strchri("bozoman", 'v'), 0 - 1, "");
|
||||
test_int(strchri("", 'v'), 0 - 1, "");
|
||||
test_num(strchri("bozoman", 'm'), 4, "");
|
||||
test_num(strchri("bozoman", 'v'), 0 - 1, "");
|
||||
test_num(strchri("", 'v'), 0 - 1, "");
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ main()
|
||||
{
|
||||
name = "strcmp";
|
||||
|
||||
test_int(strcmp("test", "test"), 0, "same chars");
|
||||
test_int(strcmp("s", "b"), 17, "");
|
||||
test_int(strcmp("", ""), 0, "empty strings");
|
||||
test_int(strcmp("", "a"), 65439, "");
|
||||
test_num(strcmp("test", "test"), 0, "same chars");
|
||||
test_num(strcmp("s", "b"), 17, "");
|
||||
test_num(strcmp("", ""), 0, "empty strings");
|
||||
test_num(strcmp("", "a"), 65439, "");
|
||||
}
|
||||
|
@ -2,6 +2,6 @@ main()
|
||||
{
|
||||
name = "strlen";
|
||||
|
||||
test_int(strlen("bozoman du 36"), 13, "");
|
||||
test_int(strlen(""), 0, "Empty string");
|
||||
test_num(strlen("bozoman du 36"), 13, "");
|
||||
test_num(strlen(""), 0, "Empty string");
|
||||
}
|
||||
|
@ -2,11 +2,11 @@ main()
|
||||
{
|
||||
name = "strncmp";
|
||||
|
||||
test_int(strncmp("test", "test", 4), 0, "same chars");
|
||||
test_int(strncmp("s", "b", 4), 17, "");
|
||||
test_int(strncmp("", "", 4), 0, "empty strings");
|
||||
test_int(strncmp("", "a", 0), 0, "");
|
||||
test_int(strncmp("ab", "ac", 1), 0, "");
|
||||
test_int(strncmp("aq", "a", 1), 0, "");
|
||||
test_int(strncmp("aq", "a", 2), 113, "");
|
||||
test_num(strncmp("test", "test", 4), 0, "same chars");
|
||||
test_num(strncmp("s", "b", 4), 17, "");
|
||||
test_num(strncmp("", "", 4), 0, "empty strings");
|
||||
test_num(strncmp("", "a", 0), 0, "");
|
||||
test_num(strncmp("ab", "ac", 1), 0, "");
|
||||
test_num(strncmp("aq", "a", 1), 0, "");
|
||||
test_num(strncmp("aq", "a", 2), 113, "");
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ test_str(value, reach_value, description)
|
||||
wrt '\n';
|
||||
}
|
||||
|
||||
test_int(value, reach_value, description)
|
||||
test_num(value, reach_value, description)
|
||||
{
|
||||
putstr(name);
|
||||
if (value != reach_value)
|
||||
|
Loading…
Reference in New Issue
Block a user