示例#1
0
    def test_convert_weight_to_ml(self):
        """Convert units of weight to milliliters.
        """
        # Two foods with very different densities
        honey = Food.objects.get(name='honey')
        paprika = Food.objects.get(name='paprika')
        # Two units of weight
        gram = Unit.objects.get(name='gram')
        ounce = Unit.objects.get(name='ounce')
        g_per_oz = Equivalence.objects.get(unit=ounce, to_unit=gram).to_quantity

        # Convert units of weight into milliliters
        # Without food, assume 1.0 g/ml
        self.failUnlessEqual(to_ml(gram), 1.0)
        self.failUnlessEqual(to_ml(ounce), g_per_oz)
        # With food, use its density
        self.failUnlessEqual(to_ml(gram, honey), 1.0 / honey.grams_per_ml)
        self.failUnlessEqual(to_ml(gram, paprika), 1.0 / paprika.grams_per_ml)
        self.failUnlessEqual(to_ml(ounce, honey), g_per_oz / honey.grams_per_ml)
        self.failUnlessEqual(to_ml(ounce, paprika), g_per_oz / paprika.grams_per_ml)
示例#2
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)