Пример #1
0
 def test__mul__and__div__(self):
     a = Value.parse('3 [meter / sec]')
     b = Value.parse('2 [kg]')
     c = Value.parse('6 [kg * meter / sec]')
     d = Value.parse('1.5 [meter / (kg * sec)]')
     self.assertEqual(c, a*b)
     self.assertEqual(d, a/b)
Пример #2
0
 def test__add__and__sub__ok(self):
     a = Value.parse('2 [meter / sec]')
     b = Value.parse('3 [meter / sec]')
     c = Value.parse('5 [meter / sec]')
     d = Value.parse('-1 [meter / sec]')
     self.assertEqual(c, a+b)
     self.assertEqual(d, a-b)
Пример #3
0
    def test__cmp__(self):
        a = Value.parse('2 [meter / sec]')
        b = Value.parse('2 [meter / sec]')
        c = Value.parse('3 [meter / sec]')

        self.assertEqual(0, cmp(a, b))
        self.assertLess(0, cmp(c, a))
        self.assertGreater(0, cmp(a, c))
Пример #4
0
 def test__neg__and__pos__(self):
     a = Value.parse('3 [meter / sec]')
     b = Value.parse('-3 [meter / sec]')
     self.assertIs(a, +a)
     self.assertEqual(b, -a)
Пример #5
0
 def test__pow__TypeError_modulus(self):
     a = Value.parse('3 [meter / sec]')
     self.assertRaises(TypeError, pow, a, 2, 4)
Пример #6
0
 def test__pow__no_modulus_nonint_decimal_power_ok(self):
     a = Value.parse('4 [meter / sec]')
     b = Value.parse('8.0 [meter^1.5 / sec^1.5]')
     self.assertEqual(b, a**D('1.5'))
Пример #7
0
 def test__pow__no_modulus_ok(self):
     a = Value.parse('4 [meter / sec]')
     b = Value.parse('16 [meter^2 / sec^2]')
     self.assertEqual(b, a**2)
Пример #8
0
 def test__add__and__sub__Mismatch(self):
     a = Value.parse('2 [meter / sec]')
     b = Value.parse('3 [kg]')
     self.assertRaises(Units.Mismatch, Value.__add__, a, b)
Пример #9
0
 def test__cmp__TypeError(self):
     a = Value.parse('2 [meter / sec]')
     self.assertRaises(TypeError, cmp, a, 'banana')
     self.assertRaises(TypeError, cmp, a, 42)
     self.assertRaises(TypeError, cmp, a, D('42'))
Пример #10
0
 def test__cmp__Mismatch(self):
     a = Value.parse('2 [meter / sec]')
     b = Value.parse('2 [kg]')
     self.assertRaises(Units.Mismatch, cmp, a, b)