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 would happen if the script fails to open password file

You have been hired by a company to provide consultation on security and provide recommendations. Using Microsoft® Word, write a 1-page document explaining.

  Write a program that simulates a traffic light

Write a program that simulates a traffic light. The program lets the user select one of three lights: red, yellow, or green.

  Problem on the interactive execution

Interactive Execution. Start the Python interactive interpreter. You can invoke it by typing in its full pathname or just its name (python or python.exe).

  Asks the user for the number of males and number of females

Write a program that asks the user for the number of males and the number of females registered in a class using two separate inputs.

  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.

  Compare programming with python and programming with scratch

Compare programming with python and programming with scratch. Describe the same program you might create in both programming languages.

  Modify your code to ask the user for the id of a restaurant

Copy check1.py to check2.py and continue to work on check2.py. Modify your code to ask the user for the id of a restaurant between 1 and 155 (humans don't need to know about list ids starting at 0).

  Define a class for representing a distance

Define a class for representing a distance (with one attribute that represents the distance in inches).

  Write a function trans(m) which returns the transpose

Write a function trans(M) which returns the transpose of an n-by-n matrix M. The matrix M is represented by a list of n lists, each of length n. Transposing M means that each M[i][j] is swapped (once!) with M[j][i].

  What is a python development framework

Give 3 examples python development framework used today. and explain which development framework is used in which industry.

  Cleint software so that it does not display

Rewrite the cleint software so that it does not display an echo of a message sent by the users. Maybe it means that each time a user tries to send a private message that same message is also sent back to them? summary: stop that from happening?

  Create a python script that will implement the given command

Write a python script that will implement the following command: merge sourcedirectory1 sourcedirectory2 destinationdirectory. The merger is a union operation, so that if a file/directory exists in either source directory it is included in the new d..

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