Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: iso-8859-2 -*-
- #
- # points.py
- from math import sqrt
- class Point:
- def __init__(self,x=0,y=0):
- self.x=x
- self.y=y
- def __str__(self):
- return "(%s,%s)" % (self.x,self.y)
- def __repr__(self):
- return "Point(%s,%s)" % (self.x,self.y)
- def __eq__(self,other):
- if self.x==other.x and self.y==other.y:
- return True
- else:
- return False
- def __ne_(_self,other):
- return not self==other
- def __add__(self,other):
- resx=self.x+other.x
- resy=self.y+other.y
- return Point(resx,resy)
- def __sub__(self,other):
- resx=self.x-other.x
- resy=self.y-other.y
- return Point(resx,resy)
- def __mul__(self,other):
- res=self.x*other.x+self.y*other.y
- return res
- def cross(self,other):
- res=self.x*other.y-self.y*other.x
- return res
- def length(self):
- len=sqrt(self.x*self.x+self.y*self.y)
- return len
- #############################################
- #!/usr/bin/python
- # -*- coding: iso-8859-2 -*-
- #
- # points_test.py
- import unittest
- from points import *
- class TestPoints(unittest.TestCase):
- def setUp(self): pass
- def test_str(self):
- self.assertEqual(str(Point(3,5)),"(3,5)")
- def test_repr(self):
- self.assertEqual(repr(Point(2,1)),"Point(2,1)")
- def test_eq(self):
- self.assertEquals(eq(Point(1,2),Point(1,2)),True)
- if __name__ == '__main__':
- unittest.main()
Add Comment
Please, Sign In to add comment