| 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 random import randint, random |
| 9 |
from wxgeometrie.geolib import Champ, Bouton |
| 10 |
|
| 11 |
def rand(): |
| 12 |
return randint(0,50) - randint(0,50) + random() |
| 13 |
|
| •14 |
class TestGeolib(tools.unittests.TestCase): |
| 15 |
|
| 16 |
def test_Champ(self): |
| 17 |
champ = Champ('', 4, 3, couleur_fond='#ffffb5', |
| 18 |
prefixe=(r"Combien vaut 1+1 ? "), |
| 19 |
alignement_horizontal='left', |
| 20 |
alignement_vertical='bottom', |
| 21 |
attendu='2') |
| 22 |
points = 0 |
| 23 |
|
| 24 |
def valider(reponse, attendu): |
| 25 |
return reponse.strip() == attendu |
| 26 |
|
| 27 |
def evt_valider(**kw): |
| 28 |
nonlocal points |
| 29 |
points = (5 if kw['correct'] else 1) |
| 30 |
|
| 31 |
champ.valider = valider |
| 32 |
champ.evt_valider = evt_valider |
| 33 |
|
| 34 |
champ.texte = '3' |
| 35 |
self.assertEqual(champ.label(), "Combien vaut 1+1 ? $3$") |
| 36 |
self.assertFalse(champ.correct) |
| 37 |
self.assertEqual(points, 1) |
| 38 |
champ.texte = '2' |
| 39 |
self.assertEqual(champ.label(), "Combien vaut 1+1 ? $2$") |
| 40 |
self.assertTrue(champ.correct) |
| 41 |
self.assertEqual(points, 5) |
| 42 |
champ.texte = ' 3 ' |
| 43 |
self.assertFalse(champ.correct) |
| 44 |
self.assertEqual(points, 1) |
| 45 |
champ.texte = ' 2 ' |
| 46 |
self.assertTrue(champ.correct) |
| 47 |
self.assertEqual(points, 5) |
| 48 |
|
| 49 |
@unittest.expectedFailure |
| 50 |
def test_Bouton(): |
| 51 |
raise NotImplementedError |