mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-04 11:42:28 +00:00
Remove old shuffle header
This commit is contained in:
parent
c7e3d9f7ff
commit
a51ccc8fb1
5 changed files with 64 additions and 32 deletions
38
test/libc/stdio/strfry_test.c
Normal file
38
test/libc/stdio/strfry_test.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2024 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/stdio/rand.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(strfry, empty) {
|
||||
char s[1] = "";
|
||||
EXPECT_EQ(s, strfry(s));
|
||||
EXPECT_STREQ("", s);
|
||||
}
|
||||
|
||||
TEST(strfry, one) {
|
||||
char s[2] = "a";
|
||||
EXPECT_EQ(s, strfry(s));
|
||||
EXPECT_STREQ("a", s);
|
||||
}
|
||||
|
||||
TEST(strfry, test) {
|
||||
char s[5] = "abcd";
|
||||
EXPECT_EQ(s, strfry(s));
|
||||
EXPECT_STREQ("cbda", s);
|
||||
}
|
|
@ -18,7 +18,6 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/mem/shuffle.internal.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
|
@ -82,11 +81,20 @@ TEST(utf32to8, testLargeThompsonPikeEncoded) {
|
|||
-1, 0)));
|
||||
}
|
||||
|
||||
void shuffle(wchar_t *a, int n) {
|
||||
for (int i = n - 1; i >= 1; --i) {
|
||||
int r = rand() % (i + 1);
|
||||
wchar_t t = a[r];
|
||||
a[r] = a[i];
|
||||
a[i] = t;
|
||||
}
|
||||
}
|
||||
|
||||
char *GenerateBranchyUtf8Text(size_t *out_n) {
|
||||
char *p;
|
||||
size_t n;
|
||||
wchar_t *q = gc(utf8to32(kViewables, kViewablesSize, &n));
|
||||
shuffle(lemur64, q, n);
|
||||
shuffle(q, n);
|
||||
p = utf32to8(q, n, &n);
|
||||
if (out_n)
|
||||
*out_n = n;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue