This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic unit tests for precipitation
- Loading branch information
Reed Martz
committed
Dec 6, 2016
1 parent
027ac56
commit 0ee7e6b
Showing
2 changed files
with
45 additions
and
42 deletions.
There are no files selected for viewing
85 changes: 44 additions & 41 deletions
85
django/climate_change_api/indicators/tests/test_unit_converters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,49 @@ | ||
from django.test import TestCase | ||
from indicators.unit_converters import TemperatureConverter | ||
from indicators.tests.mixins import ConverterTestMixin | ||
from indicators.unit_converters import TemperatureConverter, PrecipitationConverter | ||
|
||
|
||
class TemperatureConverterTestCase(TestCase): | ||
def test_conversions(self): | ||
cases = { | ||
('F', 'K'): [ | ||
(0, 255.372222), | ||
(32, 273.15), | ||
(73.45, 296.17778) | ||
], | ||
('K', 'F'): [ | ||
(0, -459.67), | ||
(276.3, 37.67) | ||
], | ||
('K', 'C'): [ | ||
(0, -273.15), | ||
(295.3, 22.15) | ||
], | ||
('C', 'F'): [ | ||
(-40, -40), | ||
(0, 32), | ||
(10, 50), | ||
(100, 212), | ||
(23.2, 73.76) | ||
], | ||
('F', 'C'): [ | ||
(80, 26.6667), | ||
(73.2, 22.888889), | ||
(-40, -40), | ||
(0, -17.77778), | ||
(212, 100), | ||
(32, 0) | ||
] | ||
} | ||
class TemperatureConverterTestCase(ConverterTestMixin, TestCase): | ||
converter_class = TemperatureConverter | ||
cases = { | ||
('F', 'K'): [ | ||
(0, 255.372222), | ||
(32, 273.15), | ||
(73.45, 296.17778) | ||
], | ||
('K', 'F'): [ | ||
(0, -459.67), | ||
(276.3, 37.67) | ||
], | ||
('K', 'C'): [ | ||
(0, -273.15), | ||
(295.3, 22.15) | ||
], | ||
('C', 'F'): [ | ||
(-40, -40), | ||
(0, 32), | ||
(10, 50), | ||
(100, 212), | ||
(23.2, 73.76) | ||
], | ||
('F', 'C'): [ | ||
(80, 26.6667), | ||
(73.2, 22.888889), | ||
(-40, -40), | ||
(0, -17.77778), | ||
(212, 100), | ||
(32, 0) | ||
] | ||
} | ||
|
||
for units, tests in cases.iteritems(): | ||
converter = TemperatureConverter.get(*units) | ||
|
||
for start, expected in tests: | ||
value = converter(start) | ||
self.assertAlmostEqual(value, expected, | ||
places=3, | ||
msg='Failed assertion that %f %s = %f %s, got %f %s' % | ||
(start, units[0], expected, units[1], value, units[1])) | ||
class PrecipitationConverterTestCase(ConverterTestMixin, TestCase): | ||
converter_class = PrecipitationConverter | ||
cases = { | ||
('kg/m^2/s', 'kg/m^2/day'): [ | ||
(1, 86400) | ||
], | ||
('kg/m^2/day', 'kg/m^2/s'): [ | ||
(86400, 1) | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters