#Name: Roberto Reyes #CIN:203807805 #COURSE: CS-3035-01 #Description: Tester class that test all methods in object class from vector import Vector obj = Vector(2, 2, 1) obj1 = Vector(2, 2, 1) num = 5 print("str:", obj.__str__()) print("repr:", obj.__repr__()) print("Magnitude:", obj.magnitude()) print("== op:", obj == obj1) print("ADD:", obj + obj1) iadd = obj iadd += obj1 print("IADD:", iadd) print("SUB:", obj - obj1) isub = obj1 isub -= obj1 print("ISUB:", isub) obj4 = obj * obj1 print("MUL:", obj4) obj3 = obj obj3 *= num print("IMUL:", obj3) obj2 = obj % obj1 print("% opp:", obj2)
# **************************************************************************** # # # # ::: :::::::: # # test.py :+: :+: :+: # # +:+ +:+ +:+ # # By: ythomas <*****@*****.**> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/11/05 20:30:12 by ythomas #+# #+# # # Updated: 2019/11/06 14:15:16 by ythomas ### ########.fr # # # # **************************************************************************** # from vector import Vector v1 = Vector(5) v2 = v1 - 5 print(v1.values) v1 = Vector(5) v2 = v1 / 2 print(v1.values) v1 = Vector(5) v2 = 2 / v1 print(v1.values) print(v1.__repr__())
from vector import Vector v1 = Vector(3) print("Vector(3): " + str(v1.values)) v1 = Vector((5, 8)) print("Vector((5,8)): " + str(v1.values)) v1 = Vector([10.0, 11.0, 12.0, 13.0]) print("v1.values: " + str(v1.values)) print("v1.size: " + str(v1.size)) v2 = v1 + 5 print("v1.__add__: " + str(v2)) v2 = v1.__radd__(5) print("v1.__radd__: " + str(v2)) v2 = v1 - 5 print("v1.__sub__: " + str(v2)) v2 = v1.__rsub__(5) print("v1.__rsub__: " + str(v2)) v2 = v1 / 5 print("v1.__truediv__: " + str(v2)) v2 = v1.__rtruediv__(5) print("v1.__rtruediv__: " + str(v2)) v2 = v1 * 5 print("v1.__mul__: " + str(v2)) v2 = v1.__rmul__(5) print("v1.__rmul__: " + str(v2)) print("v1.__str__: " + str(v1)) print("v1.__repr__(v1): " + str(v1.__repr__(v1)))
test_eval(f'Vector([0.0, 1.0, 2.0, 3.0]) {op} 5') test_eval(f'5 {op} Vector([0.0, 1.0, 2.0, 3.0])') test_eval(f'Vector([0.0, 1.0, 2.0, 3.0]) {op} 5.1') test_eval(f'5.1 {op} Vector([0.0, 1.0, 2.0, 3.0])') test_eval(f'"hi" {op} Vector([0.0, 1.0, 2.0, 3.0])') test_eval(f'Vector([0.0, 1.0, 2.0, 3.0]) \ {op} Vector([0.0, 1.0, 2.0, 3.0])') test_eval(f'Vector([0.0, 1.0, 2.0, 3.0]) \ {op} Vector([0.0, 1.0, 2.0])') if __name__ == "__main__": v1 = Vector([0.0, 1.0, 2.0, 3.0]) print('v1', v1) print('repr(v1)', repr(v1)) print('v1.__repr__()', v1.__repr__()) print(eval(repr(v1)) == v1) # test __repr__ v2 = v1 * 5 print(v2) test_eval('Vector([0.0, 1.0, 2.0, 3.0])') test_eval('Vector([0.0, 1.0, 2.0, 3.0]).size') test_eval('Vector(3)') test_eval('Vector(1)') test_eval('Vector(0)') test_eval('Vector(-1)') test_eval('Vector(4.2)') test_eval('Vector((10, 15))') test_eval('Vector((15, 10))') test_eval('Vector((15, 15))') test_eval('Vector((-15, 10))') test_eval('Vector((10, 15.0))')
# print('\n##### add #####') # print(V1 + V1) # print(V1 + 10) # print('\n##### radd ######') # print(V1 + V1) # print(10 + V1) # print('\n##### sub #####') # print(V1 - V2) # print(V1 - 10) # print('\n##### rsub #####') # print(V2 - V1) # print(10 - V1) print('\n##### mul #####') print(V1 * V2) print(V1 * 10) print('\n##### rmul #####') print(V2 * V1) print(10 * V1) print('\n##### div #####') print(1 / V2) print(V1.__repr__()) print(Vector.__init__.__doc__) print(Vector.__doc__)