def test_comparing_none_base_with_base_less(self): l1 = quantity.Length(100., 'mm') l2 = quantity.Length(1., 'm') self.assertFalse(l1 == l2) self.assertTrue(l1 <= l2) self.assertFalse(l1 >= l2) self.assertFalse(l1 > l2) self.assertTrue(l1 < l2) self.assertTrue(l1 != l2)
def test_acceleration_from_l_t_none_zero(self): l = quantity.Length(2.33, "m") t = quantity.Time(2.33, "s") a1 = l / (t * t) a2 = l / (t**2) a3 = l / t / t self.assertAlmostEqual(a1('m s-2'), float('0.4229'), delta=1e-2) self.assertAlmostEqual(a2('m s-2'), float('0.4229'), delta=1e-2) self.assertAlmostEqual(a3('m s-2'), float('0.4229'), delta=1e-2)
def test_acceleration_from_l_t(self): l = quantity.Length(1, "m") t = quantity.Time(1, "s") a1 = l / (t * t) a2 = l / (t**2) a3 = l / t / t self.assertIsInstance(a1, quantity.Acceleration) self.assertIsInstance(a2, quantity.Acceleration) self.assertIsInstance(a3, quantity.Acceleration)
def test_volumetricflow_233(self): l = quantity.Length(2.33, 'm') v = quantity.Volume(12.649, "m3") l1 = l * l * l t = quantity.Time(2.33, 'h') vf1 = l1 / t vf2 = v / t self.assertIsInstance(vf1, quantity.VolumetricFlow) self.assertAlmostEqual(vf1('m3 h-1'), float('5.4289'), delta=1e-6) self.assertIsInstance(vf2, quantity.VolumetricFlow) self.assertAlmostEqual(vf2('m3 h-1'), float('5.4289'), delta=1e-3)
def test_molar_concentration_from_n_l_v_(self): l = quantity.Length(2.33, 'm') v = quantity.Volume(12.649, 'm3') n = quantity.AmountOfSubstance(1, "mol") mc1 = n / (l * l * l) mc2 = n / (l**3) mc3 = n / l / l / l mc4 = n / v self.assertAlmostEqual(mc1('mol m-3'), float('0.0790'), delta=1e-3) self.assertAlmostEqual(mc2('mol m-3'), float('0.0790'), delta=1e-3) self.assertAlmostEqual(mc3('mol m-3'), float('0.0790'), delta=1e-3) self.assertAlmostEqual(mc4('mol m-3'), float('0.0790'), delta=1e-3)
def test_molar_concentration_from_n_l_v(self): l = quantity.Length(1, 'm') v = quantity.Volume(1, 'm3') n = quantity.AmountOfSubstance(1, "mol") mc1 = n / (l * l * l) mc2 = n / (l**3) mc3 = n / l / l / l mc4 = n / v self.assertEqual(mc1('mol m-3'), float('1.')) self.assertEqual(mc2('mol m-3'), float('1.')) self.assertEqual(mc3('mol m-3'), float('1.')) self.assertEqual(mc4('mol m-3'), float('1.'))
def test_volumetricflow_(self): l = quantity.Length(1, 'm') v1 = l * l * l v2 = l**3 t = quantity.Time(1, 'h') vf1 = v1 / t vf2 = v2 / t vf3 = l * l * l / t self.assertIsInstance(vf1, quantity.VolumetricFlow) self.assertEqual(vf1('m3 h-1'), float('1.')) self.assertIsInstance(vf2, quantity.VolumetricFlow) self.assertEqual(vf2('m3 h-1'), float('1.')) self.assertIsInstance(vf3, quantity.VolumetricFlow) self.assertEqual(vf3('m3 h-1'), float('1.'))
def test_length(self): l = quantity.Length(1.0, 'm') self.assertEqual(l('Em'), float('1e-18')) self.assertEqual(l('Pm'), float('1e-15')) self.assertEqual(l('Tm'), float('1e-12')) self.assertEqual(l('Gm'), float('1e-9')) self.assertEqual(l('Mm'), float('1e-6')) self.assertEqual(l('km'), float('1e-3')) self.assertEqual(l('hm'), float('1e-2')) self.assertEqual(l('dam'), float('0.1')) self.assertEqual(l('m'), float('1')) self.assertEqual(l('dm'), float('10.')) self.assertEqual(l('cm'), float('100.')) self.assertEqual(l('mm'), float('1000.')) self.assertEqual(l('μm'), float('1e6')) self.assertAlmostEqual(l('nm'), float('1e9'), delta=1) self.assertEqual(l('pm'), float('1e12')) self.assertAlmostEqual(l('fm'), float('1e15'), delta=1)
def test_none_si_length_inch_in_to_prefix_m(self): l = quantity.Length(1, 'in') self.assertEqual(l('Em'), float('0.0254e-18')) self.assertEqual(l('Pm'), float('0.0254e-15')) self.assertAlmostEqual(l('Tm'), float('0.0254e-12'), delta=1e-6) self.assertEqual(l('Gm'), float('0.0254e-9')) self.assertEqual(l('Mm'), float('0.0254e-6')) self.assertEqual(l('km'), float('0.0254e-3')) self.assertEqual(l('hm'), float('0.0254e-2')) self.assertEqual(l('dam'), float('0.0254e-1')) self.assertEqual(l('m'), float('0.0254')) self.assertEqual(l('dm'), float('0.0254e1')) self.assertEqual(l('cm'), float('0.0254e2')) self.assertEqual(l('mm'), float('0.0254e3')) self.assertEqual(l('μm'), float('0.0254e6')) self.assertAlmostEqual(l('nm'), float('0.0254e9'), delta=1e-6) self.assertEqual(l('pm'), float('0.0254e12')) self.assertAlmostEqual(l('fm'), float('0.0254e15'), delta=1)
def test_length_zero(self): l = quantity.Length(0, 'm') self.assertEqual(l('Em'), float('0')) self.assertEqual(l('Pm'), float('0')) self.assertEqual(l('Tm'), float('0')) self.assertEqual(l('Gm'), float('0')) self.assertEqual(l('Mm'), float('0')) self.assertEqual(l('km'), float('0')) self.assertEqual(l('hm'), float('0')) self.assertEqual(l('dam'), float('0')) self.assertEqual(l('m'), float('0')) self.assertEqual(l('dm'), float('0')) self.assertEqual(l('cm'), float('0')) self.assertEqual(l('mm'), float('0')) self.assertEqual(l('μm'), float('0')) self.assertEqual(l('nm'), float('0')) self.assertEqual(l('pm'), float('0')) self.assertEqual(l('fm'), float('0')) self.assertEqual(l('am'), float('0'))
def test_length_233(self): l = quantity.Length(2.33, 'm') self.assertAlmostEqual(l('Em'), float('2.33e-18'), delta=1e-6) self.assertAlmostEqual(l('Pm'), float('2.33e-15'), delta=1e-4) self.assertAlmostEqual(l('Tm'), float('2.33e-12'), delta=1e-6) self.assertEqual(l('Gm'), float('2.33e-9')) self.assertEqual(l('Mm'), float('2.33e-6')) self.assertEqual(l('km'), float('2.33e-3')) self.assertEqual(l('hm'), float('2.33e-2')) self.assertEqual(l('dam'), float('2.33e-1')) self.assertEqual(l('m'), float('2.33')) self.assertEqual(l('dm'), float('23.3')) self.assertEqual(l('cm'), float('233.')) self.assertEqual(l('mm'), float('2330.')) self.assertEqual(l('μm'), float('2.33e6')) self.assertEqual(l('nm'), float('2.33e9')) self.assertEqual(l('pm'), float('2.33e12')) self.assertEqual(l('fm'), float('2.33e15')) self.assertEqual(l('am'), float('2.33e18'))
def test_non_si_length(self): l = quantity.Length(1, 'in') self.assertEqual(l('Eyd'), float('0.02778993435448577680525164114e-18')) self.assertEqual(l('Pyd'), float('0.02778993435448577680525164114e-15')) self.assertEqual(l('Tyd'), float('0.02778993435448577680525164114e-12')) self.assertEqual(l('Gyd'), float('0.02778993435448577680525164114e-9')) self.assertEqual(l('Myd'), float('0.02778993435448577680525164114e-6')) self.assertEqual(l('kyd'), float('0.02778993435448577680525164114e-3')) self.assertEqual(l('hyd'), float('0.02778993435448577680525164114e-2')) self.assertEqual(l('dayd'), float('0.02778993435448577680525164114e-1')) self.assertEqual(l('yd'), float('0.02778993435448577680525164114')) self.assertEqual(l('dyd'), float('0.02778993435448577680525164114e1')) self.assertEqual(l('cyd'), float('0.02778993435448577680525164114e2')) self.assertEqual(l('myd'), float('0.02778993435448577680525164114e3')) self.assertEqual(l('μyd'), float('0.02778993435448577680525164114e6')) self.assertEqual(l('nyd'), float('0.02778993435448577680525164114e9')) self.assertEqual(l('pyd'), float('0.02778993435448577680525164114e12')) self.assertEqual(l('fyd'), float('0.02778993435448577680525164114e15')) self.assertEqual(l('ayd'), float('0.02778993435448577680525164114e18'))
def test_none_si_length_inch_to_ft_mi_233(self): l = quantity.Length(2.33, 'in') self.assertAlmostEqual(l('ft'), float('0.1941'), delta=1e-4) self.assertAlmostEqual(l('mi'), float('3.677e-5'), delta=1e-2) self.assertAlmostEqual(l('in'), float('2.33'), delta=1e-2)
def test_none_si_length_inch_to_ft_mi(self): l = quantity.Length(1, 'in') self.assertAlmostEqual(l('ft'), float('0.0833'), delta=1e-2) self.assertAlmostEqual(l('mi'), float('1.578e-5'), delta=1e-2) self.assertAlmostEqual(l('in'), float('1'), delta=1e-2)
def test_si_length_m_to_in_ft_mi_233(self): l = quantity.Length(2.33, 'm') self.assertAlmostEqual(l('in'), float('91.7322'), delta=1e-4) self.assertAlmostEqual(l('ft'), float('7.6443'), delta=1e-4) self.assertAlmostEqual(l('mi'), float('0.00144'), delta=1e-4)
def test_si_length_m_to_in_ft_mi(self): l = quantity.Length(1, 'm') self.assertAlmostEqual(l('in'), float('39.37'), delta=1e-4) self.assertAlmostEqual(l('ft'), float('3.2808'), delta=1e-4) self.assertAlmostEqual(l('mi'), float('0.000621'), delta=1e-4)