def test_get_merged_timeline__single_timeline(self):
        """Verify merged timeline of exactly one partial timeline.
        """
        partial_timeline = ['one', 'two', 'three', 'four']
        timeline = Timeline(partial_timelines=[partial_timeline])

        # Verify get_merged_timelines return value
        merged_timelines = timeline.get_merged_timelines()
        self.assertEqual([partial_timeline], merged_timelines)
    def test_get_merged_timelines__full_merge__interleaved(self):
        """Verify that unambiguous interleaved timelines merge correctly.
        """
        partial_timelines = [['two', 'three', 'seven'],
                             ['three', 'four', 'five', 'seven']]
        timeline = Timeline(partial_timelines=partial_timelines)

        merged_timelines = timeline.get_merged_timelines()
        self.assertEqual([['two', 'three', 'four', 'five', 'seven']],
                         merged_timelines)
    def test_get_merged_timelines__full_merge__start_and_end_overlap(self):
        """Verify that unambiguous overlapping timelines merge correctly.
        """
        partial_timelines = [['two', 'three', 'six'],
                             ['six', 'seven'],
                             ['one', 'two']]
        timeline = Timeline(partial_timelines=partial_timelines)

        merged_timelines = timeline.get_merged_timelines()
        self.assertEqual([['one', 'two', 'three', 'six', 'seven']],
                         merged_timelines)
    def test_get_merged_timelines__full_merge__shooting_example(self):
        """Verify that full merge is possible for shooting example.
        """
        partial_timelines = [
            ['shouting', 'fight', 'fleeing'],
            ['fight', 'gunshot', 'panic', 'fleeing'],
            ['anger', 'shouting']]
        timeline = Timeline(partial_timelines=partial_timelines)

        merged_timelines = timeline.get_merged_timelines()
        self.assertEqual([['anger', 'shouting', 'fight', 'gunshot', 'panic', 'fleeing']],
                         merged_timelines)
    def test_get_merged_timelines__no_merge__scandal_example(self):
        """Verify that no merge is possible for scandal example.
        """
        partial_timelines = [
            ['argument', 'coverup', 'pointing'],
            ['press brief', 'scandal', 'pointing'],
            ['argument', 'bribe']]
        timeline = Timeline(partial_timelines=partial_timelines)

        merged_timelines = timeline.get_merged_timelines()
        expected_timelines = partial_timelines
        self.assertEqual(len(expected_timelines), len(merged_timelines))
        for merged_timeline in merged_timelines:
            self.assertTrue(merged_timeline in expected_timelines)
    def test_get_merged_timelines__partial_merge(self):
        """Verify that ambiguous partial timelines are merged as far as possible.
        """
        partial_timelines = [['two', 'three', 'four', 'seven', 'eight'],
                             ['one', 'two', 'five', 'six', 'seven']]
        timeline = Timeline(partial_timelines=partial_timelines)

        merged_timelines = timeline.get_merged_timelines()
        expected_timelines = [
            ['one', 'two', 'three', 'four', 'seven', 'eight'],
            ['one', 'two', 'five', 'six', 'seven', 'eight']]
        self.assertEqual(len(expected_timelines), len(merged_timelines))
        for merged_timeline in merged_timelines:
            self.assertTrue(merged_timeline in expected_timelines)
    def test_get_merged_timelines__partial_merge__foiled_mugging_example(self):
        """Verify that partial merge is possible for foiled_mugging example.
        """
        partial_timelines = [
            ['shadowy figure', 'demands', 'scream', 'siren'],
            ['shadowy figure', 'pointed gun', 'scream']]
        timeline = Timeline(partial_timelines=partial_timelines)

        merged_timelines = timeline.get_merged_timelines()
        expected_timelines = [
            ['shadowy figure', 'demands', 'scream', 'siren'],
            ['shadowy figure', 'pointed gun', 'scream', 'siren']]
        self.assertEqual(len(expected_timelines), len(merged_timelines))
        for merged_timeline in merged_timelines:
            self.assertTrue(merged_timeline in expected_timelines)
    def test_get_merged_timelines__partial_merge__arson_example(self):
        """Verify that partial merge is possible for arson example.
        """
        partial_timelines = [
            ['pouring gas', 'laughing', 'lighting match', 'fire'],
            ['buying gas', 'pouring gas', 'crying', 'fire', 'smoke']]
        timeline = Timeline(partial_timelines=partial_timelines)

        merged_timelines = timeline.get_merged_timelines()
        expected_timelines = [
            ['buying gas', 'pouring gas', 'crying', 'fire', 'smoke'],
            ['buying gas', 'pouring gas', 'laughing', 'lighting match', 'fire', 'smoke']]
        self.assertEqual(len(expected_timelines), len(merged_timelines))
        for merged_timeline in merged_timelines:
            self.assertTrue(merged_timeline in expected_timelines)
    def test_get_merged_timelines__multiple_partial_merge(self):
        """Verify that ambiguous partial timelines are merged in multiple places.

        Note that generating four timelines may not be the desired behavior. Rather, we 
        would like two timelines with merged fronts, middles, and ends, one timeline with 
        the divergent sections of the first partial timeline and the other with the
        divergent sections of the second partial timeline.
        """
        partial_timelines = [['two', 'three', 'four', 'six', 'seven', 'eight', 'nine', 'eleven'],
                             ['one', 'two', 'five', 'six', 'seven', 'ten', 'eleven', 'twelve']]
        timeline = Timeline(partial_timelines=partial_timelines)

        merged_timelines = timeline.get_merged_timelines()
        expected_timelines = [
            ['one', 'two', 'three', 'four', 'six', 'seven', 'eight', 'nine', 'eleven', 'twelve'],
            ['one', 'two', 'three', 'four', 'six', 'seven', 'ten', 'eleven', 'twelve'],
            ['one', 'two', 'five', 'six', 'seven', 'eight', 'nine', 'eleven', 'twelve'],
            ['one', 'two', 'five', 'six', 'seven', 'ten', 'eleven', 'twelve']]
        self.assertEqual(len(expected_timelines), len(merged_timelines))
        for merged_timeline in merged_timelines:
            self.assertTrue(merged_timeline in expected_timelines)
 def test_get_merged_timeline__none(self):
     """Verify merged timeline of nothing.
     """
     timeline = Timeline()
     self.assertEqual([[]], timeline.get_merged_timelines())