| 12 | from lib import * |
| 13 | |
| 14 | class Test(unittest.TestCase): |
| 15 | def test_component(self): |
| 16 | """ |
| 17 | test for method component |
| 18 | """ |
| 19 | x = Vector([1,2,3]) |
| 20 | self.assertEqual(x.component(0),1) |
| 21 | self.assertEqual(x.component(2),3) |
| 22 | try: |
| 23 | y = Vector() |
| 24 | self.assertTrue(False) |
| 25 | except: |
| 26 | self.assertTrue(True) |
| 27 | def test_str(self): |
| 28 | """ |
| 29 | test for toString() method |
| 30 | """ |
| 31 | x = Vector([0,0,0,0,0,1]) |
| 32 | self.assertEqual(str(x),"(0,0,0,0,0,1)") |
| 33 | def test_size(self): |
| 34 | """ |
| 35 | test for size()-method |
| 36 | """ |
| 37 | x = Vector([1,2,3,4]) |
| 38 | self.assertEqual(len(x),4) |
| 39 | def test_euclidLength(self): |
| 40 | """ |
| 41 | test for the eulidean length |
| 42 | """ |
| 43 | x = Vector([1,2]) |
| 44 | self.assertAlmostEqual(x.eulidLength(),2.236,3) |
| 45 | def test_add(self): |
| 46 | """ |
| 47 | test for + operator |
| 48 | """ |
| 49 | x = Vector([1,2,3]) |
| 50 | y = Vector([1,1,1]) |
| 51 | self.assertEqual((x+y).component(0),2) |
| 52 | self.assertEqual((x+y).component(1),3) |
| 53 | self.assertEqual((x+y).component(2),4) |
| 54 | def test_sub(self): |
| 55 | """ |
| 56 | test for - operator |
| 57 | """ |
| 58 | x = Vector([1,2,3]) |
| 59 | y = Vector([1,1,1]) |
| 60 | self.assertEqual((x-y).component(0),0) |
| 61 | self.assertEqual((x-y).component(1),1) |
| 62 | self.assertEqual((x-y).component(2),2) |
| 63 | def test_mul(self): |
| 64 | """ |
| 65 | test for * operator |
| 66 | """ |
| 67 | x = Vector([1,2,3]) |
| 68 | a = Vector([2,-1,4]) # for test of dot-product |
| 69 | b = Vector([1,-2,-1]) |
| 70 | self.assertEqual(str(x*3.0),"(3.0,6.0,9.0)") |
| 71 | self.assertEqual((a*b),0) |
nothing calls this directly
no outgoing calls
no test coverage detected