view tests/test_error.py @ 83:1b61ce99ee82

derivative calculation: midpoint rule
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 13:51:13 -0800
parents 351fc97bb996
children
line wrap: on
line source

#!/usr/bin/env python

"""
test error computation functionality
"""

import numpy as np
import os
import unittest
from tvii import error

class ErrorTest(unittest.TestCase):

    def test_error_computation(self):
        """test error computation"""

        def square(x):
            return x*x

        x = [[1], [2], [3]]
        y = np.array([0, 3, 8])

        yhat, _err = error.error(square, x, y)

        assert list(yhat) == [1, 4, 9]
        assert list(_err) == [1, 1, 1]

if __name__ == '__main__':
    unittest.main()