# Path: expremigen/patterns/pchord.py
# class Pchord(Pattern):
#     """
#     special pattern that is never flattened; interpreted as a chord by the rest of the system
#     """
# 
#     def __init__(self, notes=0):
#         super().__init__()
#         self.notes = notes
# 
#     def __str__(self):
#         return "{0}({1})".format(self.__class__.__name__, self.notes)
# 
#     def __iter__(self):
#         yield Pchord(self.notes)
# 
#     def __repr__(self):
#         return self.__str__()
# 
#     def __eq__(self, other):
#         return self.notes == other.notes
# 
# Path: expremigen/patterns/pconst.py
# class Pconst(Pattern):
#     """
#     pattern that returns a given "constant" for "repeats" time
#     """
# 
#     def __init__(self, constant=0, repeats=sys.maxsize):
#         super().__init__()
#         self.constant = constant
#         self.repeats = repeats
# 
#     def __str__(self):
#         return "{0}({1}, {2})".format(self.__class__.__name__, self.constant, self.repeats)
# 
#     def __iter__(self):
#         return flatten(c for c in itertools.repeat(self.constant, self.repeats))
# 
#     def __repr__(self):
#         return self.__str__()
# 
# Path: expremigen/patterns/pseq.py
# class Pseq(Pattern):
#     """
#     pattern that generates numbers one by one from a list
#     """
# 
#     def __init__(self, alist=None, repeats=sys.maxsize):
#         super().__init__()
#         if alist is None:
#             alist = []
#         self.alist = copy.deepcopy(alist)
#         self.repeats = repeats
# 
#     def __iter__(self):
#         return flatten(j for i in itertools.repeat(self.alist, self.repeats) for j in i)
# 
#     def __str__(self):
#         return "{0}({1}, {2})".format(self.__class__.__name__, self.alist, self.repeats)


import unittest
from expremigen.patterns.pchord import Pchord
from expremigen.patterns.pconst import Pconst
from expremigen.patterns.pseq import Pseq



class TestPseq(unittest.TestCase):
    def test_normal(self):
        a = [i for i in Pseq([4, 5, 6], 2)]
        self.assertEqual(a, [4, 5, 6] * 2)

    def test_empty(self):
        b = [i for i in Pseq([4, 5, 6], 0)]
        self.assertEqual(b, [])

    def test_adult(self):
        d = [i for i in Pseq(["X", "Y", "X"], 3)]
        self.assertEqual(d, ["X", "Y", "X"] * 3)

    def test_repr(self):
        self.assertEqual("{0}".format(Pseq([1, -1, Pconst(2, 2)], 3)), "Pseq([1, -1, Pconst(2, 2)], 3)")

    def test_defaultvalue(self):
        e = [i for i in Pseq(repeats=2)]
        self.assertEqual(e, [])

    def test_nesting(self):
        f = [i for i in Pseq([Pseq([1, Pconst(2, 2)], 2), Pseq([3, 4], 2)], 2)]
        self.assertEqual(f, [1, 2, 2, 1, 2, 2, 3, 4, 3, 4, 1, 2, 2, 1, 2, 2, 3, 4, 3, 4])

    def test_withchord(self):
        f = [i for i in Pseq([Pseq([1, Pconst(2, 2)], 2), Pseq(Pchord([3, 4]), 2)], 2)]

# Path: expremigen/patterns/pchord.py
# class Pchord(Pattern):
#     """
#     special pattern that is never flattened; interpreted as a chord by the rest of the system
#     """
# 
#     def __init__(self, notes=0):
#         super().__init__()
#         self.notes = notes
# 
#     def __str__(self):
#         return "{0}({1})".format(self.__class__.__name__, self.notes)
# 
#     def __iter__(self):
#         yield Pchord(self.notes)
# 
#     def __repr__(self):
#         return self.__str__()
# 
#     def __eq__(self, other):
#         return self.notes == other.notes
# 
# Path: expremigen/patterns/pconst.py
# class Pconst(Pattern):
#     """
#     pattern that returns a given "constant" for "repeats" time
#     """
# 
#     def __init__(self, constant=0, repeats=sys.maxsize):
#         super().__init__()
#         self.constant = constant
#         self.repeats = repeats
# 
#     def __str__(self):
#         return "{0}({1}, {2})".format(self.__class__.__name__, self.constant, self.repeats)
# 
#     def __iter__(self):
#         return flatten(c for c in itertools.repeat(self.constant, self.repeats))
# 
#     def __repr__(self):
#         return self.__str__()
# 
# Path: expremigen/patterns/pseq.py
# class Pseq(Pattern):
#     """
#     pattern that generates numbers one by one from a list
#     """
# 
#     def __init__(self, alist=None, repeats=sys.maxsize):
#         super().__init__()
#         if alist is None:
#             alist = []
#         self.alist = copy.deepcopy(alist)
#         self.repeats = repeats
# 
#     def __iter__(self):
#         return flatten(j for i in itertools.repeat(self.alist, self.repeats) for j in i)
# 
#     def __str__(self):
#         return "{0}({1}, {2})".format(self.__class__.__name__, self.alist, self.repeats)


# Path: tests/testpseq.py
import unittest
from expremigen.patterns.pchord import Pchord
from expremigen.patterns.pconst import Pconst
from expremigen.patterns.pseq import Pseq




class TestPseq(unittest.TestCase):
    def test_normal(self):
        a = [i for i in Pseq([4, 5, 6], 2)]
        self.assertEqual(a, [4, 5, 6] * 2)

    def test_empty(self):
        b = [i for i in Pseq([4, 5, 6], 0)]
        self.assertEqual(b, [])

    def test_adult(self):
        d = [i for i in Pseq(["X", "Y", "X"], 3)]
        self.assertEqual(d, ["X", "Y", "X"] * 3)

    def test_repr(self):
        self.assertEqual("{0}".format(Pseq([1, -1, Pconst(2, 2)], 3)), "Pseq([1, -1, Pconst(2, 2)], 3)")

    def test_defaultvalue(self):
        e = [i for i in Pseq(repeats=2)]
        self.assertEqual(e, [])

    def test_nesting(self):
        f = [i for i in Pseq([Pseq([1, Pconst(2, 2)], 2), Pseq([3, 4], 2)], 2)]
        self.assertEqual(f, [1, 2, 2, 1, 2, 2, 3, 4, 3, 4, 1, 2, 2, 1, 2, 2, 3, 4, 3, 4])

    def test_withchord(self):
        f = [i for i in Pseq([Pseq([1, Pconst(2, 2)], 2), Pseq(Pchord([3, 4]), 2)], 2)]

        self.assertEqual(f, [1, 2, 2, 1, 2, 2, Pchord([3, 4]), Pchord([3, 4]), 1, 2, 2, 1, 2, 2, Pchord([3, 4]),