Esempio n. 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')
Esempio n. 2
0
    def testConvertFahrenheitToCelcius(self):
        print "\nNow testing convertFahrenheitToCelcius function:"

        # Iterate through the known values list
        for i in range(0,len(self.knownValues)):
            result = conversions.convertFahrenheitToCelcius(self.knownValues[i][2]) # result of the conversion from fahrenheit to celcius
            celcius = self.knownValues[i][0]
            self.assertEqual(celcius, result) # comparing if the values are equal
            print "   testing fahrenheit = %f; %f = %f; Passed" % (self.knownValues[i][2], celcius, result)
Esempio n. 3
0
 def test_convertFahrenheitToCelcius(self):
     for x in self.celToFaKnown:
         # Run conversion
         result = conversions.convertFahrenheitToCelcius(x[1])
         # Check result
         self.assertEqual(result, x[0])
         # Print test
         print 'Testing Farenheiht ' + str(x[1]) + ' converts to ' + str(
             x[0]) + ' Celcius.'
Esempio n. 4
0
    def testConvertFahrenheitToCelcius(self):
        print "\nNow testing convertFahrenheitToCelcius function:"

        for i in range(0, len(self.knownValues)):
            result = conversions.convertFahrenheitToCelcius(
                self.knownValues[i][2])
            celcius = self.knownValues[i][0]
            self.assertEqual(celcius, result)
            print "   testing fahrenheit = %f; %f = %f; Passed" % (
                self.knownValues[i][2], celcius, result)
Esempio n. 5
0
 def testFromFahrenheitToCelciusPositive(self):
     print("Checking if the conversion of 932.00F is 500.15C")
     self.assertAlmostEqual(500.00,
                            conversions.convertFahrenheitToCelcius(932.00),
                            places=2)
Esempio n. 6
0
 def testFToC(self):
     """should produce known result with know input"""
     for input, output in self.knownValuesF2C:
         result = conversions.convertFahrenheitToCelcius(input)
         self.assertEqual(output, result, msg = 'Test converting {}F to Celsius. Result {}. Expected {}'.format(input, result, output))
Esempio n. 7
0
 def testConvertFahrenheittoCelcius(self):
     """convertFahrenheitToCelcius should give knownFahrenheitConversion results"""
     for celcius, fahrenheit in self.knownFahrenheitConversions:
         result = float(conversions.convertFahrenheitToCelcius(fahrenheit))
         self.assertEqual(celcius, result)
Esempio n. 8
0
 def negative_value_testing(self):
     self.assertEqual(convertFahrenheitToCelcius(-200.0), 173.15)
Esempio n. 9
0
 def big_value_testing(self):
     self.assertEqual(convertFahrenheitToCelcius(937538), 937938.15)
Esempio n. 10
0
 def decimal_value_testing(self):
     self.assertEqual(convertFahrenheitToCelcius(200.22), 373.37)
Esempio n. 11
0
 def zeroBasedValue_testing(self):
     self.assertEqual(convertFahrenheitToCelcius(0.0), 273.15)
Esempio n. 12
0
 def positiveValue_testing(self):
     self.assertEqual(convertFahrenheitToCelcius(300.0), 573.15)
        def testFahrenheittoCelcius(self):

                for i in range(len(self.fah)):
                        celcius = conversions.convertFahrenheitToCelcius(
                                self.fah[i])
                        self.assertEqual(self.cel[i],celcius,msg='{}C != {}C'.format(celcius,self.cel[i]))
Esempio n. 14
0
 def testconvertFahrenheitToCelcius(self):
     print 'Testing that convertFahrenheitToCelcius returns the correct known values'
     for f, c in self.f2cKnownValues:
         result = conversions.convertFahrenheitToCelcius(f)
         self.assertEqual(c, result)
Esempio n. 15
0
 def testConvertFahrenheitToCelcius(self):
     """convertFahrenheitToCelcius should give known result with known input"""
     for celcius, fahrenheit, _ in self.knownValues:
         result = conversions.convertFahrenheitToCelcius(fahrenheit)
         self.assertEqual(celcius, result)