Example #1
0
    def test_convert_weight_to_grams(self):
        """Convert units of weight to grams.
        """
        pound = Unit.objects.get(name='pound')
        grams_per_pound = convert_unit('pound', 'gram')
        self.failUnlessEqual(to_grams(pound), grams_per_pound)

        kilo = Unit.objects.get(name='kilogram')
        grams_per_kilo = convert_unit('kilogram', 'gram')
        self.failUnlessEqual(to_grams(kilo), grams_per_kilo)
Example #2
0
 def test_convert_unit_reverse_equivalence(self):
     """Convert from one unit to another with reverse Equivalence.
     """
     # tablespoon --> teaspoon is defined in fixture, but
     # teaspoon --> tablespoon is not, and must use a reverse lookup
     self.failUnlessEqual(convert_unit('teaspoon', 'tablespoon'), 1.0 / 3.0)
Example #3
0
 def test_convert_volume_to_ml(self):
     """Convert units of volume to milliliters.
     """
     cup = Unit.objects.get(name='cup')
     ml_per_cup = convert_unit('cup', 'milliliter')
     self.failUnlessEqual(to_ml(cup), ml_per_cup)
Example #4
0
 def test_convert_unit(self):
     """Convert from one unit to another with direct Equivalence.
     """
     self.failUnlessEqual(convert_unit('pound', 'ounce'), 16)
     self.failUnlessEqual(convert_unit('ounce', 'pound'), 1.0 / 16)