knotkit/main.cpp
Cotton Seed 53a139416c Added Zp and unary minus to ring classes. Added *~ to .gitignore.
Added unsigned_extended_gcd.  There are ring/field tests that should
be separated.
2011-12-14 13:07:53 -05:00

127 lines
2.3 KiB
C++

#include <knotkit.h>
// test for ring
template<class R> void
test_ring (int p)
{
R zero (0);
R one (1);
R minus_one (-1);
assert (zero == 0);
assert (zero | zero);
assert (one | zero);
assert (minus_one | zero);
assert (! (zero | one));
assert (! (zero | minus_one));
assert (one.is_unit ());
assert (minus_one.is_unit ());
assert (one.recip () == one);
assert (minus_one.recip () == minus_one);
if (p)
assert (R (p) == 0);
if (p != 2)
assert (one != minus_one);
int n = (p
? std::min (p, 20)
: 20);
for (int i = -n; i <= n; i ++)
{
R x (i);
if (x.is_unit ())
{
assert (x * x.recip () == one);
assert (x.recip () * x == one);
assert (x.recip ().recip () == x);
}
assert (one | x);
assert (minus_one | x);
if (x != 0)
{
assert (x | zero);
assert (! (zero | x));
}
for (int j = -n; j <= n; j ++)
{
R y (j);
assert (- (-x) == x);
assert (x + y == y + x);
assert (x * y == y * x);
if (x != 0 && x | y)
{
R q = y.div (x);
assert (y == q * x);
}
if (x != 0 || y != 0)
{
triple<R, R, R> t = x.extended_gcd (y);
assert (t.first == t.second*x + t.third*y);
}
for (int k = -n; k <= n; k ++)
{
R z (k);
assert ((x + y) + z == x + (y + z));
assert ((x * y) * z == x * (y * z));
assert (x*(y + z) == x*y + x*z);
assert ((x + y)*z == x*z + y*z);
}
}
}
}
template<class F> void
test_field ()
{
for (unsigned i = 1; i <= 8; i ++)
for (unsigned j = 1; j <= rolfsen_crossing_knots (i); j ++)
{
knot_diagram kd (rolfsen_knot (i, j));
show (kd); newline ();
cube<F> c (kd);
mod_map<F> d = c.compute_d (1, 0, 0, 0, 0);
assert (d.compose (d) == 0);
ptr<const quotient_module<F> > H = d.homology ();
display ("H:\n", *H);
chain_complex_simplifier<F> s (c.khC, d, 1);
display ("s.new_C:\n", *s.new_C);
assert (H->dim () == s.new_C->dim ());
}
}
int
main ()
{
test_ring<Z2> (2);
test_ring<Z> (0);
test_ring<Zp<2> > (2);
test_ring<Zp<3> > (3);
test_ring<Zp<5> > (5);
test_ring<Zp<7> > (7);
test_field<Zp<7> > ();
test_field<Zp<5> > ();
test_field<Zp<3> > ();
test_field<Z2> ();
test_field<Zp<2> > ();
}