Esempio n. 1
0
 def test_parentheses(self):
     self.assertEqual(1, evaluator.evaluate("(1)"))
     self.assertEqual(-1, evaluator.evaluate("(-1)"))
     self.assertEqual(2, evaluator.evaluate("(1+1)"))
     self.assertEqual(15, evaluator.evaluate("(1+2) * 5"))
     self.assertEqual(3, evaluator.evaluate("(1+2)*(3-1)/((1+(2-1)))"))
     self.assertEqual(
         -8.0, evaluator. evaluate("((1.0 / 0.5) * (2)) *(-2)"))
Esempio n. 2
0
 def test_variables_dict(self):
     stats = {'iops': 1000, 'usage': 0.65, 'count': 503, 'free_space': 407}
     request = {'iops': 500, 'size': 4}
     self.assertEqual(
         1500,
         evaluator.evaluate("stats.iops + request.iops",
                            stats=stats,
                            request=request))
Esempio n. 3
0
 def test_comparisons(self):
     self.assertTrue(evaluator.evaluate("1 < 2"))
     self.assertTrue(evaluator.evaluate("2 > 1"))
     self.assertTrue(evaluator.evaluate("2 != 1"))
     self.assertFalse(evaluator.evaluate("1 > 2"))
     self.assertFalse(evaluator.evaluate("2 < 1"))
     self.assertFalse(evaluator.evaluate("2 == 1"))
     self.assertTrue(evaluator.evaluate("(1 == 1) == !(1 == 2)"))
Esempio n. 4
0
 def test_comparisons(self):
     self.assertTrue(evaluator.evaluate("1 < 2"))
     self.assertTrue(evaluator.evaluate("2 > 1"))
     self.assertTrue(evaluator.evaluate("2 != 1"))
     self.assertFalse(evaluator.evaluate("1 > 2"))
     self.assertFalse(evaluator.evaluate("2 < 1"))
     self.assertFalse(evaluator.evaluate("2 == 1"))
     self.assertTrue(evaluator.evaluate("(1 == 1) == !(1 == 2)"))
Esempio n. 5
0
 def test_simple_integer(self):
     self.assertEqual(2, evaluator.evaluate("1+1"))
     self.assertEqual(9, evaluator.evaluate("2+3+4"))
     self.assertEqual(23, evaluator.evaluate("11+12"))
     self.assertEqual(30, evaluator.evaluate("5*6"))
     self.assertEqual(2, evaluator.evaluate("22/11"))
     self.assertEqual(38, evaluator.evaluate("109-71"))
     self.assertEqual(493,
                      evaluator.evaluate("872 - 453 + 44 / 22 * 4 + 66"))
Esempio n. 6
0
 def test_simple_integer(self):
     self.assertEqual(2, evaluator.evaluate("1+1"))
     self.assertEqual(9, evaluator.evaluate("2+3+4"))
     self.assertEqual(23, evaluator.evaluate("11+12"))
     self.assertEqual(30, evaluator.evaluate("5*6"))
     self.assertEqual(2, evaluator.evaluate("22/11"))
     self.assertEqual(38, evaluator.evaluate("109-71"))
     self.assertEqual(
         493, evaluator.evaluate("872 - 453 + 44 / 22 * 4 + 66"))
Esempio n. 7
0
    def _run_evaluator(self, func, stats):
        """Evaluates a given function using the provided available stats."""
        host_stats = stats["host_stats"]
        host_caps = stats["host_caps"]
        extra_specs = stats["extra_specs"]
        share_stats = stats["share_stats"]

        result = evaluator.evaluate(
            func, extra=extra_specs, stats=host_stats, capabilities=host_caps, share=share_stats
        )

        return result
Esempio n. 8
0
 def test_parentheses(self):
     self.assertEqual(1, evaluator.evaluate("(1)"))
     self.assertEqual(-1, evaluator.evaluate("(-1)"))
     self.assertEqual(2, evaluator.evaluate("(1+1)"))
     self.assertEqual(15, evaluator.evaluate("(1+2) * 5"))
     self.assertEqual(3, evaluator.evaluate("(1+2)*(3-1)/((1+(2-1)))"))
     self.assertEqual(-8.0, evaluator.evaluate("((1.0 / 0.5) * (2)) *(-2)"))
Esempio n. 9
0
    def _run_evaluator(self, func, stats):
        """Evaluates a given function using the provided available stats."""
        host_stats = stats['host_stats']
        host_caps = stats['host_caps']
        extra_specs = stats['extra_specs']
        share_stats = stats['share_stats']

        result = evaluator.evaluate(func,
                                    extra=extra_specs,
                                    stats=host_stats,
                                    capabilities=host_caps,
                                    share=share_stats)

        return result
Esempio n. 10
0
 def test_int_float_mix(self):
     self.assertEqual(2.5, evaluator.evaluate("1.5 + 1"))
     self.assertEqual(4.25, evaluator.evaluate("8.5 / 2"))
     self.assertEqual(5.25, evaluator.evaluate("10/4+0.75    + 2"))
Esempio n. 11
0
 def test_simple_float(self):
     self.assertEqual(2.0, evaluator.evaluate("1.0 + 1.0"))
     self.assertEqual(2.5, evaluator.evaluate("1.5 + 1.0"))
     self.assertEqual(3.0, evaluator.evaluate("1.5 * 2.0"))
Esempio n. 12
0
 def test_ternary_conditional(self):
     self.assertEqual(5, evaluator.evaluate("(1 < 2) ? 5 : 10"))
     self.assertEqual(10, evaluator.evaluate("(1 > 2) ? 5 : 10"))
Esempio n. 13
0
 def test_negative_numbers(self):
     self.assertEqual(-2, evaluator.evaluate("-2"))
     self.assertEqual(-1, evaluator.evaluate("-2+1"))
     self.assertEqual(3, evaluator.evaluate("5+-2"))
Esempio n. 14
0
 def test_exponent(self):
     self.assertEqual(8, evaluator.evaluate("2^3"))
     self.assertEqual(-8, evaluator.evaluate("-2 ^ 3"))
     self.assertEqual(15.625, evaluator.evaluate("2.5 ^ 3"))
     self.assertEqual(8, evaluator.evaluate("4 ^ 1.5"))
Esempio n. 15
0
    def test_logic_ops(self):
        self.assertTrue(evaluator.evaluate("(1 == 1) AND (2 == 2)"))
        self.assertTrue(evaluator.evaluate("(1 == 1) and (2 == 2)"))
        self.assertTrue(evaluator.evaluate("(1 == 1) && (2 == 2)"))
        self.assertFalse(evaluator.evaluate("(1 == 1) && (5 == 2)"))

        self.assertTrue(evaluator.evaluate("(1 == 1) OR (5 == 2)"))
        self.assertTrue(evaluator.evaluate("(1 == 1) or (5 == 2)"))
        self.assertTrue(evaluator.evaluate("(1 == 1) || (5 == 2)"))
        self.assertFalse(evaluator.evaluate("(5 == 1) || (5 == 2)"))

        self.assertFalse(evaluator.evaluate("(1 == 1) AND NOT (2 == 2)"))
        self.assertFalse(evaluator.evaluate("(1 == 1) AND not (2 == 2)"))
        self.assertFalse(evaluator.evaluate("(1 == 1) AND !(2 == 2)"))
        self.assertTrue(evaluator.evaluate("(1 == 1) AND NOT (5 == 2)"))
        self.assertTrue(
            evaluator.evaluate("(1 == 1) OR NOT (2 == 2) "
                               "AND (5 == 5)"))
Esempio n. 16
0
 def test_function(self):
     self.assertEqual(5, evaluator.evaluate("abs(-5)"))
     self.assertEqual(2, evaluator.evaluate("abs(2)"))
     self.assertEqual(1, evaluator.evaluate("min(1, 100)"))
     self.assertEqual(100, evaluator.evaluate("max(1, 100)"))
     self.assertEqual(100, evaluator.evaluate("max(1, 2, 100)"))
Esempio n. 17
0
 def test_function(self):
     self.assertEqual(5, evaluator.evaluate("abs(-5)"))
     self.assertEqual(2, evaluator.evaluate("abs(2)"))
     self.assertEqual(1, evaluator.evaluate("min(1, 100)"))
     self.assertEqual(100, evaluator.evaluate("max(1, 100)"))
     self.assertEqual(100, evaluator.evaluate("max(1, 2, 100)"))
Esempio n. 18
0
 def test_negative_numbers(self):
     self.assertEqual(-2, evaluator.evaluate("-2"))
     self.assertEqual(-1, evaluator.evaluate("-2+1"))
     self.assertEqual(3, evaluator.evaluate("5+-2"))
Esempio n. 19
0
 def test_exponent(self):
     self.assertEqual(8, evaluator.evaluate("2^3"))
     self.assertEqual(-8, evaluator.evaluate("-2 ^ 3"))
     self.assertEqual(15.625, evaluator.evaluate("2.5 ^ 3"))
     self.assertEqual(8, evaluator.evaluate("4 ^ 1.5"))
Esempio n. 20
0
 def test_int_float_mix(self):
     self.assertEqual(2.5, evaluator.evaluate("1.5 + 1"))
     self.assertEqual(4.25, evaluator.evaluate("8.5 / 2"))
     self.assertEqual(5.25, evaluator.evaluate("10/4+0.75    + 2"))
Esempio n. 21
0
 def test_simple_float(self):
     self.assertEqual(2.0, evaluator.evaluate("1.0 + 1.0"))
     self.assertEqual(2.5, evaluator.evaluate("1.5 + 1.0"))
     self.assertEqual(3.0, evaluator.evaluate("1.5 * 2.0"))
Esempio n. 22
0
    def test_logic_ops(self):
        self.assertTrue(evaluator.evaluate("(1 == 1) AND (2 == 2)"))
        self.assertTrue(evaluator.evaluate("(1 == 1) and (2 == 2)"))
        self.assertTrue(evaluator.evaluate("(1 == 1) && (2 == 2)"))
        self.assertFalse(evaluator.evaluate("(1 == 1) && (5 == 2)"))

        self.assertTrue(evaluator.evaluate("(1 == 1) OR (5 == 2)"))
        self.assertTrue(evaluator.evaluate("(1 == 1) or (5 == 2)"))
        self.assertTrue(evaluator.evaluate("(1 == 1) || (5 == 2)"))
        self.assertFalse(evaluator.evaluate("(5 == 1) || (5 == 2)"))

        self.assertFalse(evaluator.evaluate("(1 == 1) AND NOT (2 == 2)"))
        self.assertFalse(evaluator.evaluate("(1 == 1) AND not (2 == 2)"))
        self.assertFalse(evaluator.evaluate("(1 == 1) AND !(2 == 2)"))
        self.assertTrue(evaluator.evaluate("(1 == 1) AND NOT (5 == 2)"))
        self.assertTrue(evaluator.evaluate("(1 == 1) OR NOT (2 == 2) "
                                           "AND (5 == 5)"))
Esempio n. 23
0
 def test_variables_dict(self):
     stats = {'iops': 1000, 'usage': 0.65, 'count': 503, 'free_space': 407}
     request = {'iops': 500, 'size': 4}
     self.assertEqual(1500, evaluator.evaluate("stats.iops + request.iops",
                                               stats=stats,
                                               request=request))
Esempio n. 24
0
 def test_ternary_conditional(self):
     self.assertEqual(5, evaluator.evaluate("(1 < 2) ? 5 : 10"))
     self.assertEqual(10, evaluator.evaluate("(1 > 2) ? 5 : 10"))