Hemofobia

Untitled

Nov 25th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: iso-8859-2 -*-
  3. #
  4. # points.py
  5. from math import sqrt
  6.  
  7. class Point:
  8.     def __init__(self,x=0,y=0):
  9.         self.x=x
  10.         self.y=y
  11.     def __str__(self):
  12.             return "(%s,%s)" % (self.x,self.y)
  13.     def __repr__(self):
  14.         return "Point(%s,%s)" % (self.x,self.y)
  15.     def __eq__(self,other):
  16.         if self.x==other.x and self.y==other.y:
  17.             return True
  18.         else:
  19.             return False
  20.     def __ne_(_self,other):
  21.         return not self==other
  22.  
  23.     def __add__(self,other):
  24.         resx=self.x+other.x
  25.         resy=self.y+other.y
  26.         return Point(resx,resy)
  27.     def __sub__(self,other):
  28.         resx=self.x-other.x
  29.         resy=self.y-other.y
  30.         return Point(resx,resy)
  31.     def __mul__(self,other):
  32.         res=self.x*other.x+self.y*other.y
  33.         return res
  34.     def cross(self,other):
  35.         res=self.x*other.y-self.y*other.x
  36.         return res
  37.     def length(self):
  38.         len=sqrt(self.x*self.x+self.y*self.y)
  39.         return len
  40.  
  41. #############################################
  42.  
  43. #!/usr/bin/python
  44. # -*- coding: iso-8859-2 -*-
  45. #
  46. # points_test.py
  47.  
  48. import unittest
  49. from points import *
  50.  
  51. class TestPoints(unittest.TestCase):
  52.     def setUp(self): pass
  53.     def test_str(self):
  54.         self.assertEqual(str(Point(3,5)),"(3,5)")
  55.     def test_repr(self):
  56.         self.assertEqual(repr(Point(2,1)),"Point(2,1)")
  57.     def test_eq(self):
  58.         self.assertEquals(eq(Point(1,2),Point(1,2)),True)
  59.  
  60.  
  61.  
  62. if __name__ == '__main__':
  63.     unittest.main()
Add Comment
Please, Sign In to add comment