Example #1
0
 def test_magnitude(self):
     """
     """
     v = Vector(1, 1, 1)
     m = v.magnitude
     self.assertTrue(is_number(m))
     self.assertEqual(m, np.sqrt(3))
Example #2
0
 def __init__(self, symbol, quantity, si_scale, validate=True):
     """
     symbol: string
     quantity: string
     si_scale: number
     """
     if validate is True:
         assert(is_string(symbol))
         assert(is_string(quantity))
         assert(is_number(si_scale))
     self._symbol = symbol
     self._quantity = quantity
     self._si_scale = si_scale
Example #3
0
def round_to_significant(x, n=1, validate=True):
    """
    Round number to significant figures.
    """
    if validate is True:
        assert(is_number(x))
        assert(is_pos_integer_not_0(n))
    round_to = -int(np.floor(np.log10(np.abs(x)))) + n-1
    out = np.round(x, round_to)
    if is_neg_integer(round_to):
        out = int(out)
    else:
        out = float(out)
    return out
Example #4
0
 def test_magnitude(self):
     """
     """
     m = Vector(1, 1, 1).magnitude
     self.assertTrue(is_number(m))
     self.assertEqual(m, np.sqrt(3))