forked from zenorogue/hyperrogue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.cpp
More file actions
132 lines (111 loc) · 4.12 KB
/
tests.cpp
File metadata and controls
132 lines (111 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "../hyper.h"
#include <iostream>
#include <thread>
namespace hr {
namespace tests {
int errors = 0;
string test_eq(hyperpoint h1, hyperpoint h2, ld err = 1e-6) {
if(sqhypot_d(MDIM, h1 -h2) < err)
return lalign(0, "OK ", h1, " ", h2);
else {
errors++;
return lalign(0, "ERROR", " ", h1, " ", h2);
}
}
string test_eq(transmatrix T1, transmatrix T2, ld err = 1e-6) {
if(eqmatrix(T1, T2, err))
return "OK";
else {
errors++;
return "ERROR";
}
}
int readArgs() {
using namespace arg;
if(0) ;
else if(argis("-test-dist")) {
start_game();
shift(); int d = argi();
vector<cell*> l = currentmap->allcells();
int unknown = 0;
for(cell *c1: l) if(c1->cpdist <= d)
for(cell *c2: l) if(c2->cpdist <= d) {
int cd = celldistance(c1, c2);
int bcd = bounded_celldistance(c1, c2);
if(bcd == DISTANCE_UNKNOWN)
unknown++;
else if(cd != bcd) {
errors++;
println(hlog, "distance error: ", tie(c1,c2), " cd = ", cd, " bcd = ", bcd);
}
}
int q = 0;
for(cell *c: l) if(c->cpdist <= d) q++;
println(hlog, "cells checked: ", q, " errors: ", errors, " unknown: ", unknown, " in: ", full_geometry_name());
if(errors) exit(1);
}
else if(argis("-test-bt")) {
PHASEFROM(3);
for(int i=0; i<gGUARD; i++) {
eGeometry g = eGeometry(i);
set_geometry(g);
ld aer = bt::area_expansion_rate();
if(!aer) continue;
// if(cgflags & qDEPRECATED) continue;
// if(cgflags & qHYBRID) continue;
// if(arb::in() || arcm::in()) continue;
// if(!(bt::in() || nonisotropic || among(geometry, gEuclidSquare,
println(hlog, "testing geometry: ", ginf[g].menu_displayed_name);
start_game();
int co = bt::expansion_coordinate();
int cx = (co + 1) % WDIM;
int cy = (co + 2) % WDIM;
auto oxy = [&] (ld x, ld y, ld z) { hyperpoint h = Hypc; h[co] = z; h[cx] = x; if(WDIM == 3) h[cy] = y; return tC0(bt::normalized_at(h)); };
ld shrunk_x = geo_dist(oxy(0,0,-1), oxy(.01,0,-1));
ld shrunk_y = geo_dist(oxy(0,0,-1), oxy(0,.01,-1));
ld expand_x = geo_dist(oxy(0,0,+1), oxy(.01,0,+1));
ld expand_y = geo_dist(oxy(0,0,+1), oxy(0,.01,+1));
if(WDIM == 2) shrunk_y = expand_y = 1;
println(hlog, "should be 1: ", lalign(10, (shrunk_x * shrunk_y * bt::area_expansion_rate()) / (expand_x * expand_y)), " : ", tie(shrunk_x, shrunk_y, expand_x, expand_y, aer));
if(geometry == gArnoldCat)
println(hlog, "(but not in Arnold's cat)");
}
}
else if(argis("-test-push")) {
PHASEFROM(3);
for(eGeometry g: {gSol, gNil, gCubeTiling, gSpace534, gCell120}) {
stop_game();
set_geometry(g);
println(hlog, "testing geometry: ", geometry_name());
hyperpoint h = hyperpoint(.1, .2, .3, 1);
h = normalize(h);
println(hlog, "h = ", h);
println(hlog, "test rgpushxto0: ", test_eq(rgpushxto0(h) * C0, h));
println(hlog, "test gpushxto0: ", test_eq(gpushxto0(h) * h, C0));
println(hlog, "test inverses: ", test_eq(inverse(rgpushxto0(h)), gpushxto0(h)));
println(hlog, "test iso_inverse: ", test_eq(iso_inverse(rgpushxto0(h)), gpushxto0(h)));
}
if(errors) exit(1);
}
else if(argis("-partest", [] {
hyperpoint h = point31(.01, .05, 0);
if(LDIM == 3) h[2] = .015;
println(hlog, "h = ", h);
println(hlog, "good Ph = ", parabolic13(h));
println(hlog, "good DPh = ", test_eq(h, deparabolic13(parabolic13(h))));
// println(hlog, "bad Ph = ", parabolic10(h));
// println(hlog, "bad DPh = ", test_eq(h, deparabolic10(parabolic10(h))));
if(LDIM == 3) {
println(hlog, "min Ph = ", bt::bt_to_minkowski(h));
println(hlog, "min DPh = ", test_eq(h, bt::minkowski_to_bt(bt::bt_to_minkowski(h))));
}
});
else return 1;
return 0;
}
auto hooks = addHook(hooks_args, 100, readArgs);
// Bolza:: genus 2 => Euler characteristic -2
// octagon: -2/6
// ~> 6 octagons
}
}