Esempio n. 1
0
 def test_multiply(self):
     us = UnitSystem()
     Meter = us.new_dimension("Length", "Meter",)
     Length = Meter.dimension
     Msq = us.add_derived_dimension(Length * Length, "Area", "Meter^2")
     self.assertEquals(
         Meter(10) * Meter(10), Msq(100))
Esempio n. 2
0
    def test_derived_dimension_unit(self):
        us = UnitSystem()
        Meter = us.new_dimension("Length", "Meter")
        Second = us.new_dimension("Time", "Second")

        Length = us.Dimensions.Length
        Msq = us.add_derived_dimension(Length * Length, "Area", "Meter^2")

        self.assertAlmostEqual(
            Meter(10), (Msq(100) / Meter(10)))

        Area = us.Dimensions.Area
        Mcb = us.add_derived_dimension(Area * Length, "Volume", "Meter^3")

        self.assertAlmostEqual(
            Msq(100), Mcb(1000)/(Meter(10)))
Esempio n. 3
0
import unittest
from simple_units.base import (BaseDimension, _fill_relational_table,
                               UnitSystem, InvalidType, InvalidExpressionException)

us = UnitSystem()
Meter = us.new_dimension("Length", "Meter")
Second= us.new_dimension("Time", "Second")
#Minute = Second.dimension.add_unit(60 * Second, "Minute")
Length = Meter.dimension
Meter_2 = us.add_derived_dimension(Length * Length, "Area", "Meter^2")

print Meter(1)
print Meter_2(1)
Feet = us.add_unit("Feet", Meter / 3.208)
print Meter(1), Meter(1).convert_to(Feet)
class TestUnits(unittest.TestCase):


    def test_conversion(self):
        us = UnitSystem()
        Meter = us.new_dimension("Length", "Meter")
        Feet = us.add_unit("Feet", Meter / 3.208)
        Yard = us.add_unit("Yard", Feet * 3)

        f, m = Feet(3.208), Meter(1)
        print f.real_quantity, m.real_quantity
        self.assertAlmostEqual(f.real_quantity,m.real_quantity)
        self.assertUnitAlmostEqual(f,m)
        self.assertAlmostEqual(Feet(3), Yard(1))
        self.assertAlmostEqual(Feet(3), Feet(1) * 3)
        self.assertAlmostEqual(Feet(3), 3 * Feet(1))