def test_fuzz_bisect(): N = 50 for data in generate_fuzz_data(N, lines=2): l1, l2 = data.lines if l1.null() or l2.null() or Vertex(l1, l2).parallel() or Vertex( l1, l2).point.null(): continue V = l1.vector() U = l2.vector() try: (U.norm() / V.norm()).sqrt() except ValueError: continue v0 = Vertex(l1, l2) bisectors = v0.bisect() s0 = v0.spread() s1 = Vertex(l1, bisectors.line1).spread() s2 = Vertex(l1, bisectors.line2).spread() s3 = Vertex(l2, bisectors.line1).spread() s4 = Vertex(l2, bisectors.line2).spread() assert bisectors.spread() == 1
def test_fuzz_grammola(): N = 20 for data in generate_fuzz_data(N, vertices=1, spreads=1): try: K = data.spreads[0] diags = data.vertices[0] if diags.parallel(): continue grammola = diags.grammola(K) d1, d2 = diags.line1, diags.line2 try: point = grammola._point_on() except ValueError: continue except ZeroDivisionError: continue assert PointLine(point, d1).quadrance() + PointLine( point, d2).quadrance() - K == 0 d22, K22 = grammola.co_diagonal(d1) d11, K11 = grammola.co_diagonal(d2) assert d22 == d2 assert d11 == d1 assert K22 == K assert K11 == K d1.geometry = True assert_raises(GeometryError, grammola.co_diagonal, d1) except NullLineError: pass
def test_fuzz_bisect(): N = 50 for data in generate_fuzz_data(N, lines=2): l1, l2 = data.lines if l1.null() or l2.null() or Vertex(l1, l2).parallel() or Vertex(l1, l2).point.null(): continue V = l1.vector() U = l2.vector() try: (U.norm()/V.norm()).sqrt() except ValueError: continue v0 = Vertex(l1, l2) bisectors = v0.bisect() s0 = v0.spread() s1 = Vertex(l1, bisectors.line1).spread() s2 = Vertex(l1, bisectors.line2).spread() s3 = Vertex(l2, bisectors.line1).spread() s4 = Vertex(l2, bisectors.line2).spread() assert bisectors.spread() == 1
def test_fuzz_grammola(): N = 20 for data in generate_fuzz_data(N, vertices=1, spreads=1): try: K = data.spreads[0] diags = data.vertices[0] if diags.parallel(): continue grammola = diags.grammola(K) d1, d2 = diags.line1, diags.line2 try: point = grammola._point_on() except ValueError: continue except ZeroDivisionError: continue assert PointLine(point, d1).quadrance() + PointLine(point, d2).quadrance() - K == 0 d22, K22 = grammola.co_diagonal(d1) d11, K11 = grammola.co_diagonal(d2) assert d22 == d2 assert d11 == d1 assert K22 == K assert K11 == K d1.geometry = True assert_raises(GeometryError, grammola.co_diagonal, d1) except NullLineError: pass
def test_fuzz_parabola(): N = 50 for data in generate_fuzz_data(N, pointlines=1): try: parabola = data.pointlines[0].parabola() assert parabola.is_parabola() except NullLineError: pass
def test_div(): for data in generate_fuzz_data(20, points=1, spreads=1): point = data.points[0] x = data.spreads[0] if x == 0: assert_raises(ZeroDivisionError, point.__div__, x) else: assert x * (point / x) == point
def test_div(): for data in generate_fuzz_data(20, points=1, spreads=1): point = data.points[0] x = data.spreads[0] if x == 0: assert_raises(ZeroDivisionError, point.__div__, x) else: assert x*(point/x) == point
def test_parallel(): N = 20 for data in generate_fuzz_data(N, lines=1): line = data.lines[0] if line.null(): assert_raises(NullLineError, Vertex(line, line).spread) else: assert Vertex(line, line).spread() == 0 assert Vertex(line, line).parallel()
def test_sub(): for data in generate_fuzz_data(20, points=2): point1, point2 = data.points p1 = point1 - point1 p2 = point2 - point2 p3 = (point1 - point2) + (point2 - point1) assert p1.x == p1.y == 0 assert p2.x == p2.y == 0 assert p3.x == p3.y == 0
def test_fuzz_pole_polar(): N = 50 for data in generate_fuzz_data(N, points=1, conics=1): conic = data.conics[0] pole = data.points[0] try: polar = conic.polar(pole) assert pole == conic.pole(polar) except ZeroDivisionError: pass
def test_fuzz_altitude(): N = 20 for data in generate_fuzz_data(N, pointlines=1): pl = data.pointlines[0] if pl.line.null(): assert_raises(NullLineError, pl.altitude) else: alt = pl.altitude() assert PointLine(pl.point, alt.line).on() assert Vertex(alt.line, pl.line).perpendicular() assert PointLine(alt.point, pl.line).on()
def test_fuzz_circle(): N = 50 for data in generate_fuzz_data(N, points=1, spreads=1): centre = data.points[0] K = data.spreads[0] circle = centre.circle(K) assert circle.is_circle() new_centre, new_K = circle.centre_quadrance() assert new_centre == centre assert new_K == K
def test_fuzz_reflection(): N = 20 for data in generate_fuzz_data(N, pointlines=1): pl = data.pointlines[0] if pl.line.null(): assert_raises(NullLineError, pl.reflection) else: ref = pl.reflection() assert pl == ref.reflection() assert pl.altitude().point == ref.altitude().point assert pl.line == ref.line assert ref.quadrance() == pl.quadrance()
def test_construct_quadrance(): f = FiniteField f.base = 37 geom = blue(f) line = Line(f(1), f(1), f(10), geom) point = Point(f(0), f(1), geom) pl = PointLine(point, line) X = pl.construct_quadrance(f(10)) v = pl.construct_spread(f(1) / f(5)) N = 20 for data in generate_fuzz_data(N, pointlines=1, spreads=1): pl = data.pointlines[0] s = data.spreads[0] try: ls = pl.construct_quadrance(s) except ValueError: pass
def test_eval(): for data in generate_fuzz_data(20, points=2, lines=1): point1, point2 = data.points line = data.lines[0] x1, y1 = point1.form() x2, y2 = point2.form() a, b, c = line.form() assert point1.eval(x1, y1) == 0 assert point2.eval(x2, y2) == 0 if point1 != point2: assert point1.eval(x2, y2) == 1 assert point2.eval(x1, y1) == 1 else: assert point1.eval(x2, y2) == 0 assert point2.eval(x1, y1) == 0 assert line.eval(x1, y1) == a * x1 + b * y1 + c assert line.eval(x2, y2) == a * x2 + b * y2 + c
def test_construct_quadrance(): f = FiniteField f.base = 37 geom = blue(f) line = Line(f(1), f(1), f(10), geom) point = Point(f(0), f(1), geom) pl = PointLine(point, line) X = pl.construct_quadrance(f(10)) v = pl.construct_spread(f(1)/f(5)) N = 20 for data in generate_fuzz_data(N, pointlines=1, spreads=1): pl = data.pointlines[0] s = data.spreads[0] try: ls = pl.construct_quadrance(s) except ValueError: pass
def test_eval(): for data in generate_fuzz_data(20, points=2, lines=1): point1, point2 = data.points line = data.lines[0] x1, y1 = point1.form() x2, y2 = point2.form() a, b, c = line.form() assert point1.eval(x1, y1) == 0 assert point2.eval(x2, y2) == 0 if point1 != point2: assert point1.eval(x2, y2) == 1 assert point2.eval(x1, y1) == 1 else: assert point1.eval(x2, y2) == 0 assert point2.eval(x1, y1) == 0 assert line.eval(x1, y1) == a*x1 + b*y1 + c assert line.eval(x2, y2) == a*x2 + b*y2 + c
def test_fuzz_midpoint(): N = 20 for data in generate_fuzz_data(N, points=2): X0, X1 = data.points l0 = LineSegment(X0, X1) l1 = LineSegment(X1, X0) if l0.line.null(): assert l1.line.null() assert_raises(ValueError, l0.midpoint) assert_raises(ValueError, l1.midpoint) continue M0 = l0.midpoint() M1 = l1.midpoint() quadrance = LineSegment(X0, M0).quadrance() assert LineSegment(X0, M0).quadrance() == quadrance assert LineSegment(X1, M0).quadrance() == quadrance assert LineSegment(X0, M1).quadrance() == quadrance assert LineSegment(X1, M1).quadrance() == quadrance
def test_fuzz_init(): N = 20 for data in generate_fuzz_data(N, geoms=2, lines=2, points=2): g0, g1 = data.geoms l0, l1 = data.lines p0, p1 = data.points ls0 = LineSegment(p0, p1) ls1 = LineSegment(p0, p1) assert ls0 == ls1 v0 = Vertex(l0, l1) v1 = Vertex(l1, l0) assert v0 == v1 if g0 != g1: l0.geometry = p0.geometry = g0 l1.geometry = p1.geometry = g1 assert_raises(GeometryError, Vertex, l0, l1) assert_raises(GeometryError, PointLine, p0, l1) assert_raises(GeometryError, LineSegment, p0, p1)
def test_fuzz_tangent(): N = 50 for data in generate_fuzz_data(N, points=1, conics=1): conic = data.conics[0] point = data.points[0] try: tangent = conic.tangent(point) assert conic.is_tangent(tangent) except ValueError: assert not conic.through(point) try: point = conic._point_on() except ValueError: continue except ZeroDivisionError: continue tangent = conic.tangent(point) assert conic.is_tangent(tangent)
def test_construct_spread(): f = FiniteField f.base = 7 geom = blue(f) line = Line(f(0), f(1), f(0), geom) point = Point(f(1), f(2), geom) pl = PointLine(point, line) v = pl.construct_spread(f(1)/f(5)) N = 20 for data in generate_fuzz_data(N, pointlines=1, spreads=1): pl = data.pointlines[0] s = data.spreads[0] if pl.line.null(): assert_raises(NullLineError, pl.construct_spread, s) else: try: v = pl.construct_spread(s) except ValueError: pass
def test_construct_spread(): f = FiniteField f.base = 7 geom = blue(f) line = Line(f(0), f(1), f(0), geom) point = Point(f(1), f(2), geom) pl = PointLine(point, line) v = pl.construct_spread(f(1) / f(5)) N = 20 for data in generate_fuzz_data(N, pointlines=1, spreads=1): pl = data.pointlines[0] s = data.spreads[0] if pl.line.null(): assert_raises(NullLineError, pl.construct_spread, s) else: try: v = pl.construct_spread(s) except ValueError: pass
def test_fuzz_conic(): N = 50 for data in generate_fuzz_data(N, pointlines=1, spreads=1): try: focus_direc = data.pointlines[0] K = data.spreads[0] conic = focus_direc.conic(K) v1, v2, KK = conic.focus_directrix() dir = focus_direc.line focus = focus_direc.point assert K == KK assert v1 == focus_direc or v2 == focus_direc assert Vertex(v1.line, v2.line).parallel() except NullLineError: pass except ZeroDivisionError: #FIXME pass
def test_fuzz_quadrola(): N = 20 for data in generate_fuzz_data(N, line_segments=1, spreads=1): try: K = data.spreads[0] points = data.line_segments[0] quadrola = points.quadrola(K) try: point = quadrola._point_on() except ValueError: continue except ZeroDivisionError: continue assert quadrola.through(point) Q1 = LineSegment(point, points.point1).quadrance() Q2 = LineSegment(point, points.point2).quadrance() assert (Q1 + Q2 + K)*(Q1 + Q2 + K) - 2*(Q1*Q1 + Q2*Q2 + K*K) == 0 except NullLineError: pass
def test_fuzz_quadrola(): N = 20 for data in generate_fuzz_data(N, line_segments=1, spreads=1): try: K = data.spreads[0] points = data.line_segments[0] quadrola = points.quadrola(K) try: point = quadrola._point_on() except ValueError: continue except ZeroDivisionError: continue assert quadrola.through(point) Q1 = LineSegment(point, points.point1).quadrance() Q2 = LineSegment(point, points.point2).quadrance() assert (Q1 + Q2 + K) * (Q1 + Q2 + K) - 2 * (Q1 * Q1 + Q2 * Q2 + K * K) == 0 except NullLineError: pass
def test_mul(): for data in generate_fuzz_data(20, points=1, spreads=1): point = data.points[0] x = data.spreads[0] assert point*x == x*point
def test_add(): for data in generate_fuzz_data(20, points=2): point1, point2 = data.points assert point1 + point2 == point2 + point1
def test_mul(): for data in generate_fuzz_data(20, points=1, spreads=1): point = data.points[0] x = data.spreads[0] assert point * x == x * point