def setUp(self): self.simple_a = make_dimension("a") self.simple_b = make_dimension("b") self.dimension = make_compound_dimension("TEST", ((self.simple_a, 1), (self.simple_b, -1))) self.alt_dimension = make_compound_dimension("TESTAlt", ((self.simple_a, 1), (self.simple_b, -2)))
def test_isinstance(self): a = make_compound_dimension("baseline", ((self.dimA, 1), (self.dimB, -1))) b = make_compound_dimension("compare", ((self.dimA, 1), (self.dimB, -1))) unit_a = make_unit("fromA", a, 1) self.assertTrue(unit_a(1).instance_of(a)) self.assertTrue(unit_a(1).instance_of(b))
def test_unit_name_exponent(self): length = make_unit('Meters', self.dimension, 1) time = make_unit('Seconds', self.alt_dimension, 1) acceleration = make_compound_dimension("Acceleration", ((length, 1), (time, -2))) mpss = make_compound_unit(acceleration, 1) self.assertEqual("MetersPerSecondSquared", mpss.__name__)
def test_unit_name(self): length = make_unit('Meters', self.dimension, 1) time = make_unit('Seconds', self.alt_dimension, 1) velocity = make_compound_dimension("Velocity", ((length, 1), (time, -1))) mps = make_compound_unit(velocity, 1) self.assertEqual("MetersPerSecond", mps.__name__)
def test_multiply_complex_unit(self): first = make_compound_unit(self.dimension, 1) second = make_compound_unit(self.alt_dimension, 1) expected_dim = make_compound_dimension("EXPECTED", ((self.simple_a, 2), (self.simple_b, -3))) expected_unit = make_compound_unit(expected_dim, 1) expected = expected_unit(1) result = first(1) * second(1) self.assertTrue(result.instance_of(expected_dim)) self.assertEqual(expected, result)