Exemplo n.º 1
0
 def test_simple_clamp(self):
     result = misc.clamp(1.0, 2.0, 3.0)
     self.assertEqual(result, 2.0)
     result = misc.clamp(4.0, 2.0, 3.0)
     self.assertEqual(result, 3.0)
     result = misc.clamp(3.0, 4.0, 4.0)
     self.assertEqual(result, 4.0)
Exemplo n.º 2
0
 def test_simple_clamp(self):
     result = misc.clamp(1.0, 2.0, 3.0)
     self.assertEqual(result, 2.0)
     result = misc.clamp(4.0, 2.0, 3.0)
     self.assertEqual(result, 3.0)
     result = misc.clamp(3.0, 4.0, 4.0)
     self.assertEqual(result, 4.0)
Exemplo n.º 3
0
    def update_progress(self, progress):
        """Update task progress and notify all registered listeners.

        :param progress: task progress float value between 0.0 and 1.0
        """
        def on_clamped():
            LOG.warn("Progress value must be greater or equal to 0.0 or less"
                     " than or equal to 1.0 instead of being '%s'", progress)
        cleaned_progress = misc.clamp(progress, 0.0, 1.0,
                                      on_clamped=on_clamped)
        self._notifier.notify(EVENT_UPDATE_PROGRESS,
                              {'progress': cleaned_progress})
Exemplo n.º 4
0
    def update_progress(self, progress):
        """Update task progress and notify all registered listeners.

        :param progress: task progress float value between 0.0 and 1.0
        """
        def on_clamped():
            LOG.warn("Progress value must be greater or equal to 0.0 or less"
                     " than or equal to 1.0 instead of being '%s'", progress)
        cleaned_progress = misc.clamp(progress, 0.0, 1.0,
                                      on_clamped=on_clamped)
        self._notifier.notify(EVENT_UPDATE_PROGRESS,
                              {'progress': cleaned_progress})
Exemplo n.º 5
0
    def test_clamped_callback(self):
        calls = []

        def on_clamped():
            calls.append(True)

        misc.clamp(-1, 0.0, 1.0, on_clamped=on_clamped)
        self.assertEqual(1, len(calls))
        calls.pop()

        misc.clamp(0.0, 0.0, 1.0, on_clamped=on_clamped)
        self.assertEqual(0, len(calls))

        misc.clamp(2, 0.0, 1.0, on_clamped=on_clamped)
        self.assertEqual(1, len(calls))
Exemplo n.º 6
0
    def test_clamped_callback(self):
        calls = []

        def on_clamped():
            calls.append(True)

        misc.clamp(-1, 0.0, 1.0, on_clamped=on_clamped)
        self.assertEqual(1, len(calls))
        calls.pop()

        misc.clamp(0.0, 0.0, 1.0, on_clamped=on_clamped)
        self.assertEqual(0, len(calls))

        misc.clamp(2, 0.0, 1.0, on_clamped=on_clamped)
        self.assertEqual(1, len(calls))