Skip to content

Commit

Permalink
Use tabs for indentation in all tests (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanRenison authored Oct 25, 2023
1 parent 966095d commit 81d547a
Show file tree
Hide file tree
Showing 26 changed files with 999 additions and 999 deletions.
60 changes: 30 additions & 30 deletions stress-tests/data-structures/LineContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@ namespace other {
// source: https://github.com/niklasb/contest-algos/blob/master/convex_hull/dynamic.cpp
const ll is_query = -(1LL<<62);
struct Line {
ll m, b;
mutable function<const Line*()> succ;
bool operator<(const Line& rhs) const {
if (rhs.b != is_query) return m < rhs.m;
const Line* s = succ();
if (!s) return 0;
ll x = rhs.m;
return b - s->b < (s->m - m) * x;
}
ll m, b;
mutable function<const Line*()> succ;
bool operator<(const Line& rhs) const {
if (rhs.b != is_query) return m < rhs.m;
const Line* s = succ();
if (!s) return 0;
ll x = rhs.m;
return b - s->b < (s->m - m) * x;
}
};
struct HullDynamic : public multiset<Line> { // will maintain upper hull for maximum
bool bad(iterator y) {
auto z = next(y);
if (y == begin()) {
if (z == end()) return 0;
return y->m == z->m && y->b <= z->b;
}
auto x = prev(y);
if (z == end()) return y->m == x->m && y->b <= x->b;
return (x->b - y->b)*(z->m - y->m) >= (y->b - z->b)*(y->m - x->m);
}
void add(ll m, ll b) {
auto y = insert({ m, b });
y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
if (bad(y)) { erase(y); return; }
while (next(y) != end() && bad(next(y))) erase(next(y));
while (y != begin() && bad(prev(y))) erase(prev(y));
}
ll query(ll x) {
auto l = *lower_bound((Line) { x, is_query });
return l.m * x + l.b;
}
bool bad(iterator y) {
auto z = next(y);
if (y == begin()) {
if (z == end()) return 0;
return y->m == z->m && y->b <= z->b;
}
auto x = prev(y);
if (z == end()) return y->m == x->m && y->b <= x->b;
return (x->b - y->b)*(z->m - y->m) >= (y->b - z->b)*(y->m - x->m);
}
void add(ll m, ll b) {
auto y = insert({ m, b });
y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
if (bad(y)) { erase(y); return; }
while (next(y) != end() && bad(next(y))) erase(next(y));
while (y != begin() && bad(prev(y))) erase(prev(y));
}
ll query(ll x) {
auto l = *lower_bound((Line) { x, is_query });
return l.m * x + l.b;
}
};
}

Expand Down
30 changes: 15 additions & 15 deletions stress-tests/geometry/CircleLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

typedef Point<double> P;
int main() {
{
auto res = circleLine(P(0, 0), 1, P(-1, -1), P(1, 1));
assert(res.size() == 2);
assert((res[1]-P(sqrt(2)/2, sqrt(2)/2)).dist() < 1e-8);
}
{
auto res = circleLine(P(0, 0), 1, P(-5, 1), P(5, 1));
assert(res.size() == 1);
assert((res[0]-P(0,1)).dist() < 1e-8);
}
{
auto res = circleLine(P(4, 4), 1, P(0, 0), P(5, 0));
assert(res.size() == 0);
}
{
auto res = circleLine(P(0, 0), 1, P(-1, -1), P(1, 1));
assert(res.size() == 2);
assert((res[1]-P(sqrt(2)/2, sqrt(2)/2)).dist() < 1e-8);
}
{
auto res = circleLine(P(0, 0), 1, P(-5, 1), P(5, 1));
assert(res.size() == 1);
assert((res[0]-P(0,1)).dist() < 1e-8);
}
{
auto res = circleLine(P(4, 4), 1, P(0, 0), P(5, 0));
assert(res.size() == 0);
}
rep(it,0,100000) {
P a = randIntPt(5);
P b = randIntPt(5);
Expand All @@ -46,5 +46,5 @@ int main() {
assert(!points.empty());
}
}
cout<<"Tests passed!"<<endl;
cout<<"Tests passed!"<<endl;
}
98 changes: 49 additions & 49 deletions stress-tests/geometry/CirclePolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,64 @@
namespace orig{
typedef Point<long double> P;
long double areaCT(P pa, P pb, long double r) {
if (pa.dist() < pb.dist()) swap(pa, pb);
if (sgn(pb.dist()) == 0) return 0;
long double a = pb.dist(), b = pa.dist(), c = (pb - pa).dist();
long double sinB = fabs(pb.cross(pb - pa) / a / c), cosB = pb.dot(pb - pa) / a / c,
sinC = fabs(pa.cross(pb) / a / b), cosC = pa.dot(pb) / a / b;
long double B = atan2(sinB, cosB), C = atan2(sinC, cosC);
if (a > r) {
long double S = C / 2 * r * r, h = a * b * sinC / c;
if (h < r && B < M_PI / 2)
S -= (acos(h / r) * r * r - h * sqrt(r * r - h * h));
return S;
} else if (b > r) {
long double theta = M_PI - B - asin(sinB / r * a);
return a * r * sin(theta) / 2 + (C - theta) / 2 * r * r;
} else return sinC * a * b / 2;
if (pa.dist() < pb.dist()) swap(pa, pb);
if (sgn(pb.dist()) == 0) return 0;
long double a = pb.dist(), b = pa.dist(), c = (pb - pa).dist();
long double sinB = fabs(pb.cross(pb - pa) / a / c), cosB = pb.dot(pb - pa) / a / c,
sinC = fabs(pa.cross(pb) / a / b), cosC = pa.dot(pb) / a / b;
long double B = atan2(sinB, cosB), C = atan2(sinC, cosC);
if (a > r) {
long double S = C / 2 * r * r, h = a * b * sinC / c;
if (h < r && B < M_PI / 2)
S -= (acos(h / r) * r * r - h * sqrt(r * r - h * h));
return S;
} else if (b > r) {
long double theta = M_PI - B - asin(sinB / r * a);
return a * r * sin(theta) / 2 + (C - theta) / 2 * r * r;
} else return sinC * a * b / 2;
}
long double circlePoly(P c, long double r, vector<P> poly) {
long double area = 0;
rep(i,0,sz(poly)){
auto a = poly[i] - c, b = poly[(i+1)%sz(poly)] - c;
area += areaCT(a, b, r) * sgn(a.cross(b));
}
return area;
long double area = 0;
rep(i,0,sz(poly)){
auto a = poly[i] - c, b = poly[(i+1)%sz(poly)] - c;
area += areaCT(a, b, r) * sgn(a.cross(b));
}
return area;
}
}

signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
const int lim=5;
for (int i=0;i<100000; i++) {
ios::sync_with_stdio(0);
cin.tie(0);
const int lim=5;
for (int i=0;i<100000; i++) {

vector<Point<int>> pts;
for (int j=0; j<10; j++) {
int x = rand()%lim, y = rand()%lim;
pts.push_back(Point<int>(x, y));
}
vector<Point<int>> pts;
for (int j=0; j<10; j++) {
int x = rand()%lim, y = rand()%lim;
pts.push_back(Point<int>(x, y));
}

auto polyInt = genPolygon(pts);
auto polyInt = genPolygon(pts);

int cx = rand()%lim, cy = rand()%lim;
auto c = P(cx, cy);
auto c2 = orig::P(cx, cy);
double r= rand()%(2*lim);
int cx = rand()%lim, cy = rand()%lim;
auto c = P(cx, cy);
auto c2 = orig::P(cx, cy);
double r= rand()%(2*lim);

vector<P> poly;
vector<orig::P> poly2;
for (auto j: polyInt) {
poly.push_back(P(j.x, j.y));
poly2.push_back(orig::P(j.x, j.y));
}
auto res1 = circlePoly(c, r, poly);
auto res2 = orig::circlePoly(c2, r, poly2);
vector<P> poly;
vector<orig::P> poly2;
for (auto j: polyInt) {
poly.push_back(P(j.x, j.y));
poly2.push_back(orig::P(j.x, j.y));
}
auto res1 = circlePoly(c, r, poly);
auto res2 = orig::circlePoly(c2, r, poly2);

if (abs(res1 - res2) > 1e-8) {
cout<<abs(res1-res2)<<' '<<res1<<' '<<res2<<endl;
assert(false);
}
}
cout<<"Tests passed!"<<endl;
if (abs(res1 - res2) > 1e-8) {
cout<<abs(res1-res2)<<' '<<res1<<' '<<res2<<endl;
assert(false);
}
}
cout<<"Tests passed!"<<endl;
}
36 changes: 18 additions & 18 deletions stress-tests/geometry/CircleTangents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
typedef Point<double> P;

signed main() {
for (int i = 0; i < 1000000; i++) {
P c1 = randIntPt(5), c2 = randIntPt(5);
double r1 = sqrt(rand()%20), r2 = sqrt(rand()%20);
for (auto sgn : {-1, 1}) {
auto tans = tangents(c1, r1, c2, sgn * r2);
for (int i = 0; i < 1000000; i++) {
P c1 = randIntPt(5), c2 = randIntPt(5);
double r1 = sqrt(rand()%20), r2 = sqrt(rand()%20);
for (auto sgn : {-1, 1}) {
auto tans = tangents(c1, r1, c2, sgn * r2);

if (tans.size() ==1) {
assert((tans[0].first - tans[0].second).dist() < 1e-8);
assert(abs((tans[0].first-c1).dist() - r1) < 1e-8);
assert(abs((tans[0].first-c2).dist() - r2) < 1e-8);
} else if (tans.size() == 2) {
for (auto l : tans) {
assert(abs(abs(lineDist(l.first, l.second, c1))-r1) < 1e-8);
assert(abs(abs(lineDist(l.first, l.second, c2))-r2) < 1e-8);
}
}
}
}
cout<<"Tests passed!"<<endl;
if (tans.size() ==1) {
assert((tans[0].first - tans[0].second).dist() < 1e-8);
assert(abs((tans[0].first-c1).dist() - r1) < 1e-8);
assert(abs((tans[0].first-c2).dist() - r2) < 1e-8);
} else if (tans.size() == 2) {
for (auto l : tans) {
assert(abs(abs(lineDist(l.first, l.second, c1))-r1) < 1e-8);
assert(abs(abs(lineDist(l.first, l.second, c2))-r2) < 1e-8);
}
}
}
}
cout<<"Tests passed!"<<endl;
}
26 changes: 13 additions & 13 deletions stress-tests/geometry/ConvexHull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ vi convexHull(const vector<P>& S) {
}

int main() {
const int SZ = 1e2;
rep(t,0,100000) {
const int GRID=1e3;
vector<P> pts(SZ);
rep(i,0,SZ) pts[i] = P(rand()%GRID, rand()%GRID);
auto res = convexHull(pts);
auto res2 = old::convexHull(pts);
assert(sz(res) == sz(res2));
rep(i,0,sz(res2)) {
assert(pts[res2[i]] == res[i]);
}
}
cout<<"Tests passed!"<<endl;
const int SZ = 1e2;
rep(t,0,100000) {
const int GRID=1e3;
vector<P> pts(SZ);
rep(i,0,SZ) pts[i] = P(rand()%GRID, rand()%GRID);
auto res = convexHull(pts);
auto res2 = old::convexHull(pts);
assert(sz(res) == sz(res2));
rep(i,0,sz(res2)) {
assert(pts[res2[i]] == res[i]);
}
}
cout<<"Tests passed!"<<endl;
}
32 changes: 16 additions & 16 deletions stress-tests/geometry/LineProjectionReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

typedef Point<double> P;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
const int lim = 5;
for (int i = 0; i < 100000; i++) {
P p = P(rand() % lim, rand() % lim);
P a = P(rand() % lim, rand() % lim);
P b = P(rand() % lim, rand() % lim);
while (a == b)
b = P(rand() % lim, rand() % lim);
auto proj = lineProj(a, b, p, false);
auto refl = lineProj(a, b, p, true);
assert(lineDist(a, b, proj) < 1e-8);
auto manProj = (refl + p) / 2;
assert((proj-manProj).dist() < 1e-8);
}
cout<<"Tests passed!"<<endl;
cin.sync_with_stdio(0);
cin.tie(0);
const int lim = 5;
for (int i = 0; i < 100000; i++) {
P p = P(rand() % lim, rand() % lim);
P a = P(rand() % lim, rand() % lim);
P b = P(rand() % lim, rand() % lim);
while (a == b)
b = P(rand() % lim, rand() % lim);
auto proj = lineProj(a, b, p, false);
auto refl = lineProj(a, b, p, true);
assert(lineDist(a, b, proj) < 1e-8);
auto manProj = (refl + p) / 2;
assert((proj-manProj).dist() < 1e-8);
}
cout<<"Tests passed!"<<endl;
}
Loading

0 comments on commit 81d547a

Please sign in to comment.