"""
Unit tests for the extractor Python interface.
"""


from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

from extractor import extractor, util


class TestExtractor:
    def _test_dna(self, s1, s2, expected_variants):
        s1_swig = util.swig_str(s1)
        s2_swig = util.swig_str(s2)
        extracted = extractor.extract(s1_swig[0], s1_swig[1],
                                      s2_swig[0], s2_swig[1], extractor.TYPE_DNA)

        assert len(extracted.variants) == len(expected_variants)

        for variant, expected_variant in zip(extracted.variants, expected_variants):
            for attribute, expected_value in expected_variant.items():
                assert getattr(variant, attribute) == expected_value

    def test1(self):
        self._test_dna(
            'ATGATGATCAGATACAGTGTGATACAGGTAGTTAGACAA',
            'ATGATTTGATCAGATACATGTGATACCGGTAGTTAGGACAA',
            [{'sample_start': 0,
              'sample_end': 5,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 5,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 5,
              'sample_end': 7,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 5,
              'type': 4,
              'reference_start': 5},
             {'sample_start': 7,
              'sample_end': 18,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 16,
              'type': 1,
              'reference_start': 5},
             {'sample_start': 18,
              'sample_end': 18,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 17,
              'type': 4,
              'reference_start': 16},
             {'sample_start': 18,
              'sample_end': 26,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 25,
              'type': 1,
              'reference_start': 17},
             {'sample_start': 26,
              'sample_end': 27,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 26,
              'type': 4,
              'reference_start': 25},
             {'sample_start': 27,
              'sample_end': 35,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 34,
              'type': 1,
              'reference_start': 26},
             {'sample_start': 35,
              'sample_end': 36,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 34,
              'type': 4,
              'reference_start': 34},
             {'sample_start': 36,
              'sample_end': 41,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 39,
              'type': 1,
              'reference_start': 34}]
        )

    def test2(self):
        self._test_dna(
            'TAAGCACCAGGAGTCCATGAAGAAGATGGCTCCTGCCATGGAATCCCCTACTCTACTGTG',
            'TAAGCACCAGGAGTCCATGAAGAAGCTGGATCCTCCCATGGAATCCCCTACTCTACTGTG',
            [{'sample_start': 0,
              'sample_end': 25,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 25,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 25,
              'sample_end': 26,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 26,
              'type': 4,
              'reference_start': 25},
             {'sample_start': 26,
              'sample_end': 29,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 29,
              'type': 1,
              'reference_start': 26},
             {'sample_start': 29,
              'sample_end': 30,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 30,
              'type': 4,
              'reference_start': 29},
             {'sample_start': 30,
              'sample_end': 34,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 34,
              'type': 1,
              'reference_start': 30},
             {'sample_start': 34,
              'sample_end': 35,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 35,
              'type': 4,
              'reference_start': 34},
             {'sample_start': 35,
              'sample_end': 60,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 60,
              'type': 1,
              'reference_start': 35}]
        )

    def test3(self):
        self._test_dna(
            'TAAGCACCAGGAGTCCATGAAGAAGATGGCTCCTGCCATGGAATCCCCTACTCTA',
            'TAAGCACCAGGAGTCCATGAAGAAGCCATGTCCTGCCATGGAATCCCCTACTCTA',
            [{'sample_start': 0,
              'sample_end': 25,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 25,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 25,
              'sample_end': 29,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 29,
              'type': 2,
              'reference_start': 25},
             {'sample_start': 29,
              'sample_end': 30,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 30,
              'type': 4,
              'reference_start': 29},
             {'sample_start': 30,
              'sample_end': 55,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 55,
              'type': 1,
              'reference_start': 30}]
        )

    def test4(self):
        self._test_dna(
            'TAAGCACCAGGAGTCCATGAAGAAGATGGCTCCTGCCATGGAATCCCCTACTCTA',
            'TAAGCACCAGGAGTCCATGAAGAAGCCATGTCCTGCCATGAATCCCCTACTCTA',
            [{'sample_start': 0,
              'sample_end': 25,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 25,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 25,
              'sample_end': 29,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 29,
              'type': 2,
              'reference_start': 25},
             {'sample_start': 29,
              'sample_end': 30,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 30,
              'type': 4,
              'reference_start': 29},
             {'sample_start': 30,
              'sample_end': 39,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 39,
              'type': 1,
              'reference_start': 30},
             {'sample_start': 39,
              'sample_end': 39,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 40,
              'type': 4,
              'reference_start': 39},
             {'sample_start': 39,
              'sample_end': 54,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 55,
              'type': 1,
              'reference_start': 40}]
        )

    def test5(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 44,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 44,
              'type': 1,
              'reference_start': 0}]
        )

    def test6(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCGGTTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 6,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 6,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 6,
              'sample_end': 7,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 7,
              'type': 4,
              'reference_start': 6},
             {'sample_start': 7,
              'sample_end': 44,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 44,
              'type': 1,
              'reference_start': 7}]
        )

    def test7(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCGTTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 6,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 6,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 6,
              'sample_end': 6,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 7,
              'type': 4,
              'reference_start': 6},
             {'sample_start': 6,
              'sample_end': 43,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 44,
              'type': 1,
              'reference_start': 7}]
        )

    def test8(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCGTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 6,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 6,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 6,
              'sample_end': 6,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 8,
              'type': 4,
              'reference_start': 6},
             {'sample_start': 6,
              'sample_end': 42,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 44,
              'type': 1,
              'reference_start': 8}]
        )

    def test9(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCGCATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 6,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 6,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 6,
              'sample_end': 7,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 6,
              'type': 4,
              'reference_start': 6},
             {'sample_start': 7,
              'sample_end': 45,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 44,
              'type': 1,
              'reference_start': 6}]
        )

    def test10(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCGCCATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 6,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 6,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 6,
              'sample_end': 8,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 6,
              'type': 4,
              'reference_start': 6},
             {'sample_start': 8,
              'sample_end': 46,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 44,
              'type': 1,
              'reference_start': 6}]
        )

    def test11(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCGAATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 7,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 7,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 7,
              'sample_end': 8,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 7,
              'type': 4,
              'reference_start': 7},
             {'sample_start': 8,
              'sample_end': 45,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 44,
              'type': 1,
              'reference_start': 7}])

    def test12(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCGAGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 7,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 7,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 7,
              'sample_end': 9,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 7,
              'type': 4,
              'reference_start': 7},
             {'sample_start': 9,
              'sample_end': 46,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 44,
              'type': 1,
              'reference_start': 7}]
        )

    def test13(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCGACGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 7,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 7,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 7,
              'sample_end': 10,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 7,
              'type': 4,
              'reference_start': 7},
             {'sample_start': 10,
              'sample_end': 47,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 44,
              'type': 1,
              'reference_start': 7}]
        )

    def test14(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCGCGAATCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 6,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 6,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 6,
              'sample_end': 11,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 11,
              'type': 2,
              'reference_start': 6},
             {'sample_start': 11,
              'sample_end': 44,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 44,
              'type': 1,
              'reference_start': 11}]
        )

    def test15(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCGCCTTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 6,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 6,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 6,
              'sample_end': 8,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 7,
              'type': 4,
              'reference_start': 6},
             {'sample_start': 8,
              'sample_end': 45,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 44,
              'type': 1,
              'reference_start': 7}]
        )

    def test16(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCGATTCGCTAGCTTCGTTTTGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 20,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 20,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 20,
              'sample_end': 24,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 23,
              'type': 4,
              'reference_start': 20},
             {'sample_start': 24,
              'sample_end': 45,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 44,
              'type': 1,
              'reference_start': 23}]
        )

    def test17(self):
        self._test_dna(
            'ACGTCGATTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            'ACGTCTCTTCGCTAGCTTCGGGGGATAGATAGAGATATAGAGAT',
            [{'sample_start': 0,
              'sample_end': 5,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 5,
              'type': 1,
              'reference_start': 0},
             {'sample_start': 5,
              'sample_end': 7,
              'transposition_end': 0,
              'transposition_start': 0,
              'reference_end': 7,
              'type': 2,
              'reference_start': 5},
             {'sample_start': 7,
              'sample_end': 44,