# -*- coding: iso-8859-1 -*-
from __future__ import division # 1/2 == .5 (par defaut, 1/2 == 0)

from geolib import *
import unittest
import math

def randint(a, b = None):
    if b is None:
        b = a
        a = 0
    return ALL.module_random.randint(a, b)
random = ALL.module_random.random

def rand():
    return randint(50) - randint(50) + random()
def rand_pt():
    return ALL.Point(rand(), rand())
def rand_vec():
    return ALL.Vecteur_libre(rand(), rand())
def rand_dte():
    return ALL.Droite_equation(rand(), rand(), rand())
def rand_cercle():
    a = rand()
    b = rand()
    c = (a**2+b**2-abs(rand()))/4
    return ALL.Cercle_equation(a, b, c)


class CustomTest(unittest.TestCase):

    def setUp(self):
        pass

    def assertAlmostEqual(self,  x,  y):
        if isinstance(x,  tuple) and isinstance(y,  tuple):
            for x_elt, y_elt in zip(x, y):
                TEST = abs(y_elt - x_elt) < contexte['tolerance']
                if not TEST:
                    print x_elt,  "!=",  y_elt
                self.assert_(TEST)
        else:
            TEST = abs(y - x) < contexte['tolerance']
            if not TEST:
                print x,  "!=",  y
            self.assert_(TEST)

    def assertNotAlmostEqual(self,  x,  y):
        # TODO: define test for tuple
        TEST = abs(y - x) > contexte['tolerance']
        if not TEST:
            print x,  "==",  y
        self.assert_(TEST)
