| 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 |
from random import random, randint |
| 7 |
from math import pi |
| 8 |
|
| •9 |
import tools.unittests |
| 10 |
from wxgeometrie.geolib import ( |
| 11 |
Point, Droite, Droite_equation, Reflexion, Rotation, Translation, |
| 12 |
Homothetie, Symetrie_centrale, Milieu, Mediatrice, Vecteur_libre |
| 13 |
) |
| 14 |
|
| •15 |
class TestGelolib(tools.unittests.TestCase): |
| 16 |
|
| 17 |
def test_Rotation(self): |
| 18 |
A = Point(1.523, 45.35211) |
| 19 |
r = Rotation(A, pi/4) |
| 20 |
M = Point(1.4452, -1.2545) |
| 21 |
self.assertAlmostEqual(r(M).coordonnees, (34.423837071540447, 12.341247113306926)) |
| 22 |
self.assertAlmostEqual(r(A).coordonnees, A.coordonnees) |
| 23 |
d = Droite(A, M) |
| 24 |
d1 = Droite(A, r(M)) |
| 25 |
self.assertAlmostEqual(r(d).equation_reduite, d1.equation_reduite) |
| 26 |
self.assertIs(r(A), A) |
| 27 |
|
| 28 |
|
| 29 |
def test_Translation(self): |
| 30 |
v = Vecteur_libre(random()+randint(0,50)-randint(0,50), random()+randint(0,50)-randint(0,50)) |
| 31 |
t = Translation(v) |
| 32 |
M = Point(random()+randint(0,50)-randint(0,50), random()+randint(0,50)-randint(0,50)) |
| 33 |
self.assertAlmostEqual(M.x + v.x, t(M).x) |
| 34 |
self.assertAlmostEqual(M.y + v.y, t(M).y) |
| 35 |
|
| 36 |
|
| 37 |
def test_Reflexion(self): |
| 38 |
d = Droite_equation(1, 6, -2) |
| 39 |
r = Reflexion(d) |
| 40 |
M = Point(random()+randint(0,50)-randint(0,50), random()+randint(0,50)-randint(0,50)) |
| 41 |
m = Mediatrice(M, r(M)) |
| 42 |
self.assertAlmostEqual(d.equation_reduite[0], m.equation_reduite[0]) |
| 43 |
self.assertAlmostEqual(d.equation_reduite[1], m.equation_reduite[1]) |
| 44 |
self.assertIs(r(d), d) |
| 45 |
|
| 46 |
def test_Homothetie(self): |
| 47 |
A = Point(1, -2) |
| 48 |
h = Homothetie(A, -3) |
| 49 |
M = Point(2, 7) |
| 50 |
self.assertAlmostEqual(h(M).coordonnees, (-2, -29)) |
| 51 |
self.assertIs(h(A), A) |
| 52 |
|
| 53 |
|
| 54 |
def test_Symetrie_centrale(self): |
| 55 |
M = Point(random()+randint(0,50)-randint(0,50), random()+randint(0,50)-randint(0,50)) |
| 56 |
A = Point(random()+randint(0,50)-randint(0,50), random()+randint(0,50)-randint(0,50)) |
| 57 |
s = Symetrie_centrale(A) |
| 58 |
self.assertAlmostEqual(Milieu(M, s(M)).coordonnees[0], A.coordonnees[0]) |
| 59 |
self.assertAlmostEqual(Milieu(M, s(M)).coordonnees[1], A.coordonnees[1]) |
| 60 |
self.assertIs(s(A), A) |