#!/usr/bin/env python import unittest from math import sqrt from domain import * from Numeric import allclose, array class TestCase(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def test_construct(self): a = 0.0 b = 2.0 c = 2.5 d = 3.0 e = 10.0 f = 12.0 points = [a, b, c, d, e, f] domain = Domain(points) assert allclose(domain.get_centroids(),[(a+b)*0.5, (b+c)*0.5, (c+d)*0.5, (d+e)*0.5, (e+f)*0.5]) def test_area(self): a = 0.0 b = 2.0 c = 2.5 d = 3.0 e = 10.0 f = 12.0 points = [a, b, c, d, e, f] domain = Domain(points) assert allclose(domain.get_area(0),b-a) assert allclose(domain.get_area(1),c-b) assert allclose(domain.get_area(2),d-c) assert allclose(domain.get_area(3),e-d) assert allclose(domain.get_area(4),f-e) def test_in_order(self): a = 0.0 b = 2.0 c = 2.5 d = 3.0 e = 10.0 f = 12.0 points = [a, c, b, d, e, f] try: domain = Domain(points) except: pass else: msg = 'Should have raised exception' raise msg def test_point(self): a = 0.0 b = 2.0 c = 2.5 d = 3.0 points = [a, b, c, d] domain = Domain(points) assert allclose(domain.get_coordinate(0), 0.5*(a+b)) assert allclose(domain.get_coordinate(1), 0.5*(b+c)) assert allclose(domain.get_coordinate(2), 0.5*(c+d)) try: allclose(domain.get_coordinate(3), 0.5*(a+b)) except: pass else: msg = 'Should have raised exception' raise msg assert allclose(domain.get_coordinate(0,0), a) assert allclose(domain.get_coordinate(1,0), b) assert allclose(domain.get_coordinate(2,0), c) assert allclose(domain.get_coordinate(0,1), b) assert allclose(domain.get_coordinate(1,1), c) assert allclose(domain.get_coordinate(2,1), d) #------------------------------------------------------------- if __name__ == "__main__": suite = unittest.makeSuite(TestCase,'test') runner = unittest.TextTestRunner() runner.run(suite)