Esempio n. 1
0
 def test_with_empty_arguments(self):
     generator = solution.intertwined_sequences(())
     self.assertTrue(hasattr(generator, "__iter__"))
     self.assertTrue(hasattr(generator, "__next__"))
     self.assertFalse(hasattr(generator, "__getitem__"))
     self.assertFalse(hasattr(generator, "__len__"))
     self.assertEqual([], list(generator))
Esempio n. 2
0
    def test_intertwine(self):
        fibonacci_3_prime_3_bg_3 = solution.intertwined_sequences(
            [
                {"sequence": "fibonacci", "length": 3},
                {"sequence": "primes", "length": 3},
                {"sequence": "alphabet", "code": "bg", "length": 3},
            ]
        )

        self.assertEqual(list(fibonacci_3_prime_3_bg_3), [1, 1, 2, 2, 3, 5, "а", "б", "в"])
Esempio n. 3
0
    def test_for_endless_argument(self):
        def endless_sequences():
            for key in cycle(["fibonacci", "primes", "alphabet"]):
                if key == "alphabet":
                    yield {"sequence": key, "length": 1, "code": "bg"}
                else:
                    yield {"sequence": key, "length": 1}

        generator = solution.intertwined_sequences(endless_sequences())
        self.assertTrue(hasattr(generator, "__iter__"))
        self.assertTrue(hasattr(generator, "__next__"))
        self.assertFalse(hasattr(generator, "__getitem__"))
        self.assertFalse(hasattr(generator, "__len__"))

        solution_result = list(islice(generator, 6))
        self.assertEqual(solution_result, [1, 2, "а", 1, 3, "б"])
Esempio n. 4
0
    def test_all_same(self):
        fibonacci_3_times = solution.intertwined_sequences(
            [
                {"sequence": "fibonacci", "length": 3},
                {"sequence": "fibonacci", "length": 3},
                {"sequence": "fibonacci", "length": 4},
            ]
        )

        result = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
        self.assertTrue(hasattr(fibonacci_3_times, "__iter__"))
        self.assertTrue(hasattr(fibonacci_3_times, "__next__"))
        self.assertFalse(hasattr(fibonacci_3_times, "__getitem__"))
        self.assertFalse(hasattr(fibonacci_3_times, "__len__"))

        solution_result = list(fibonacci_3_times)
        self.assertEqual(solution_result, result)
Esempio n. 5
0
    def test_alphabet_3_times_with_diff_args(self):
        chinese_letters = "蜙跣鉌鳭蟷蠉蟼踸躽輷輴郺暲釂鱞鸄緀綡蒚曋橪"
        alphabet_3_times_diff_args = solution.intertwined_sequences(
            [
                {"sequence": "alphabet", "code": "bg", "length": 3},
                {"sequence": "alphabet", "letters": chinese_letters, "length": 3},
                {"sequence": "alphabet", "code": "lat", "length": 3},
            ]
        )
        self.assertTrue(hasattr(alphabet_3_times_diff_args, "__iter__"))
        self.assertTrue(hasattr(alphabet_3_times_diff_args, "__next__"))
        self.assertFalse(hasattr(alphabet_3_times_diff_args, "__getitem__"))
        self.assertFalse(hasattr(alphabet_3_times_diff_args, "__len__"))

        result = list("абвгдежзи")
        solution_result = list(alphabet_3_times_diff_args)
        self.assertEqual(solution_result, result)
Esempio n. 6
0
    def test_with_same_generator_but_diff_args(self):
        input_ = [
            {"sequence": "square_from_to", "length": 2, "from_": 1, "to_": 6},
            {"sequence": "square_from_to", "length": 2, "from_": 5, "to_": 10},
            {"sequence": "square_from_to", "length": 2, "from_": 10, "to_": 13},
        ]

        input_definitions = {"square_from_to": square_from_to}

        generator = solution.intertwined_sequences(input_, generator_definitions=input_definitions)
        self.assertTrue(hasattr(generator, "__iter__"))
        self.assertTrue(hasattr(generator, "__next__"))
        self.assertFalse(hasattr(generator, "__getitem__"))
        self.assertFalse(hasattr(generator, "__len__"))

        result = [1, 4, 9, 16, 25, 36]
        solution_result = list(generator)
        self.assertEqual(solution_result, result)
Esempio n. 7
0
    def test_with_other_generators(self):
        input_ = [
            {"sequence": "square", "length": 3},
            {"sequence": "pentagonal", "length": 3},
            {"sequence": "catalan", "length": 3},
        ]

        input_definitions = {"square": square, "pentagonal": pentagonal, "catalan": catalan}

        result = [1, 4, 9, 1, 5, 12, 1, 1, 2]
        generator = solution.intertwined_sequences(input_, generator_definitions=input_definitions)
        self.assertTrue(hasattr(generator, "__iter__"))
        self.assertTrue(hasattr(generator, "__next__"))
        self.assertFalse(hasattr(generator, "__getitem__"))
        self.assertFalse(hasattr(generator, "__len__"))

        solution_result = list(generator)
        self.assertEqual(solution_result, result)
Esempio n. 8
0
    def test_with_other_generators_and_args(self):
        input_ = [
            {"sequence": "square_from_to", "length": 2, "from_": 1, "to_": 3},
            {"sequence": "pentagonal_from_to", "length": 2, "from_": 1, "to_": 3},
            {"sequence": "catalan_from_to", "length": 2, "from_": 0, "to_": 3},
        ]

        input_definitions = {
            "square_from_to": square_from_to,
            "pentagonal_from_to": pentagonal_from_to,
            "catalan_from_to": catalan_from_to,
        }

        result = [1, 4, 1, 5, 1, 1]
        generator = solution.intertwined_sequences(input_, generator_definitions=input_definitions)
        self.assertTrue(hasattr(generator, "__iter__"))
        self.assertTrue(hasattr(generator, "__next__"))
        self.assertFalse(hasattr(generator, "__getitem__"))
        self.assertFalse(hasattr(generator, "__len__"))

        solution_result = list(generator)
        self.assertEqual(solution_result, result)