# wxPython / tests / testPoint.py

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116``` ```"""Unit tests for wx.Point. Methods yet to test: __del__, __getitem__, __iadd__, __isub__, __len__, __nonzero__, __reduce__, __repr__, __setitem__, __str__""" import unittest import wx # the delegation among the following methods is in order to expose # "valid" data to the wx.Window tests while still being able to # comprehensively test the point class (and, in the future, expose # the full functionality to any other class) def getPointData(): return tuple( wx.Point(x,y) for x,y in getXYData() ) # ASSUME: "valid" points are positive def getValidPointData(): return tuple( wx.Point(x,y) for x,y in getPositiveXYData() ) # ----------------------------------------------------------- # TODO: what is the maximum value that wx.Point is capable of achieving? def getXYData(): return ( getPositiveXYData() + getNegativeXYData() + getMixedXYData() ) def getPositiveXYData(): return ( (0,0), (1,2), (2,1), (10,10), (20,30), (66,99), (100,200), (999,789), (1000,2000), (3141,2718) ) def getNegativeXYData(): return ( (-1,-1), (-2,-3), (-9,-9), (-10,-11), (-34,-56), (-64,-81), (-99,-99), (-121, -324), (-999, -999), (-1001,-1234), (-9999,-9999), (-99999,-99999) ) def getMixedXYData(): return ( (-1,1), (2,-3), (-9,9), (-10,11), (34,-56), (-64,81), (99,-99), (-121, 324), (-999, 999), (1001,-1234), (-9999,9999), (99999,-99999), (-1,2), (-2,1), (6,-7), (10,-10), (-20,30), (66,-99), (-100,200), (999,-789), (1000,-2000), (3141,-2718) ) # ----------------------------------------------------------- NEG_TWO = wx.Point(-2,-2) NEG_ONE = wx.Point(-1,-1) ZERO = wx.Point(0,0) ONE = wx.Point(1,1) TWO = wx.Point(2,2) # ----------------------------------------------------------- class PointTest(unittest.TestCase): def testConstructor(self): """__init__""" for x,y in getXYData(): point = wx.Point(x,y) self.assertEquals((x,y), point.Get()) point = wx.Point() self.assertEquals((0,0), point) def testGetSet(self): """Set, Get""" point = wx.Point() for x,y in getXYData(): point.Set(x,y) self.assertEquals((x,y), point.Get()) def testEquals(self): """__eq__""" self.assert_( ZERO == ZERO ) self.assert_( ZERO == wx.Point(0,0) ) self.assert_( ZERO == wx.Point() ) self.assert_( NEG_ONE == NEG_ONE ) self.assert_( NEG_ONE == wx.Point(-1,-1) ) self.assert_( ONE == ONE ) self.assert_( ONE == wx.Point(1,1) ) def testNotEquals(self): """__ne__""" self.assert_( ZERO != ONE ) self.assert_( ONE != NEG_ONE ) self.assert_( TWO != NEG_TWO ) self.assert_( NEG_TWO != ZERO ) def testAddition(self): """__add__""" self.assertEquals( ONE+NEG_ONE, ZERO ) self.assertEquals( TWO+NEG_TWO, ZERO ) self.assertEquals( ONE+ONE, TWO ) self.assertEquals( ZERO+ZERO, ZERO ) self.assertEquals( NEG_ONE+NEG_ONE, NEG_TWO ) self.assertEquals( ONE+ZERO, ONE ) self.assertEquals( TWO+NEG_ONE, ONE ) def testSubtraction(self): """__sub__""" self.assertEquals( ONE-ONE, ZERO ) self.assertEquals( NEG_ONE-NEG_ONE, ZERO ) self.assertEquals( ONE-NEG_ONE, TWO ) self.assertEquals( NEG_ONE-ONE, NEG_TWO ) self.assertEquals( ZERO-ONE, NEG_ONE ) self.assertEquals( ZERO-NEG_ONE, ONE ) self.assertEquals( NEG_ONE-ZERO, NEG_ONE ) self.assertEquals( ONE-ZERO, ONE ) ```