Implement the celsius conversion functions

Assignment Help Python Programming
Reference no: EM132192385

Assignment ­ Testing and Refactoring

Overview

This week, we focused on how to build tests for our software and how to refactor our code to be simpler or more efficient. For this week's assignment, we are going to build some functions that will help us do some temperature unit conversions. We will start by writing out tests that fail, and then building some code to make that test pass, until we have a working version of the application. After that, we will see how we can potentially refactor this implementation into something simpler.

Our code will be organized into two files:

1. conversions.py, which holds functions that will do these temperature unit conversions; and
2. tests.py, which will hold all of our tests

Useful Reminders

1. Read the assignment over a few times. At least twice. It always helps to have a clear picture of the overall assignment when understanding how to build a solution.
2. Think about the problem for a while, and even try writing or drawing a solution using pencil and paper or a whiteboard.

Part I ­ Create Tests for Celsius Conversion

Following the test­driven development methodology, we are going to start by first creating some tests for our implementation. Let us start with testing two functions that we will eventually need to write and put inside conversions.py:

1. convertCelsiusToKelvin ­ Takes in a float representing a Celsius measurement, and returns that temperature converted into Kelvins
2. convertCelsiusToFahrenheit ­ Takes in a float representing a Celsius measurement, and returns that temperature converted into Fahrenheit

For now, create these functions in the correct file but have them return 0.0.

The tests should make multiple calls to each function, checking if the conversion is correct. For example,
300.00 °C is 572.00 °F and 573.15 K. For more information on how to do these conversions, please refer to Conversion of Units of Temperature webpage, which has a reference table of known conversions that you can use for your testing. Make sure this test is thorough by including 5 test cases per test. Also make sure to be verbose in your testing (i.e. print a message for every test case you are checking).

Part II ­ Implement the Celsius Conversion Functions

Now we need to make the tests work. Do this by correctly implementing the conversion functions listed above. Make sure all your tests at this point run without any errors.

Part III ­ Repeat

Repeat Part I and II for converting from Fahrenheit to Celsius and Kelvin, as well as converting from Kelvin to Fahrenheit and Celsius. There should now be a total of 6 functions, each one having a test case which confirms it is properly converting. Make sure all your tests can run successfully.

Part IV ­ Refactor

In many real world situations, the requirements for your code may change. It behooves you as a programmer to think in general terms, such that if requirements do change, you can minimize the impact of how your code needs to change. Lets mimic this by changing the requirements of the application to support not only temperature, but to support converting between Miles, Yards and Meters.

Now, to support this, we can do like we did above: keep creating functions to convert one unit to another, and writing a test for that function to confirm its functionality. However, is there a more general way to solve these conversion problems? Do they have a similar pattern? If they do, is there a way for you to refactor your code such that you only need one functions to convert any unit into another (of course, we can't convert Celsius to Meters, and we should account for that by throwing an exception).

Lets create a new method inside of a new file (called conversions_refactored.py) named convert that takes in 3 values:

1. fromUnit ­ the unit we are converting from, as a string
2. toUnit ­ the unit we are converting to, as a string
3. value ­ the value of fromUnit we are converting from

The function should return the converted value as a float. This method should not rely on the methods we wrote above. This about the problem and see if a pattern emerges that lets you implement it in a simpler way. The test for this function should:

1. Check that all temperature conversions are working
2. Check that all distance conversions are working
3. Check that converting from one unit to itself returns the same value for all units

Verified Expert

The task of the assignment is to develop a conversion application that converts the units from one form to another. for example conversion among Fahrenheit Celsius and Kelvin. This conversion application is also applied to Miles, Yards and Meters. A python unit test is also written that helps in this conversion process.

Reference no: EM132192385

Questions Cloud

What causes you stress on the job : What causes you stress on the job? How do you deal with it? How do you supervisors and co-workers deal with their stress?
Crimes are differences in the burden of proof at trial : Three ways torts differ from crimes are differences in the burden of proof at trial, differences in terminology and consequences, and differences in parties.
What changed since the dotcom bubble : Explain what this was and some of the factors that created the bubble, and then the factors that led to the bubble bursting.
Social enterprises to succeed in business : Meta-skills managers need for social enterprises to succeed in business: (1) acceptance, (2) differentiation, and (3) integration
Implement the celsius conversion functions : Implement the Celsius Conversion Functions - Create Tests for Celsius Conversion - It always helps to have a clear picture of the overall assignment
What types of securities does the treasury issue : What are emerging markets; converging markets and frontier markets? What characterizes the emerging markets of Brazil and Eastern Europe?
Abstract talking about ethical decision making and hiring : Write an abstract talking about Ethical Decision Making and Hiring
Improve a company performance : What are the effectiveness of using Fayol's management model in a business.
Business revenue and profit growth by managing innovation : Write examples of how Trinity Solar supports business revenue and profit growth by managing innovation. Write about different types of innovation.

Reviews

len2192385

12/12/2018 11:03:58 PM

the solution should NOT be at a graduate level but undergraduate level. I need to know how to meet the requirements but not too advanced. Let me know as soon as possible Read the assignment over a few times. At least twice. It always helps to have a clear picture of the overall assignment when understanding how to build a solution. 2. Think about the problem for a while, and even try writing or drawing a solution using pencil and paper or a whiteboard.

Write a Review

Python Programming Questions & Answers

  What does that mean in real life

Build a table to be used as the basis for a directed weighted graph - Find the 3 stations with the highest in-degree. What does that mean in real life

  Design and implement mini-missions in the haunted house

Create a cheat commands in the game so player can pick up any item he wants from any location in the map. You have to name this cheat command 'giveme'

  Write a string expression whose value is the string

Write a string expression whose value is the string equivalent of each these variables joined by a single period .

  Assignment on python code

A robot is asked to navigate a maze. It is placed at a certain position (the starting position) in the maze and is asked to try to reach another position (the goal position)

  Demonstrates the benefits of well-designed data abstraction

Demonstrates the benefits of well-designed data abstraction and modularity in that most methods and functions need no modification or consideration at all, but continue to do their jobs flawlessly and abstractly.

  Design a python program that prompts the user to enter

Design a PYTHON program that prompts the user to enter a number and then you will build a multiplication table of that size.

  Construct a model of a byte adder

Construct a model of a byte adder based on the bit adder and Specify an algorithm for integer addition based on binary operation - Create a program in Python which implement the model of the adder

  Write a program using the following python functions

You are required to write the following Python functions. Make sure you understand where each function fits into the system described above.

  A python program that contains a main function

Write a PYTHON program that contains a main function and a custom, void function namedshow_larger that takes two random integers as parameters.

  Write the code to allow user to input three integer numbers

Write the code to allow a user to input three integer numbers. The program will then produce the average of thosethree numbers

  Write the appropriate accessor and mutator methods for each

Write two class es named ProductionWorker and ShiftSupervisor that are subclass es of the Employee class.|

  Do a python project and get it running using app engine

Do a python project and get it running using App engine. Something very basic and simple

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd