# HG changeset patch # User Jeff Hammel # Date 1409880173 25200 # Node ID 2cad4536f797f71a7b8a0640295511e60b251bbb # Parent 7761aa18e885cb46c3351b6f170fb530a81ba84d new unittest diff -r 7761aa18e885 -r 2cad4536f797 tests/test_interpolation.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_interpolation.py Thu Sep 04 18:22:53 2014 -0700 @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +""" +test interpolation +""" + +import csv +import os +import sys +import unittest +from interpolation import linear_interpolation + +# globals +here = os.path.dirname(os.path.abspath(__file__)) +test_data = os.path.join(here, 'test_data.csv') + +class InterpolationUnitTest(unittest.TestCase): + + def test_linear_interpolation(self): + """test linear interpolation""" + + # make a line + data = [(float(x), float(x)) for x in range(10)] + + # interpolate at a point + point = 2.2 + values = linear_interpolation(data, [point]) + self.assertEqual(len(values), 1) + self.assertEqual(values[0], point) + + def read_test_data(self): + """read test data from sample CSV file""" + + with open(test_data, 'r') as f: + reader = csv.reader(f) + retval = [[float(col) for col in row] for row in reader] + return retval + + def test_from_csv(self): + + raw_data = self.read_test_data() + data = [[(row[0], row[col]) for row in raw_data] + for col in (1,2)] + for series in data: + x_values = range(2,10) + interpolated = linear_interpolation(series, x_values) + + +if __name__ == '__main__': + unittest.main() + diff -r 7761aa18e885 -r 2cad4536f797 tests/test_kplot.py --- a/tests/test_kplot.py Thu Sep 04 18:05:39 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -#!/usr/bin/env python - -""" -unit tests -""" - -import os -import sys -import unittest - -# globals -here = os.path.dirname(os.path.abspath(__file__)) - -class kplotUnitTest(unittest.TestCase): - - def test_kplot(self): - pass - -if __name__ == '__main__': - unittest.main() -