(Poly)
| 142 | |
| 143 | |
| 144 | def test_fit(Poly): |
| 145 | |
| 146 | def f(x): |
| 147 | return x*(x - 1)*(x - 2) |
| 148 | x = np.linspace(0, 3) |
| 149 | y = f(x) |
| 150 | |
| 151 | # check default value of domain and window |
| 152 | p = Poly.fit(x, y, 3) |
| 153 | assert_almost_equal(p.domain, [0, 3]) |
| 154 | assert_almost_equal(p(x), y) |
| 155 | assert_equal(p.degree(), 3) |
| 156 | |
| 157 | # check with given domains and window |
| 158 | d = Poly.domain + random((2,))*.25 |
| 159 | w = Poly.window + random((2,))*.25 |
| 160 | p = Poly.fit(x, y, 3, domain=d, window=w) |
| 161 | assert_almost_equal(p(x), y) |
| 162 | assert_almost_equal(p.domain, d) |
| 163 | assert_almost_equal(p.window, w) |
| 164 | p = Poly.fit(x, y, [0, 1, 2, 3], domain=d, window=w) |
| 165 | assert_almost_equal(p(x), y) |
| 166 | assert_almost_equal(p.domain, d) |
| 167 | assert_almost_equal(p.window, w) |
| 168 | |
| 169 | # check with class domain default |
| 170 | p = Poly.fit(x, y, 3, []) |
| 171 | assert_equal(p.domain, Poly.domain) |
| 172 | assert_equal(p.window, Poly.window) |
| 173 | p = Poly.fit(x, y, [0, 1, 2, 3], []) |
| 174 | assert_equal(p.domain, Poly.domain) |
| 175 | assert_equal(p.window, Poly.window) |
| 176 | |
| 177 | # check that fit accepts weights. |
| 178 | w = np.zeros_like(x) |
| 179 | z = y + random(y.shape)*.25 |
| 180 | w[::2] = 1 |
| 181 | p1 = Poly.fit(x[::2], z[::2], 3) |
| 182 | p2 = Poly.fit(x, z, 3, w=w) |
| 183 | p3 = Poly.fit(x, z, [0, 1, 2, 3], w=w) |
| 184 | assert_almost_equal(p1(x), p2(x)) |
| 185 | assert_almost_equal(p2(x), p3(x)) |
| 186 | |
| 187 | |
| 188 | def test_equal(Poly): |
nothing calls this directly
no test coverage detected