| 1 |
|
| 2 |
import os, sys |
| 3 |
TOPDIR = os.path.abspath(os.path.join(os.path.dirname(__file__),"../..")) |
| 4 |
sys.path.insert(0, TOPDIR) |
| 5 |
|
| •6 |
import tools.unittests, unittest |
| 7 |
|
| 8 |
from wxgeometrie.geolib.tests.geotestlib import rand_pt |
| 9 |
from wxgeometrie.geolib import (Point, Interpolation_polynomiale_par_morceaux, |
| 10 |
Glisseur_courbe, Interpolation_lineaire, |
| 11 |
Translation,) |
| 12 |
|
| •13 |
class GeolibTest(tools.unittests.TestCase): |
| 14 |
def test_Interpolation_lineaire(self): |
| 15 |
és : |
| 16 |
A = rand_pt() |
| 17 |
B = rand_pt() |
| 18 |
C = rand_pt() |
| 19 |
D = rand_pt() |
| 20 |
E = rand_pt() |
| 21 |
F = rand_pt() |
| 22 |
G = rand_pt() |
| 23 |
H = rand_pt() |
| 24 |
I = rand_pt() |
| 25 |
J = rand_pt() |
| 26 |
K = rand_pt() |
| 27 |
i0 = Interpolation_lineaire(A, B, C, D, E, F, G, H, I, J, K) |
| 28 |
|
| 29 |
i1 = Interpolation_lineaire(points = (A, B, C, D, E, F, G, H, I, J, K)) |
| 30 |
self.assertEqual(len(i1.points), len(i0.points)) |
| 31 |
self.assertNotIn("points", i1.style()) |
| 32 |
t = Translation((1, -2)) |
| 33 |
i2 = t(i1) |
| 34 |
self.assertEqual(i2.points[0].xy, (A.x + 1, A.y - 2)) |
| 35 |
self.assertEqual(i2.points[-1].xy, (K.x + 1, K.y - 2)) |
| 36 |
|
| 37 |
|
| 38 |
@unittest.expectedFailure |
| 39 |
def test_Interpolation_quadratique(self): |
| 40 |
raise NotImplementedError |
| 41 |
|
| 42 |
|
| 43 |
@unittest.expectedFailure |
| 44 |
def test_Interpolation_cubique(self): |
| 45 |
raise NotImplementedError |
| 46 |
|
| 47 |
|
| 48 |
def test_Interpolation_polynomiale_par_morceaux(self): |
| 49 |
A = Point(-5.9897435897435898, -1.1319690410599499) |
| 50 |
B = Point(-3.6911010558069393, 2.3942017578381218) |
| 51 |
C = Point(-0.50558069381598791, -1.0768726223271674) |
| 52 |
D = Point(2.6437405731523356, 1.1545323363505182) |
| 53 |
inter = Interpolation_polynomiale_par_morceaux(A, B, C, D) |
| 54 |
M = Glisseur_courbe(inter, 2) |
| 55 |
self.assertEqual(M.xy[0], 2) |
| 56 |
P = Point(inter) |
| 57 |
self.assertEqual(P.y, inter.fonction(float(P.x))) |
| 58 |
|
| 59 |
inter2 = Interpolation_polynomiale_par_morceaux([A, B, C, D]) |
| 60 |
M = Point(inter, -7) |
| 61 |
self.assertTrue(M.x == min(A.x, B.x, C.x, D.x) == inter2.xmin) |
| 62 |
|