import unittest
from uirapuru import utils


class TestUtils(unittest.TestCase):
    def test_flatten(self):
        a = [[1, 2, 3], [4, 5]]
        self.assertEqual(utils.flatten(a), [1, 2, 3, 4, 5])

    def test_split_by_tempo(self):
        result = utils.split_by_tempo(2.3)
        self.assertEqual(result[0:2], [1.0, 1.0])
        self.assertAlmostEqual(result[2], 0.3)

    def test_split_by_tempo_short(self):
        self.assertAlmostEqual(utils.split_by_tempo(0.5)[0], 0.5)

    def test_split_by_tempo_eight(self):
        result = utils.split_by_tempo(2.5, 0.5)
        self.assertEqual(result, [0.5, 0.5, 0.5, 0.5, 0.5])
