remove outdated/broken tests
This commit is contained in:
parent
58252950d4
commit
aefc398883
10 changed files with 0 additions and 282 deletions
|
@ -1,48 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# This is a quick testing script for taisei’s random number generator.
|
||||
# To use it, compile taisei with -DTSRAND_FLOATTEST and run it once.
|
||||
#
|
||||
# The script will plot a histogram of the data, that should be a
|
||||
# uniform distribution from 0 to 1.
|
||||
#
|
||||
# The error bars are sqrt(bincount) according to poisson statistics.
|
||||
# This is okay at large sample sizes.
|
||||
#
|
||||
# Lastly, we it does a χ²-test. For large sample sizes, (binheight-1)/err
|
||||
# follows a Gaussian distribution. So the sum over this squared will follow the
|
||||
# χ²-distribution with degrees of freedom = number of bins - 1.
|
||||
#
|
||||
# For this distribution, χ²/dof should be around 1.
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import scipy.stats
|
||||
|
||||
plt.style.use('bmh')
|
||||
|
||||
d = np.genfromtxt("/tmp/rand_test")
|
||||
edges = np.arange(-0.1,1.1,0.05)
|
||||
binheight,edges = np.histogram(d,bins=edges)
|
||||
err = np.sqrt(binheight)
|
||||
width = edges[1]-edges[0]
|
||||
|
||||
norm = len(d)*width
|
||||
binheight = binheight/norm
|
||||
err = err/norm
|
||||
|
||||
plt.figure(figsize=(7,5))
|
||||
plt.bar(edges[:-1],binheight,yerr=err,color="#2255bb",width=width)
|
||||
|
||||
# only consider non-empty bins
|
||||
err = err[binheight != 0]
|
||||
binheight = binheight[binheight != 0]
|
||||
dof = len(binheight)-1
|
||||
|
||||
chisq, p = scipy.stats.chisquare(binheight*norm, f_exp=norm, ddof=0, axis=0)
|
||||
print("χ²/dof: %g\np-value: %g"%( chisq/dof, p))
|
||||
|
||||
plt.title("N = %d, $\chi^2/dof$ = %g"%(len(d),chisq/dof))
|
||||
plt.xlim(-0.1,1.1)
|
||||
plt.savefig("/tmp/hist.png",dpi=200)
|
||||
plt.show()
|
30
src/color.c
30
src/color.c
|
@ -160,33 +160,3 @@ char* color_str(Color c) {
|
|||
parse_color(c, &r, &g, &b, &a);
|
||||
return strfmt("rgba(%f, %f, %f, %f) 0x%016"PRIxMAX, r, g, b, a, (uintmax_t)c);
|
||||
}
|
||||
|
||||
// #define COLOR_TEST
|
||||
|
||||
int color_test(void) {
|
||||
#ifdef COLOR_TEST
|
||||
float clra[4];
|
||||
Color clr1, clr2, clr3;
|
||||
|
||||
clr1 = rgba(0.1, 0.2, 0.3, 0.4);
|
||||
parse_color_array(clr1, clra);
|
||||
clr2 = rgba(clra[0], clra[1], clra[2], clra[3]);
|
||||
|
||||
clr3 = derive_color(clr1, CLRMASK_A, rgba(0, 0, 0, -1.0));
|
||||
printf("1: %016"PRIxMAX" (%f %f %f %f)\n", (uintmax_t)clr1,
|
||||
color_component(clr1, CLR_R), color_component(clr1, CLR_G), color_component(clr1, CLR_B), color_component(clr1, CLR_A));
|
||||
printf("2: %016"PRIxMAX" (%f %f %f %f)\n", (uintmax_t)clr2,
|
||||
color_component(clr2, CLR_R), color_component(clr2, CLR_G), color_component(clr2, CLR_B), color_component(clr2, CLR_A));
|
||||
printf("3: %016"PRIxMAX" (%f %f %f %f)\n", (uintmax_t)clr3,
|
||||
color_component(clr3, CLR_R), color_component(clr3, CLR_G), color_component(clr3, CLR_B), color_component(clr3, CLR_A));
|
||||
|
||||
assert(clr1 == clr2);
|
||||
assert(color_component(clr3, CLR_R) == color_component(clr3, CLR_R));
|
||||
assert(color_component(clr3, CLR_G) == color_component(clr3, CLR_G));
|
||||
assert(color_component(clr3, CLR_B) == color_component(clr3, CLR_B));
|
||||
assert(color_component(clr3, CLR_A) == -1.0);
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -74,5 +74,3 @@ char* color_str(Color c) attr_returns_nonnull;
|
|||
(((Color)(ColorComponent)(CLR_ONEVALUE * (g)) & CLR_CMASK) << CLR_G) + \
|
||||
(((Color)(ColorComponent)(CLR_ONEVALUE * (b)) & CLR_CMASK) << CLR_B) + \
|
||||
(CLR_ONEVALUE << CLR_A))
|
||||
|
||||
int color_test(void);
|
||||
|
|
|
@ -491,53 +491,3 @@ void hashtable_print_stringkeys(Hashtable *ht) {
|
|||
(ulong)hashtable_get_approx_overhead(ht)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Testing
|
||||
*/
|
||||
|
||||
// #define HASHTABLE_TEST
|
||||
|
||||
#ifdef HASHTABLE_TEST
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static void hashtable_printstrings(Hashtable *ht) {
|
||||
for(size_t i = 0; i < ht->table_size; ++i) {
|
||||
for(HashtableElement *e = ht->table[i]; e; e = e->next) {
|
||||
log_info("[HT %"PRIuMAX"] %s (%"PRIuMAX"): %s\n", (uintmax_t)i, (char*)e->key, (uintmax_t)e->hash, (char*)e->data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int hashtable_test(void) {
|
||||
#ifdef HASHTABLE_TEST
|
||||
const char *mapping[] = {
|
||||
"honoka", "umi",
|
||||
"test", "12345",
|
||||
"herp", "derp",
|
||||
"hurr", "durr",
|
||||
};
|
||||
|
||||
const size_t elems = sizeof(mapping) / sizeof(char*);
|
||||
Hashtable *ht = hashtable_new_stringkeys();
|
||||
|
||||
for(int i = 0; i < elems; i += 2) {
|
||||
hashtable_set_string(ht, mapping[i], (void*)mapping[i+1]);
|
||||
}
|
||||
|
||||
hashtable_printstrings(ht);
|
||||
log_info("-----\n");
|
||||
hashtable_set_string(ht, "12345", "asdfg");
|
||||
hashtable_unset_string(ht, "test");
|
||||
hashtable_set_string(ht, "herp", "deeeeeerp");
|
||||
hashtable_printstrings(ht);
|
||||
|
||||
hashtable_free(ht);
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -66,8 +66,6 @@ bool hashtable_cmpfunc_ptr(void *p1, void *p2);
|
|||
void hashtable_copyfunc_ptr(void **dst, void *src);
|
||||
hash_t hashtable_hashfunc_ptr(void *val);
|
||||
|
||||
int hashtable_test(void);
|
||||
|
||||
void hashtable_print_stringkeys(Hashtable *ht);
|
||||
size_t hashtable_get_approx_overhead(Hashtable *ht);
|
||||
void hashtable_get_stats(Hashtable *ht, HashtableStats *stats);
|
||||
|
|
62
src/main.c
62
src/main.c
|
@ -72,64 +72,6 @@ static void init_log_file(void) {
|
|||
log_add_output(lvls_file, vfs_open("storage/log.txt", VFS_MODE_WRITE));
|
||||
}
|
||||
|
||||
#ifdef CRC32_BENCHMARK
|
||||
// TODO: move all this crap somewhere
|
||||
|
||||
static void hash_test_run(const char *str, uint32_t init, uint32_t (*hashfunc)(uint32_t, const char*)) {
|
||||
hrtime_t begin = time_get();
|
||||
for(int i = 0; i < 341346740; ++i) {
|
||||
init = hashfunc(init, str);
|
||||
}
|
||||
log_debug("%08x %f", init, (double)(time_get() - begin));
|
||||
}
|
||||
|
||||
static int hash_test(void) {
|
||||
time_init();
|
||||
const char *s;
|
||||
s = "reimu";
|
||||
log_info("-> %s", s);
|
||||
hash_test_run(s, 0, crc32str);
|
||||
hash_test_run(s, 0, crc32str_sse42);
|
||||
s = "sphereness";
|
||||
log_info("-> %s", s);
|
||||
hash_test_run(s, 0, crc32str);
|
||||
hash_test_run(s, 0, crc32str_sse42);
|
||||
s = "res/textures/rabu_raibu.png";
|
||||
log_info("-> %s", s);
|
||||
hash_test_run(s, 0, crc32str);
|
||||
hash_test_run(s, 0, crc32str_sse42);
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
static int hash_test(void) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int run_tests(void) {
|
||||
if(tsrand_test()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(zrwops_test()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(hashtable_test()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(color_test()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(hash_test()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
void sdl_log(void *userdata, int category, SDL_LogPriority priority, const char *message) {
|
||||
log_debug("[%i %i] %s", category, priority, message);
|
||||
|
@ -215,10 +157,6 @@ int main(int argc, char **argv) {
|
|||
|
||||
init_log();
|
||||
|
||||
if(run_tests()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
stage_init_array(); // cli_args depends on this
|
||||
|
||||
// commandline arguments should be parsed as early as possible
|
||||
|
|
47
src/random.c
47
src/random.c
|
@ -90,53 +90,6 @@ float nfrand(void) {
|
|||
return frand() * 2.0 - 1.0;
|
||||
}
|
||||
|
||||
int tsrand_test(void) {
|
||||
#if defined(TSRAND_FLOATTEST)
|
||||
RandomState rnd;
|
||||
|
||||
tsrand_init(&rnd, time(0));
|
||||
tsrand_switch(&rnd);
|
||||
|
||||
for(int i = 0; i < 2000000; ++i) {
|
||||
tsfprintf(stdout, "%f\n", frand());
|
||||
}
|
||||
|
||||
return 1;
|
||||
#elif defined(TSRAND_SEEDTEST)
|
||||
RandomState rnd;
|
||||
tsrand_switch(&rnd);
|
||||
|
||||
int seed = 1337, i, j;
|
||||
log_info("SEED: %d", seed);
|
||||
|
||||
for(i = 0; i < 5; ++i) {
|
||||
log_info("RUN #%i", i);
|
||||
tsrand_seed(seed);
|
||||
|
||||
for(j = 0; j < 5; ++j) {
|
||||
log_info("-> %i", tsrand());
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
#elif defined(TSRAND_RAWTEST)
|
||||
RandomState rnd;
|
||||
SDL_RWops *out = SDL_RWFromFP(stdout, false);
|
||||
|
||||
tsrand_init(&rnd, time(0));
|
||||
tsrand_switch(&rnd);
|
||||
|
||||
for(int i = 0; i < CMWC_CYCLE; ++i) {
|
||||
SDL_WriteLE32(out, tsrand());
|
||||
}
|
||||
|
||||
SDL_RWclose(out);
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// we use this to support multiple rands in a single statement without breaking replays across different builds
|
||||
|
||||
static uint32_t tsrand_array[TSRAND_ARRAY_LIMIT];
|
||||
|
|
|
@ -21,8 +21,6 @@ struct RandomState {
|
|||
|
||||
typedef struct RandomState RandomState;
|
||||
|
||||
int tsrand_test(void);
|
||||
|
||||
void tsrand_init(RandomState *rnd, uint32_t seed);
|
||||
void tsrand_switch(RandomState *rnd);
|
||||
void tsrand_seed_p(RandomState *rnd, uint32_t seed);
|
||||
|
|
|
@ -314,40 +314,3 @@ SDL_RWops* SDL_RWWrapZWriter(SDL_RWops *src, size_t bufsize, bool autoclose) {
|
|||
z_stream* SDL_RWGetZStream(SDL_RWops *rw) {
|
||||
return ZDATA(rw)->stream;
|
||||
}
|
||||
|
||||
int zrwops_test(void) {
|
||||
#ifdef TEST_ZRWOPS
|
||||
const size_t chunksize = 16;
|
||||
char data[] = "I l❤ve H❤n❤ka-chan!xzxzxzxzxzxzxzxzxzxzxzxzxz";
|
||||
char buffer1[sizeof(data) * 2];
|
||||
char buffer2[sizeof(data) * 2];
|
||||
|
||||
memset(buffer1, 0, sizeof(buffer1));
|
||||
memset(buffer2, 0, sizeof(buffer2));
|
||||
|
||||
printbuf(buffer1, sizeof(buffer1));
|
||||
printbuf(buffer2, sizeof(buffer2));
|
||||
|
||||
SDL_RWops *rwmem = SDL_RWFromMem(buffer1, sizeof(buffer1));
|
||||
SDL_RWops *rwz = SDL_RWWrapZWriter(rwmem, chunksize, false);
|
||||
SDL_WriteLE64(rwz, 9000);
|
||||
SDL_RWwrite(rwz, data, 1, sizeof(data));
|
||||
SDL_RWclose(rwz);
|
||||
SDL_RWseek(rwmem, 0, RW_SEEK_SET);
|
||||
rwz = SDL_RWWrapZReader(rwmem, chunksize, true);
|
||||
uint64_t x = SDL_ReadLE64(rwz);
|
||||
SDL_RWread(rwz, buffer2, 1, sizeof(data));
|
||||
SDL_RWclose(rwz);
|
||||
|
||||
printbuf(data, sizeof(data));
|
||||
printbuf(buffer1, sizeof(buffer1));
|
||||
printbuf(buffer2, sizeof(buffer2));
|
||||
|
||||
log_info("%lu %s\n", x, buffer2);
|
||||
|
||||
assert(!memcmp(data, buffer2, sizeof(data)));
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -15,5 +15,3 @@
|
|||
SDL_RWops* SDL_RWWrapZReader(SDL_RWops *src, size_t bufsize, bool autoclose);
|
||||
SDL_RWops* SDL_RWWrapZWriter(SDL_RWops *src, size_t bufsize, bool autoclose);
|
||||
z_stream* SDL_RWGetZStream(SDL_RWops *src);
|
||||
|
||||
int zrwops_test(void);
|
||||
|
|
Loading…
Reference in a new issue