Esempio n. 1
0
    def test_BoundaryTracker_get_regions_for_node(self):

        diag = Diagram([(1, 4), (2, 5), (3, 8), (6, 7)])

        bounds = BoundaryTracker()
        region_factory = RegionFactory()

        outside = region_factory.get_next_region_id()
        bounds.add(Span(1, 8), outside, outside)  # Initially all nodes outside

        # Add chord (1,4)
        regionA = region_factory.get_next_region_id()
        bounds.add(Span(1, 4), outside, regionA)

        # Add chord (2,5) - segment (4,5)
        regionB = region_factory.get_next_region_id()
        bounds.add(Span(4, 5), outside, regionB)
        bounds.add(Span(1, 2), regionA, regionB)

        self.assertEqual(([['A', 'B'], ['@', 'A']]),
                         bounds.get_regions_for_node(2))
        with self.assertRaisesRegexp(
                Exception,
                "get_regions_for_node: No boundary found containing node: 17"):
            bounds.get_regions_for_node(17)
Esempio n. 2
0
    def test_Boudnaries_update_regions(self):
        bounds = BoundaryTracker()
        region_factory = RegionFactory()

        outside = region_factory.get_next_region_id()
        bounds.add(Span(1, 8), outside, outside)  # Initially all nodes outside

        # Add chord (1,4)
        regionA = region_factory.get_next_region_id()
        bounds.add(Span(1, 4), outside, regionA)

        # Change boundary on span (2,3) from out_A to out_B
        regionB = region_factory.get_next_region_id()
        bounds.update_regions(Span(2, 3), regionA, regionB)
        self.assertEqual([outside, regionB],
                         bounds.get_regions_for_nodes(2, 3))
Esempio n. 3
0
    def test_BoundaryTracker_get_spans_from_node(self):
        # Setup boundaries for 1st three chords in diagram
        diag = Diagram([(1, 4), (2, 5), (3, 8), (6, 7)])

        bounds = BoundaryTracker()
        region_factory = RegionFactory()

        outside = region_factory.get_next_region_id()
        bounds.add(Span(1, 8), outside, outside)  # Initially all nodes outside

        # Add chord (1,4)
        regionA = region_factory.get_next_region_id()
        bounds.add(Span(1, 4), outside, regionA)

        # Add chord (2,5) - segment (4,5)
        regionB = region_factory.get_next_region_id()
        bounds.add(Span(4, 5), outside, regionB)
        # Test available spans to close (4,5) regionB
        spans = bounds.get_spans_from_node(4, diag, 5)
        self.assertEqual(spans, [[1, 2]])
        bounds.add(Span(1, 2), regionA, regionB)

        # Add chord (6, 7) (next in numeric order) span(6,7)
        # It's a 1-move loop, region is already closed
        regionC = region_factory.get_next_region_id()
        bounds.add(Span(6, 7), regionA, regionC)
        bounds.add(Span(5, 6), regionA, regionA)

        # Add chord(3, 8), span(7, 8)
        regionD = region_factory.get_next_region_id()
        bounds.add(Span(7, 8), regionA, regionD)
        # Test available spans to close (7,8) regionD
        spans = bounds.get_spans_from_node(7, diag, 8)
        self.assertEqual(spans, [[5, 6], [6, 7]])
Esempio n. 4
0
    def test_BoundaryTracker_validate_all_regions_closed_3_chord(self):
        "Verify regression on diagram: [(1, 2), (3, 6), (4, 5)]"
        diag = Diagram([(1, 2), (3, 6), (4, 5)])
        bounds = BoundaryTracker()
        region_factory = RegionFactory()

        outside = region_factory.get_next_region_id()
        regionA = region_factory.get_next_region_id()
        regionB = region_factory.get_next_region_id()
        regionC = region_factory.get_next_region_id()

        bounds.add(Span(1, 6), outside, outside)

        bounds.add(Span(1, 2), outside, regionA)
        bounds.add(Span(4, 5), outside, regionB)
        bounds.add(Span(3, 4), outside, regionC)
        bounds.add(Span(5, 6), outside, regionC)
        self.assertTrue(bounds.validate_all_regions_closed(diag))
Esempio n. 5
0
    def test_BoundaryTracker_add(self):
        bounds = BoundaryTracker()
        region_factory = RegionFactory()

        outside = region_factory.get_next_region_id()
        regionA = region_factory.get_next_region_id()
        regionB = region_factory.get_next_region_id()

        bounds.add(Span(1, 4), outside, regionA)
        self.assertEqual([Span(1, 4)], bounds.get(regionA, outside))
        self.assertEqual([Span(1, 4)], bounds.get(outside, regionA))

        bounds.add(Span(6, 9), outside, regionB)
        self.assertEqual([Span(1, 4)], bounds.get(regionA, outside))
        self.assertEqual([Span(6, 9)], bounds.get(outside, regionB))

        bounds.add(Span(3, 8), regionA, regionB)
        self.assertEqual([Span(1, 3)], bounds.get(regionA, outside))
        self.assertEqual([Span(8, 9)], bounds.get(outside, regionB))
        self.assertEqual([Span(3, 8)], bounds.get(regionA, regionB))
Esempio n. 6
0
    def test_BoundaryTracker_validate_all_regions_closed(self):
        # Validate regions after adding boundaries for each chord
        diag = Diagram([(1, 4), (2, 5), (3, 8), (6, 7)])
        bounds = BoundaryTracker()
        region_factory = RegionFactory()

        outside = region_factory.get_next_region_id()
        bounds.add(Span(1, 8), outside, outside)  # Initially all nodes outside
        self.assertTrue(bounds.validate_all_regions_closed(diag))

        # Add chord (1,4)
        regionA = region_factory.get_next_region_id()
        bounds.add(Span(1, 4), outside, regionA)
        self.assertTrue(bounds.validate_all_regions_closed(diag))

        # Add chord (2,5) - segment (4,5)
        regionB = region_factory.get_next_region_id()
        bounds.add(Span(4, 5), outside, regionB)
        bounds.add(Span(1, 2), regionA, regionB)
        self.assertTrue(bounds.validate_all_regions_closed(diag))

        # Add chord (6, 7) (next in numeric order) span(6,7)
        # It's a 1-move loop, region is already closed
        regionC = region_factory.get_next_region_id()
        bounds.add(Span(6, 7), regionA, regionC)
        bounds.add(Span(5, 6), regionA, regionA)
        self.assertTrue(bounds.validate_all_regions_closed(diag))

        # Add chord(3, 8), span(7, 8)
        regionD = region_factory.get_next_region_id()
        bounds.add(Span(7, 8), regionA, regionD)
        self.assertFalse(bounds.validate_all_regions_closed(diag))
        bounds.add(Span(5, 6), regionA, regionD)
        self.assertFalse(bounds.validate_all_regions_closed(diag))
        bounds.add(Span(2, 3), outside, regionD)
        self.assertTrue(bounds.validate_all_regions_closed(diag))
Esempio n. 7
0
 def test_get_ids(self):
     region_factory = RegionFactory()
     self.assertEqual('@', region_factory.get_next_region_id())
     self.assertEqual('A', region_factory.get_next_region_id())
     self.assertEqual('B', region_factory.get_next_region_id())