adamnagel / qudt-for-domain-tools

Establishing consistent unit identities in a world of whirling chaos
GNU Lesser General Public License v2.1
2 stars 1 forks source link

Implement convert_value function #3

Closed adamnagel closed 10 years ago

adamnagel commented 11 years ago

To work on this issue, create a new Git Branch called "issue-3".

In qudt4dt/init.py there is a function

def convert_value(self, source_unit_uri, destination_unit_uri, source_value)

Parameters:

Return: The converted value. Assume that "source_value" has "source_unit_uri" as its Unit. Discover and perform the numerical conversion to find the new value with "destination_unit_uri" as the Unit.

Background Information

The QUDT ontology includes the information necessary to convert between units that share a unit class. Units include conversionOffset and conversionMultiplier fields that are used for this purpose.

Examples

In some cases, it will not be possible to convert between units. In these cases, a ValueError exception must be thrown.

Some unit tests should be implemented to verify that this function works correctly. Use Python's unittest package to build unit test functions. There should be functions that test correct operation, but there should also be assertRaises() tests to verify that exceptions are raised in the correct cases.

These tests should be implemented in the file test_qudt4dt.py in the repository. Refactor the tests in this file as a unit test class, and add new tests for convert_value.