Exemple #1
0
    def test_floor_mod_identity_w_ints(self):
        for i in range(100):
            x = randoms.float() * 200 - 100.0
            m = floor(abs(random.gauss(0, 5)))

            if m == 0:
                self.assertEqual(mo_math.floor(x, m), None)
                self.assertEqual(mo_math.mod(x, m), None)
            else:
                self.assertAlmostEqual(mo_math.floor(x, m) + mo_math.mod(x, m),
                                       x,
                                       places=7)
Exemple #2
0
 def test_mod(self):
     self.assertEqual(mo_math.mod(12, 12), 0)
     self.assertEqual(mo_math.mod(11, 12), 11)
     self.assertEqual(mo_math.mod(2, 12), 2)
     self.assertEqual(mo_math.mod(1, 12), 1)
     self.assertEqual(mo_math.mod(-0, 12), 0)
     self.assertEqual(mo_math.mod(-1, 12), 11)
     self.assertEqual(mo_math.mod(-2, 12), 10)
     self.assertEqual(mo_math.mod(-12, 12), 0)
Exemple #3
0
    def test_floor_mod_identity(self):
        for i in range(100):
            x = randoms.float() * 200 - 100.0
            m = abs(random.gauss(0, 5))

            self.assertAlmostEqual(mo_math.floor(x, m) + mo_math.mod(x, m),
                                   x,
                                   places=7)
def assign_colors(values, segments, title):
    next_color = 0
    colors = ["gray"] * len(values)

    for i, _ in enumerate(segments[:-1]):
        start, end = segments[i], segments[i + 1]
        for i in range(start, end):
            colors[i] = COLORS[mod(next_color, len(COLORS))]
        next_color += 1

    fig = go.Figure(data=go.Scatter(
        x=tuple(range(0, len(values))),
        y=values,
        mode="markers",
        marker=dict(color=colors),
    ))
    fig.update_layout(title=title)
    fig.show()