mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Get more Python tests passing (#141)
This commit is contained in:
parent
916f19eea1
commit
59e1c245d1
141 changed files with 3536 additions and 1203 deletions
|
@ -75,19 +75,31 @@ TEST(commandv, testSlashes_wontSearchPath_butStillAppendsComExtension) {
|
|||
if (!IsWindows()) EXPECT_EQ(i + 2, g_syscount);
|
||||
}
|
||||
|
||||
TEST(commandv, testSameDir_doesntHappenByDefault) {
|
||||
TEST(commandv, testSameDir_doesntHappenByDefaultUnlessItsWindows) {
|
||||
EXPECT_NE(-1, touch("bog", 0755));
|
||||
EXPECT_EQ(NULL, commandv("bog", pathbuf));
|
||||
if (IsWindows()) {
|
||||
EXPECT_STREQ("./bog", commandv("bog", pathbuf));
|
||||
} else {
|
||||
EXPECT_EQ(NULL, commandv("bog", pathbuf));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(commandv, testSameDir_willHappenWithColonBlank) {
|
||||
CHECK_NE(-1, setenv("PATH", "bin:", true));
|
||||
EXPECT_NE(-1, touch("bog", 0755));
|
||||
EXPECT_STREQ("bog", commandv("bog", pathbuf));
|
||||
if (IsWindows()) {
|
||||
EXPECT_STREQ("./bog", commandv("bog", pathbuf));
|
||||
} else {
|
||||
EXPECT_STREQ("bog", commandv("bog", pathbuf));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(commandv, testSameDir_willHappenWithColonBlank2) {
|
||||
CHECK_NE(-1, setenv("PATH", ":bin", true));
|
||||
EXPECT_NE(-1, touch("bog", 0755));
|
||||
EXPECT_STREQ("bog", commandv("bog", pathbuf));
|
||||
if (IsWindows()) {
|
||||
EXPECT_STREQ("./bog", commandv("bog", pathbuf));
|
||||
} else {
|
||||
EXPECT_STREQ("bog", commandv("bog", pathbuf));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,16 @@ TEST(TimeValToFileTime, roundTrip) {
|
|||
struct timeval tv1, tv2;
|
||||
tv1.tv_sec = 31337;
|
||||
tv1.tv_usec = 1337;
|
||||
FileTimeToTimeVal(&tv2, TimeValToFileTime(&tv1));
|
||||
tv2 = FileTimeToTimeVal(TimeValToFileTime(tv1));
|
||||
EXPECT_EQ(31337, tv2.tv_sec);
|
||||
EXPECT_EQ(1337, tv2.tv_usec);
|
||||
}
|
||||
|
||||
TEST(TimeSpecToFileTime, roundTrip_withSomeTruncation) {
|
||||
struct timespec tv1, tv2;
|
||||
tv1.tv_sec = 31337;
|
||||
tv1.tv_nsec = 1337;
|
||||
tv2 = FileTimeToTimeSpec(TimeSpecToFileTime(tv1));
|
||||
EXPECT_EQ(31337, tv2.tv_sec);
|
||||
EXPECT_EQ(1300, tv2.tv_nsec);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
TEST(strcasecmp, test) {
|
||||
EXPECT_EQ(0, strcasecmp("HELLO", "hello"));
|
||||
EXPECT_EQ(0, strcasecmp("HELLOHELLOHELLOHELLOHELLOHELLO",
|
||||
"hellohellohellohellohellohello"));
|
||||
EXPECT_EQ(-17, strcasecmp("HELLO", "yello"));
|
||||
EXPECT_EQ(-17, strcasecmp("HELLO", "YELLO"));
|
||||
EXPECT_EQ(+17, strcasecmp("yello", "HELLO"));
|
||||
|
@ -29,7 +31,10 @@ TEST(strcasecmp, test) {
|
|||
}
|
||||
|
||||
BENCH(strcasecmp, bench) {
|
||||
EZBENCH2("strcasecmp 16 eq", donothing,
|
||||
EZBENCH2("strcasecmp 16 eq (same)", donothing,
|
||||
EXPROPRIATE(
|
||||
strcasecmp(VEIL("r", "abcdefghijklmnop"), "abcdefghijklmnop")));
|
||||
EZBENCH2("strcasecmp 16 eq (evil)", donothing,
|
||||
EXPROPRIATE(
|
||||
strcasecmp(VEIL("r", "abcdefghijklmnop"), "ABCDEFGHIJKLMNOP")));
|
||||
}
|
||||
|
|
62
test/libc/str/strcat_test.c
Normal file
62
test/libc/str/strcat_test.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(strcat, test) {
|
||||
char buf[128];
|
||||
EXPECT_STREQ("hello", strcpy(buf, "hello"));
|
||||
EXPECT_STREQ("hellothere", strcat(buf, "there"));
|
||||
EXPECT_STREQ("hellothere", buf);
|
||||
}
|
||||
|
||||
TEST(strcat16, test) {
|
||||
char16_t buf[128];
|
||||
EXPECT_STREQ(u"hello", strcpy16(buf, u"hello"));
|
||||
EXPECT_STREQ(u"hellothere", strcat16(buf, u"there"));
|
||||
EXPECT_STREQ(u"hellothere", buf);
|
||||
}
|
||||
|
||||
TEST(wcscat, test) {
|
||||
wchar_t buf[128];
|
||||
EXPECT_STREQ(L"hello", wcscpy(buf, L"hello"));
|
||||
EXPECT_STREQ(L"hellothere", wcscat(buf, L"there"));
|
||||
EXPECT_STREQ(L"hellothere", buf);
|
||||
}
|
||||
|
||||
TEST(strncat, test) {
|
||||
char buf[128];
|
||||
EXPECT_STREQ("hello", strcpy(buf, "hello"));
|
||||
EXPECT_STREQ("hellothe", strncat(buf, "there", 3));
|
||||
EXPECT_STREQ("hellothe", buf);
|
||||
}
|
||||
|
||||
TEST(strncat16, test) {
|
||||
char16_t buf[128];
|
||||
EXPECT_STREQ(u"hello", strcpy16(buf, u"hello"));
|
||||
EXPECT_STREQ(u"hellothe", strncat16(buf, u"there", 3));
|
||||
EXPECT_STREQ(u"hellothe", buf);
|
||||
}
|
||||
|
||||
TEST(wcsncat, test) {
|
||||
wchar_t buf[128];
|
||||
EXPECT_STREQ(L"hello", wcscpy(buf, L"hello"));
|
||||
EXPECT_STREQ(L"hellothe", wcsncat(buf, L"there", 3));
|
||||
EXPECT_STREQ(L"hellothe", buf);
|
||||
}
|
|
@ -67,6 +67,15 @@ TEST(wcscasecmp, emptyString) {
|
|||
EXPECT_NE(0, wcscasecmp(L"", L"a"));
|
||||
}
|
||||
|
||||
TEST(strncmp, nullString) {
|
||||
char *s1 = malloc(0);
|
||||
char *s2 = malloc(0);
|
||||
ASSERT_NE(s1, s2);
|
||||
ASSERT_EQ(0, strncmp(s1, s2, 0));
|
||||
free(s2);
|
||||
free(s1);
|
||||
}
|
||||
|
||||
TEST(strncmp, emptyString) {
|
||||
char *s1 = strcpy(malloc(1), "");
|
||||
char *s2 = strcpy(malloc(1), "");
|
||||
|
@ -537,44 +546,37 @@ BENCH(bench_00_strcmp, bench) {
|
|||
data = gc(malloc(size));
|
||||
dupe = gc(malloc(size));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [identity]", longstringislong(size, data),
|
||||
EXPROPRIATE(strcmp(VEIL("r", data), data)));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [2 diff]", donothing,
|
||||
EXPROPRIATE(strcmp(VEIL("r", "hi"), VEIL("r", "there"))));
|
||||
EZBENCH2("strcmp_pure [2 diff]", donothing,
|
||||
EXPROPRIATE(strcmp_pure(VEIL("r", "hi"), VEIL("r", "there"))));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [2 dupe]", randomize_buf2str_dupe(2, data, dupe),
|
||||
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcmp_pure [2 dupe]", randomize_buf2str_dupe(2, data, dupe),
|
||||
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [4 dupe]", randomize_buf2str_dupe(4, data, dupe),
|
||||
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcmp_pure [4 dupe]", randomize_buf2str_dupe(4, data, dupe),
|
||||
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [8 dupe]", randomize_buf2str_dupe(8, data, dupe),
|
||||
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcmp_pure [8 dupe]", randomize_buf2str_dupe(8, data, dupe),
|
||||
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [short dupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EZBENCH2("strcmp [sdupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcmp_pure [short dupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EZBENCH2("strcmp_pure [sdupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [long dupe]", longstringislong_dupe(size, data, dupe),
|
||||
EZBENCH2("strcmp [ldupe]", longstringislong_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcmp_pure [long dupe]", longstringislong_dupe(size, data, dupe),
|
||||
EZBENCH2("strcmp_pure [ldupe]", longstringislong_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
}
|
||||
|
||||
|
@ -586,22 +588,17 @@ BENCH(bench_01_strcasecmp, bench) {
|
|||
data = gc(malloc(size));
|
||||
dupe = gc(malloc(size));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcasecmp [identity]", longstringislong(size, data),
|
||||
EXPROPRIATE(strcasecmp(VEIL("r", data), data)));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcasecmp [short dupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EZBENCH2("strcasecmp [sdupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcasecmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcasecmp_pure [short dupe]",
|
||||
randomize_buf2str_dupe(size, data, dupe),
|
||||
EZBENCH2("strcasecmp_pure [sdupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcasecmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcasecmp [long dupe]", longstringislong_dupe(size, data, dupe),
|
||||
EZBENCH2("strcasecmp [ldupe]", longstringislong_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcasecmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcasecmp_pure [long dupe]",
|
||||
longstringislong_dupe(size, data, dupe),
|
||||
EZBENCH2("strcasecmp_pure [ldupe]", longstringislong_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcasecmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
}
|
||||
|
||||
|
|
28
test/libc/str/wcsrchr_test.c
Normal file
28
test/libc/str/wcsrchr_test.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(wcsrchr, test) {
|
||||
EXPECT_STREQ(L"/there", wcsrchr(L"sup/hello/there", L'/'));
|
||||
EXPECT_STREQ(L"/there",
|
||||
wcsrchr(L"sup/hello/theresup/hello/theresup/hello/there", L'/'));
|
||||
EXPECT_STREQ(L"p/hello/there",
|
||||
wcsrchr(L"sup/hello/theresup/hello/theresup/hello/there", L'p'));
|
||||
}
|
|
@ -30,10 +30,11 @@ TEST(acos, test) {
|
|||
EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", acos(-1.))));
|
||||
EXPECT_TRUE(isnan(acos(1.5)));
|
||||
EXPECT_TRUE(isnan(acos(-1.5)));
|
||||
EXPECT_TRUE(isnan(acos(2.)));
|
||||
EXPECT_TRUE(isnan(acos(NAN)));
|
||||
EXPECT_TRUE(isnan(acos(-NAN)));
|
||||
EXPECT_TRUE(isnan(acos(INFINITY)));
|
||||
EXPECT_TRUE(isnan(acos(-INFINITY)));
|
||||
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", acos(__DBL_MIN__))));
|
||||
EXPECT_TRUE(isnan(acos(__LDBL_MAX__)));
|
||||
EXPECT_TRUE(isnan(acos(__DBL_MAX__)));
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ TEST(asinh, test) {
|
|||
EXPECT_STREQ("0", gc(xdtoa(asinh(0))));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(asinh(NAN))));
|
||||
EXPECT_STREQ("INFINITY", gc(xdtoa(asinh(INFINITY))));
|
||||
EXPECT_STREQ("-2.1073424255447e-08",
|
||||
gc(xasprintf("%.15g", asinh(-2.1073424255447e-08))));
|
||||
}
|
||||
|
||||
TEST(asinhf, test) {
|
||||
|
|
|
@ -287,6 +287,8 @@ TEST(atan2, test) {
|
|||
EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan2(-1, INFINITY))));
|
||||
EXPECT_STREQ(
|
||||
"-0", gc(xasprintf("%.15g", atan2(-1.7976931348623157e308, INFINITY))));
|
||||
EXPECT_STREQ("1.5707963267949",
|
||||
gc(xasprintf("%.15g", atan2(1.4142135623731, 0))));
|
||||
}
|
||||
|
||||
BENCH(atan2, bench) {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
|
@ -34,6 +35,8 @@ TEST(atanh, test) {
|
|||
EXPECT_STREQ("-INFINITY", gc(xdtoa(atanh(-1))));
|
||||
EXPECT_TRUE(isnan(atanh(+1.1)));
|
||||
EXPECT_TRUE(isnan(atanh(-1.1)));
|
||||
EXPECT_STREQ("-2.1073424255447e-08",
|
||||
gc(xasprintf("%.15g", atanh(-2.1073424255447e-08))));
|
||||
}
|
||||
|
||||
TEST(atanhl, test) {
|
||||
|
@ -57,3 +60,10 @@ TEST(atanhf, test) {
|
|||
EXPECT_TRUE(isnan(atanhf(+1.1)));
|
||||
EXPECT_TRUE(isnan(atanhf(-1.1)));
|
||||
}
|
||||
|
||||
BENCH(atanh, bench) {
|
||||
volatile double a = .5;
|
||||
EZBENCH2("atanhf", donothing, EXPROPRIATE(atanhf(a)));
|
||||
EZBENCH2("atanh", donothing, EXPROPRIATE(atanh(a)));
|
||||
EZBENCH2("atanhl", donothing, EXPROPRIATE(atanhl(a)));
|
||||
}
|
||||
|
|
45
test/libc/tinymath/cos_test.c
Normal file
45
test/libc/tinymath/cos_test.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
TEST(cos, test) {
|
||||
EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(0.))));
|
||||
EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(-0.))));
|
||||
EXPECT_STREQ("0.995004165278026", gc(xasprintf("%.15g", cos(.1))));
|
||||
EXPECT_STREQ("0.995004165278026", gc(xasprintf("%.15g", cos(-.1))));
|
||||
EXPECT_STREQ("0.877582561890373", gc(xasprintf("%.15g", cos(.5))));
|
||||
EXPECT_STREQ("0.877582561890373", gc(xasprintf("%.15g", cos(-.5))));
|
||||
EXPECT_STREQ("0.54030230586814", gc(xasprintf("%.15g", cos(1.))));
|
||||
EXPECT_STREQ("0.54030230586814", gc(xasprintf("%.15g", cos(-1.))));
|
||||
EXPECT_STREQ("0.0707372016677029", gc(xasprintf("%.15g", cos(1.5))));
|
||||
EXPECT_STREQ("0.0707372016677029", gc(xasprintf("%.15g", cos(-1.5))));
|
||||
EXPECT_STREQ("-0.416146836547142", gc(xasprintf("%.15g", cos(2.))));
|
||||
EXPECT_TRUE(isnan(cos(NAN)));
|
||||
EXPECT_TRUE(isnan(cos(-NAN)));
|
||||
EXPECT_TRUE(isnan(cos(INFINITY)));
|
||||
EXPECT_TRUE(isnan(cos(-INFINITY)));
|
||||
EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(__DBL_MIN__))));
|
||||
EXPECT_STREQ("-0.99998768942656", gc(xasprintf("%.15g", cos(__DBL_MAX__))));
|
||||
EXPECT_STREQ("0.54030230586814",
|
||||
gc(xasprintf("%.15g", cos(-1.0000000000000002))));
|
||||
EXPECT_STREQ("1", gc(xasprintf("%.15g", cos(-2.1073424255447e-08))));
|
||||
}
|
|
@ -110,6 +110,13 @@ TEST(hypotll, test) {
|
|||
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(INFINITY, INFINITY))));
|
||||
}
|
||||
|
||||
/*
|
||||
hypot (musl) l: 53𝑐 17𝑛𝑠 m: 85𝑐 27𝑛𝑠
|
||||
hypot l: 39𝑐 13𝑛𝑠 m: 66𝑐 21𝑛𝑠
|
||||
hypotf l: 25𝑐 8𝑛𝑠 m: 55𝑐 18𝑛𝑠
|
||||
hypotl l: 43𝑐 14𝑛𝑠 m: 74𝑐 24𝑛𝑠
|
||||
*/
|
||||
|
||||
BENCH(hypot, bench) {
|
||||
volatile double a = 2;
|
||||
volatile double b = 3;
|
||||
|
|
|
@ -34,18 +34,32 @@ TEST(sinl, test) {
|
|||
EXPECT_STREQ("-.479425538604203", gc(xdtoal(sinl(-.5))));
|
||||
EXPECT_STREQ(".8414709794048734", gc(xdtoal(sinl(.99999999))));
|
||||
/* EXPECT_STREQ("-.998836772397", gc(xdtoal(sinl(555555555555)))); */
|
||||
/* EXPECT_STREQ("1", gc(xdtoal(SINL(5.319372648326541e+255L)))); */
|
||||
/* EXPECT_STREQ("1", gc(xdtoal(sinl(5.319372648326541e+255L)))); */
|
||||
}
|
||||
|
||||
TEST(sin, test) {
|
||||
EXPECT_STREQ("0", gc(xasprintf("%.15g", sin(0.))));
|
||||
EXPECT_STREQ("-0", gc(xasprintf("%.15g", sin(-0.))));
|
||||
EXPECT_STREQ("0.0998334166468282", gc(xasprintf("%.15g", sin(.1))));
|
||||
EXPECT_STREQ("-0.0998334166468282", gc(xasprintf("%.15g", sin(-.1))));
|
||||
EXPECT_STREQ("0.479425538604203", gc(xasprintf("%.15g", sin(.5))));
|
||||
EXPECT_STREQ("-0.479425538604203", gc(xasprintf("%.15g", sin(-.5))));
|
||||
EXPECT_STREQ("0.841470984807897", gc(xasprintf("%.15g", sin(1.))));
|
||||
EXPECT_STREQ("-0.841470984807897", gc(xasprintf("%.15g", sin(-1.))));
|
||||
EXPECT_STREQ("0.997494986604054", gc(xasprintf("%.15g", sin(1.5))));
|
||||
EXPECT_STREQ("-0.997494986604054", gc(xasprintf("%.15g", sin(-1.5))));
|
||||
EXPECT_STREQ("0.909297426825682", gc(xasprintf("%.15g", sin(2.))));
|
||||
EXPECT_TRUE(isnan(sin(NAN)));
|
||||
EXPECT_TRUE(isnan(sin(+INFINITY)));
|
||||
EXPECT_TRUE(isnan(sin(-NAN)));
|
||||
EXPECT_TRUE(isnan(sin(INFINITY)));
|
||||
EXPECT_TRUE(isnan(sin(-INFINITY)));
|
||||
EXPECT_STREQ("NAN", gc(xdtoa(sin(NAN))));
|
||||
EXPECT_STREQ(".479425538604203", gc(xdtoa(sin(.5))));
|
||||
EXPECT_STREQ("-.479425538604203", gc(xdtoa(sin(-.5))));
|
||||
EXPECT_STREQ(".479425538604203", gc(xdtoa(sin(.5))));
|
||||
EXPECT_STREQ("-.479425538604203", gc(xdtoa(sin(-.5))));
|
||||
EXPECT_STREQ("2.2250738585072e-308",
|
||||
gc(xasprintf("%.15g", sin(__DBL_MIN__))));
|
||||
EXPECT_STREQ("0.00496195478918406", gc(xasprintf("%.15g", sin(__DBL_MAX__))));
|
||||
EXPECT_STREQ("-0.841470984807897",
|
||||
gc(xasprintf("%.15g", sin(-1.0000000000000002))));
|
||||
EXPECT_STREQ("-2.1073424255447e-08",
|
||||
gc(xasprintf("%.15g", sin(-2.1073424255447e-08))));
|
||||
}
|
||||
|
||||
TEST(sinf, test) {
|
||||
|
|
37
test/libc/tinymath/sincos_test.c
Normal file
37
test/libc/tinymath/sincos_test.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
TEST(sincos, test) {
|
||||
double sine, cosine;
|
||||
sincos(.1, &sine, &cosine);
|
||||
EXPECT_STREQ("0.0998334166468282", gc(xasprintf("%.15g", sine)));
|
||||
EXPECT_STREQ("0.995004165278026", gc(xasprintf("%.15g", cosine)));
|
||||
}
|
||||
|
||||
BENCH(sincos, bench) {
|
||||
volatile double x = 31337;
|
||||
volatile double sine, cosine;
|
||||
EZBENCH2("sin+cos", donothing, (sin(x), cos(x)));
|
||||
EZBENCH2("sincos", donothing, sincos(x, &sine, &cosine));
|
||||
}
|
|
@ -36,6 +36,5 @@ TEST(tan, test) {
|
|||
EXPECT_STREQ("-nan", gc(xasprintf("%.15g", tan(-INFINITY))));
|
||||
EXPECT_STREQ("2.2250738585072e-308",
|
||||
gc(xasprintf("%.15g", tan(__DBL_MIN__))));
|
||||
/* EXPECT_STREQ("-0.0049620158744449", */
|
||||
/* gc(xasprintf("%.15g", tan(__DBL_MAX__)))); */
|
||||
EXPECT_STREQ("-0.0049620158744449", gc(xasprintf("%.15g", tan(__DBL_MAX__))));
|
||||
}
|
||||
|
|
|
@ -36,13 +36,28 @@ TEST(tanhl, test) {
|
|||
}
|
||||
|
||||
TEST(tanh, test) {
|
||||
EXPECT_STREQ(".0996679946249559", gc(xdtoa(tanh(+.1))));
|
||||
EXPECT_STREQ("-.0996679946249559", gc(xdtoa(tanh(-.1))));
|
||||
EXPECT_STREQ("0", gc(xdtoa(tanh(0))));
|
||||
EXPECT_STREQ("-0", gc(xdtoa(tanh(-0.))));
|
||||
EXPECT_STREQ("0", gc(xasprintf("%.15g", tanh(0.))));
|
||||
EXPECT_STREQ("-0", gc(xasprintf("%.15g", tanh(-0.))));
|
||||
EXPECT_STREQ("0.0996679946249558", gc(xasprintf("%.15g", tanh(.1))));
|
||||
EXPECT_STREQ("-0.0996679946249558", gc(xasprintf("%.15g", tanh(-.1))));
|
||||
EXPECT_STREQ("0.46211715726001", gc(xasprintf("%.15g", tanh(.5))));
|
||||
EXPECT_STREQ("-0.46211715726001", gc(xasprintf("%.15g", tanh(-.5))));
|
||||
EXPECT_STREQ("0.761594155955765", gc(xasprintf("%.15g", tanh(1.))));
|
||||
EXPECT_STREQ("-0.761594155955765", gc(xasprintf("%.15g", tanh(-1.))));
|
||||
EXPECT_STREQ("0.905148253644866", gc(xasprintf("%.15g", tanh(1.5))));
|
||||
EXPECT_STREQ("-0.905148253644866", gc(xasprintf("%.15g", tanh(-1.5))));
|
||||
EXPECT_STREQ("0.964027580075817", gc(xasprintf("%.15g", tanh(2.))));
|
||||
EXPECT_TRUE(isnan(tanh(NAN)));
|
||||
EXPECT_STREQ("1", gc(xdtoa(tanh(INFINITY))));
|
||||
EXPECT_STREQ("-1", gc(xdtoa(tanh(-INFINITY))));
|
||||
EXPECT_TRUE(isnan(tanh(-NAN)));
|
||||
EXPECT_STREQ("1", gc(xasprintf("%.15g", tanh(INFINITY))));
|
||||
EXPECT_STREQ("-1", gc(xasprintf("%.15g", tanh(-INFINITY))));
|
||||
EXPECT_STREQ("2.2250738585072e-308",
|
||||
gc(xasprintf("%.15g", tanh(__DBL_MIN__))));
|
||||
EXPECT_STREQ("1", gc(xasprintf("%.15g", tanh(__DBL_MAX__))));
|
||||
EXPECT_STREQ("-0.761594155955765",
|
||||
gc(xasprintf("%.15g", tanh(-1.0000000000000002))));
|
||||
EXPECT_STREQ("-2.1073424255447e-08",
|
||||
gc(xasprintf("%.15g", tanh(-2.1073424255447e-08))));
|
||||
}
|
||||
|
||||
TEST(tanhf, test) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue