|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Unit tests for geometry.py.""" |
|
import unittest |
|
|
|
from absl.testing import absltest |
|
import geometry as gm |
|
|
|
|
|
class GeometryTest(unittest.TestCase): |
|
|
|
def _setup_equality_example(self): |
|
|
|
|
|
a = gm.Segment('a') |
|
la = gm.Length('l(a)') |
|
a.connect_to(la) |
|
la.connect_to(a) |
|
|
|
b = gm.Segment('b') |
|
lb = gm.Length('l(b)') |
|
b.connect_to(lb) |
|
lb.connect_to(b) |
|
|
|
c = gm.Segment('c') |
|
lc = gm.Length('l(c)') |
|
c.connect_to(lc) |
|
lc.connect_to(c) |
|
|
|
d = gm.Segment('d') |
|
ld = gm.Length('l(d)') |
|
d.connect_to(ld) |
|
ld.connect_to(d) |
|
|
|
|
|
la.merge([lb], 'fact1') |
|
lb.merge([lc], 'fact2') |
|
la.merge([lc], 'fact3') |
|
lc.merge([ld], 'fact4') |
|
return a, b, c, d, la, lb, lc, ld |
|
|
|
def test_merged_node_representative(self): |
|
_, _, _, _, la, lb, lc, ld = self._setup_equality_example() |
|
|
|
|
|
self.assertEqual(la.rep(), la) |
|
self.assertEqual(lb.rep(), la) |
|
self.assertEqual(lc.rep(), la) |
|
self.assertEqual(ld.rep(), la) |
|
|
|
def test_merged_node_equivalence(self): |
|
_, _, _, _, la, lb, lc, ld = self._setup_equality_example() |
|
|
|
self.assertCountEqual(la.equivs(), [la, lb, lc, ld]) |
|
self.assertCountEqual(lb.equivs(), [la, lb, lc, ld]) |
|
self.assertCountEqual(lc.equivs(), [la, lb, lc, ld]) |
|
self.assertCountEqual(ld.equivs(), [la, lb, lc, ld]) |
|
|
|
def test_bfs_for_equality_transitivity(self): |
|
a, _, _, d, _, _, _, _ = self._setup_equality_example() |
|
|
|
|
|
self.assertCountEqual(gm.why_equal(a, d), ['fact3', 'fact4']) |
|
|
|
|
|
if __name__ == '__main__': |
|
absltest.main() |
|
|