# Path: scripts/trimmer.py
# def trim(source_left, source_right, dest_left, dest_right):
#     fastq_pairs = itertools.izip(
#         FastqStanza.stanza_generator(source_left), FastqStanza.stanza_generator(source_right))
#     for (left_stanza, right_stanza) in fastq_pairs:
#         FastqStanza.trim_to_shortest_sequence_length(left_stanza, right_stanza)
#         dest_left.write(left_stanza.as_text())
#         dest_right.write(right_stanza.as_text())


import unittest
from scripts.trimmer import trim


class TrimmerTest(unittest.TestCase):
    def test_trim_passthroughIfLengthsMatch(self):
        left_stanza = "@id.1\nACGTACGT\n+\nQQQQQQQQ"
        right_stanza = "@id.2\nTGCATGCA\n+\nQQQQQQQQ"
        source_left = MockReader(left_stanza)
        source_right = MockReader(right_stanza)
        dest_left = MockWriter()
        dest_right = MockWriter()

        trim(source_left, source_right, dest_left, dest_right)

        self.assertEqual(left_stanza.splitlines(), dest_left.lines())
        self.assertEqual(right_stanza.splitlines(), dest_right.lines())


    def test_trim_trimsToMinLength(self):
        left_stanza = "@id.1\nACGT\n+\nQQQQ"
        right_stanza = "@id.2\nTGCATGCA\n+\nQQQQQQQQ"
        source_left = MockReader(left_stanza)
        source_right = MockReader(right_stanza)
        dest_left = MockWriter()
        dest_right = MockWriter()


# Path: scripts/trimmer.py
# def trim(source_left, source_right, dest_left, dest_right):
#     fastq_pairs = itertools.izip(
#         FastqStanza.stanza_generator(source_left), FastqStanza.stanza_generator(source_right))
#     for (left_stanza, right_stanza) in fastq_pairs:
#         FastqStanza.trim_to_shortest_sequence_length(left_stanza, right_stanza)
#         dest_left.write(left_stanza.as_text())
#         dest_right.write(right_stanza.as_text())


# Path: test/trimmer_test.py
import unittest
from scripts.trimmer import trim



class TrimmerTest(unittest.TestCase):
    def test_trim_passthroughIfLengthsMatch(self):
        left_stanza = "@id.1\nACGTACGT\n+\nQQQQQQQQ"
        right_stanza = "@id.2\nTGCATGCA\n+\nQQQQQQQQ"
        source_left = MockReader(left_stanza)
        source_right = MockReader(right_stanza)
        dest_left = MockWriter()
        dest_right = MockWriter()

        trim(source_left, source_right, dest_left, dest_right)

        self.assertEqual(left_stanza.splitlines(), dest_left.lines())
        self.assertEqual(right_stanza.splitlines(), dest_right.lines())


    def test_trim_trimsToMinLength(self):
        left_stanza = "@id.1\nACGT\n+\nQQQQ"
        right_stanza = "@id.2\nTGCATGCA\n+\nQQQQQQQQ"
        source_left = MockReader(left_stanza)
        source_right = MockReader(right_stanza)
        dest_left = MockWriter()
        dest_right = MockWriter()


        trim(source_left, source_right, dest_left, dest_right)