#!/usr/bin/python

import unittest
from hypothesis import given, assume
from hypothesis.strategies import floats
import numpy as np
from corfunc import porod, guinier, fitguinier, smooth


class TestStringMethods(unittest.TestCase):
    def test_porod(self):
        self.assertEqual(porod(1, 1, 0), 1)

    @given(q=floats(min_value=0, max_value=1e3),
           A=floats(min_value=0))
    def test_guinier(self, q, A):
        self.assertEqual(guinier(q, A, 0), A)

    @given(A=floats(min_value=1e-100, max_value=1e30),
           B=floats(min_value=-1e2, max_value=-1e-5))
    def test_sane_fit(self, A, B):
        x = np.linspace(0, 1, 71)
        y = guinier(x, A, B)

        g = fitguinier(x, y)[0]

        self.assertAlmostEqual(B/g[0], 1.0)
        self.assertAlmostEqual(A/np.exp(g[1]), 1.0)

    def test_smooth(self):
        f = lambda x: np.sqrt(x)*np.sin(x/10)
        g = lambda x: np.log(1+x)
        s = smooth(f, g, 25, 75)

        x = np.linspace(0, 1, 100)
        fg = np.vstack([f(x), g(x)])
        small = np.min(fg, axis=0)
        large = np.max(fg, axis=0)

        x = np.linspace(0, 1, 100)

        self.assertTrue(np.all(small <= s(x)))
        self.assertTrue(np.all(s(x) <= large))
        self.assertEqual(s(0), f(0))
        self.assertEqual(s(25), f(25))
        self.assertEqual(s(75), g(75))
        self.assertEqual(s(100), g(100))


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

@@ -807,30 +807,173 @@
     
-def test_smooth(self):
+@given(start=floats(min_value=0,max_value=1e50),%0A           stop=floats(max_value=1e50))%0A    def test_smooth(self, start, stop):%0A        assume(stop %3E start + 1e-50)
 %0A   
@@ -1078,14 +1078,19 @@
  g, 
-25, 75
+start, stop
 )%0A%0A 
@@ -1108,28 +1108,39 @@
 np.linspace(
-0, 1
+start/2, stop*2
 , 100)%0A     
@@ -1246,44 +1246,8 @@
 0)%0A%0A
-        x = np.linspace(0, 1, 100)%0A%0A
     
@@ -1367,15 +1367,27 @@
 l(s(
-0), f(0
+start/2), f(start/2
 ))%0A 
@@ -1416,17 +1416,23 @@
 l(s(
-25), f(25
+start), f(start
 ))%0A 
@@ -1461,17 +1461,21 @@
 l(s(
-75
+stop
 ), g(
-75
+stop
 ))%0A 
@@ -1504,19 +1504,25 @@
 l(s(
-100), g(100
+stop*2), g(stop*2
 ))%0A%0A

Generate tests for test_smooth