Exemplo n.º 1
0
def processtemp(amount, inputunit, outputunit):
  degrees = Temperature(temperature=amount, system=inputunit)

  if outputunit == 'celsius':
    printtemperature(temp=degrees.celsius(), unit=outputunit)
  elif outputunit == 'fahrenheit':
    printtemperature(temp=degrees.fahrenheit(), unit=outputunit)
  elif outputunit == 'kalvin':
    printtemperature(temp=degrees.kalvin(), unit=outputunit)
  elif outputunit == 'rankine':
    printtemperature(temp=degrees.rankine(), unit=outputunit)
Exemplo n.º 2
0
    def test_5_conversions(self):
        """Test if setting various attributes works appropriately."""
        for celsius, fahrenheit, kelvin in zip(DEGREES_celsius,
                                               DEGREES_FAHRENHEIT, KELVINS):
            temperature = Temperature()
            temperature.celsius = celsius
            self.assertTrue(
                equal_to_n_decimal_places(temperature.fahrenheit, fahrenheit,
                                          4))
            self.assertTrue(
                equal_to_n_decimal_places(temperature.kelvin, kelvin, 4))

            temperature.fahrenheit = fahrenheit
            self.assertTrue(
                equal_to_n_decimal_places(temperature.celsius, celsius, 4))
            self.assertTrue(
                equal_to_n_decimal_places(temperature.kelvin, kelvin, 4))

            temperature.kelvin = kelvin
            self.assertTrue(
                equal_to_n_decimal_places(temperature.celsius, celsius, 4))
            self.assertTrue(
                equal_to_n_decimal_places(temperature.fahrenheit, fahrenheit,
                                          4))
Exemplo n.º 3
0
        Temperature(value)
    except TemperatureError:
        print('Correct error raised for', value)
    except Exception as e:
        print(e, 'raised instead of TemperatureError for', value)
print()

print('Testing the setters')
print('Each of these values should be 0.0:')
try:
    a = Temperature()
    a.kelvin = 273.15
    print(a.celsius)
    a.kelvin = '273.15K'
    print(a.celsius)
    a.kelvin = '273.15'
    print(a.celsius)
    a.fahrenheit = 32.0
    print(a.celsius)
    a.fahrenheit = '32F'
    print(a.celsius)
    a.fahrenheit = '32'
    print(a.celsius)
    a.celsius = '0C'
    print(a.celsius)
    a.celsius = 0
    print(a.celsius)
    a.celsius = '0'
    print(a.celsius)
except Exception as e:
    print(e, 'occurred when testing setters')
Exemplo n.º 4
0
from temperature import Temperature, AbsoluteZeroError

t1 = Temperature(0)
print(t1.celsius)
print(t1.fahrenheit)

t1.fahrenheit = 59
print(t1.celsius)
print(t1.fahrenheit)

try:
    t1.celsius = -274
except AbsoluteZeroError as error:
    print(error)

t1 = Temperature(0)
print(t1 == Temperature(0))
print(t1 != Temperature(100))
print(t1 < Temperature(100))
print(t1 > Temperature(-100))
print(t1 >= Temperature(0))

print(Temperature(0) + Temperature(10))
print(Temperature(20) - Temperature(10))
print(Temperature(5) * 2)
print(Temperature(5) * Temperature(2))
print(Temperature(20) / 2)
print(Temperature(20) / Temperature(2))
print(abs(Temperature(-10)))