MCPcopy Create free account
hub / github.com/google-deepmind/alphageometry / GraphTest

Class GraphTest

graph_test.py:28–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27
28class GraphTest(unittest.TestCase):
29
30 @classmethod
31 def setUpClass(cls):
32 super().setUpClass()
33
34 cls.defs = pr.Definition.from_txt_file('defs.txt', to_dict=True)
35 cls.rules = pr.Theorem.from_txt_file('rules.txt', to_dict=True)
36
37 # load a complex setup:
38 txt = 'a b c = triangle a b c; h = orthocenter a b c; h1 = foot a b c; h2 = foot b c a; h3 = foot c a b; g1 g2 g3 g = centroid g1 g2 g3 g a b c; o = circle a b c ? coll h g o' # pylint: disable=line-too-long
39 p = pr.Problem.from_txt(txt, translate=False)
40 cls.g, _ = gh.Graph.build_problem(p, GraphTest.defs)
41
42 def test_build_graph_points(self):
43 g = GraphTest.g
44
45 all_points = g.all_points()
46 all_names = [p.name for p in all_points]
47 self.assertCountEqual(
48 all_names,
49 ['a', 'b', 'c', 'g', 'h', 'o', 'g1', 'g2', 'g3', 'h1', 'h2', 'h3'],
50 )
51
52 def test_build_graph_predicates(self):
53 gr = GraphTest.g
54
55 a, b, c, g, h, o, g1, g2, g3, h1, h2, h3 = gr.names2points(
56 ['a', 'b', 'c', 'g', 'h', 'o', 'g1', 'g2', 'g3', 'h1', 'h2', 'h3']
57 )
58
59 # Explicit statements:
60 self.assertTrue(gr.check_cong([b, g1, g1, c]))
61 self.assertTrue(gr.check_cong([c, g2, g2, a]))
62 self.assertTrue(gr.check_cong([a, g3, g3, b]))
63 self.assertTrue(gr.check_perp([a, h1, b, c]))
64 self.assertTrue(gr.check_perp([b, h2, c, a]))
65 self.assertTrue(gr.check_perp([c, h3, a, b]))
66 self.assertTrue(gr.check_cong([o, a, o, b]))
67 self.assertTrue(gr.check_cong([o, b, o, c]))
68 self.assertTrue(gr.check_cong([o, a, o, c]))
69 self.assertTrue(gr.check_coll([a, g, g1]))
70 self.assertTrue(gr.check_coll([b, g, g2]))
71 self.assertTrue(gr.check_coll([g1, b, c]))
72 self.assertTrue(gr.check_coll([g2, c, a]))
73 self.assertTrue(gr.check_coll([g3, a, b]))
74 self.assertTrue(gr.check_perp([a, h, b, c]))
75 self.assertTrue(gr.check_perp([b, h, c, a]))
76
77 # These are NOT part of the premises:
78 self.assertFalse(gr.check_perp([c, h, a, b]))
79 self.assertFalse(gr.check_coll([c, g, g3]))
80
81 # These are automatically inferred by the graph datastructure:
82 self.assertTrue(gr.check_eqangle([a, h1, b, c, b, h2, c, a]))
83 self.assertTrue(gr.check_eqangle([a, h1, b, h2, b, c, c, a]))
84 self.assertTrue(gr.check_eqratio([b, g1, g1, c, c, g2, g2, a]))
85 self.assertTrue(gr.check_eqratio([b, g1, g1, c, o, a, o, b]))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected