Example #1
0
def convert(fromUnit, toUnit, value):
    """Convert fromUnit value to toUnit."""

    if fromUnit == 'Fahrenheit':
        if toUnit == 'Celcius':
            return float(conversions.convertFahrenheitToCelcius(value))
        elif toUnit == 'Kelvin':
            return float(conversions.convertFahrenheitToKelvin(value))
        else:
            raise ConversionError('{} cannot be converted to {}'.format(fromUnit, toUnit))

    elif fromUnit == 'Celcius':
        if toUnit == 'Fahrenheit':
            return float(conversions.convertCelciusToFahrenheit(value))
        elif toUnit == 'Kelvin':
            return float(conversions.convertCelciusToKelvin(value))
        else:
            raise ConversionError('{} cannot be converted to {}'.format(fromUnit, toUnit))

    elif fromUnit == 'Kelvin':
        if toUnit == 'Fahrenheit':
            return float(conversions.convertKelvinToFahrenheit(value))
        elif toUnit == 'Celcius':
            return float(conversions.convertKelvinToCelcius(value))

    else:
        raise ConversionNotPossible('Cannot perform conversions')
Example #2
0
    def testConvertCelciusToKelvin(self):
        print "\nNow testing convertCelciusToKelvin() function:"

        for i in range(0, len(self.knownValues)):
            result = conversions.convertCelciusToKelvin(self.knownValues[i][0])
            kelvin = self.knownValues[i][1]
            self.assertEqual(kelvin, result)
            print "   testing celcius = %f; %f = %f; Passed" % (
                self.knownValues[i][0], kelvin, result)
Example #3
0
    def testConvertCelciusToKelvin(self):
        print "\nNow testing convertCelciusToKelvin() function:"

        # Iterate through the known values list
        for i in range(0,len(self.knownValues)):
            result = conversions.convertCelciusToKelvin(self.knownValues[i][0]) # result of the conversion from celcius to kelvin
            kelvin = self.knownValues[i][1]
            self.assertEqual(kelvin, result) # comparing if the values are equal
            print "   testing celcius = %f; %f = %f; Passed" % (self.knownValues[i][0], kelvin, result)
Example #4
0
 def testConvertCelciusToKelvin(self):
     """convertToKelvin should give known results."""
     for celcius, kelvin in self.knownKelvinConversions:
         result = float(conversions.convertCelciusToKelvin(celcius))
         self.assertEqual(kelvin, result)
        def testCelciustoKelvin(self):

                for i in range(len(self.cel)):
                        kelvin = conversions.convertCelciusToKelvin(
                                self.cel[i])
                        self.assertEqual(self.kel[i],kelvin,msg='{}K != {}K'.format(kelvin,self.kel[i]))
Example #6
0
 def testConvertCelciusToKelvin(self):
     """convertCelciusToKelvin should give known result with known input"""
     for celcius, _, kelvin in self.knownValues:
         result = conversions.convertCelciusToKelvin(celcius)
         self.assertEqual(kelvin, result)
Example #7
0
 def testSanityCelciusAndKelvin(self):
     """convertKelvinToCelcius(convertCelciusToKelvin(n))==n for all n"""
     for integer in range(1, 4000):
         numeral = conversions.convertCelciusToKelvin(integer)
         result = conversions.convertKelvinToCelcius(numeral)
         self.assertEqual(integer, result)