def test_getVectorAtIndex(self): v = MyVector(21, "r", 1, [2, 40, 44, 55]) u = MyVector(2, "y", 2, [1, 2]) repo = VectorRepository([]) repo.addVector(v) repo.addVector(u) self.assertEqual(repo.getVectorAtIndex(1), u)
def test_getIndex(self): v1 = MyVector(21, "r", 1, [2, 40, 44, 55]) v2 = MyVector(2, "y", 2, [1, 2]) v3 = MyVector(33, "b", 4, [45, 66]) repo = VectorRepository([]) repo.addVector(v1) repo.addVector(v2) repo.addVector(v3) self.assertEqual(repo.getIndex(33), 2)
def test_getSumOfAll(self): v1 = MyVector(21, "r", 1, [2, 40, 44, 55]) v2 = MyVector(2, "y", 2, [1, 2]) v3 = MyVector(33, "b", 4, [45, 66]) v4 = MyVector(54, "g", 6, [11, 12]) repo = VectorRepository([]) repo.addVector(v1) repo.addVector(v2) repo.addVector(v3) repo.addVector(v4) self.assertEqual(repo.getSumOfAll(), 278)
def test_updateVectorById(self): v1 = MyVector(21, "r", 1, [2, 40, 44, 55]) v2 = MyVector(2, "y", 2, [1, 2]) v3 = MyVector(33, "b", 4, [45, 66]) v4 = MyVector(54, "g", 6, [11, 12]) repo = VectorRepository([]) repo.addVector(v1) repo.addVector(v2) repo.addVector(v3) repo.updateVectorById(33, v4) self.assertEqual(repo.listOfVectors[2].get_name_id(), 54) self.assertEqual(repo.listOfVectors[2].get_colour(), "g") self.assertEqual(repo.listOfVectors[2].get_typev(), 6) self.assertEqual(repo.listOfVectors[2].get_values(), [11, 12])
def readVector(): nameid = VectorUI.readPositiveInteger( "Please introduce the id(must be a number greater than 0:") colour = VectorUI.readColour( "Please introduce the colour (should be r, g, b, y, or m)") typev = VectorUI.readPositiveInteger( "Please introduce the type(must be a number greater than 0:") values = VectorUI.readValues() return MyVector(nameid, colour, typev, values)
def test_getMaximum(self): v = MyVector(21, "r", 1, [2, 40, 44, 55]) self.assertEqual(v.getMaximum(), 55)
def test_create(self): v = MyVector(21, "r", 1, [2, 40, 44, 55]) self.assertEqual(v.get_name_id(), 21) self.assertEqual(v.get_colour(), "r") self.assertEqual(v.get_typev(), 1) self.assertEqual(v.get_values(), [2, 40, 44, 55]) v.set_name_id(2) v.set_colour("y") v.set_typev(2) v.set_values([40, 50, 30]) self.assertEqual(v.get_name_id(), 2) self.assertEqual(v.get_colour(), "y") self.assertEqual(v.get_typev(), 2) self.assertEqual(v.get_values(), [40, 50, 30])
def test_getAverage(self): v = MyVector(21, "r", 1, [2, 40, 44, 55]) self.assertEqual(v.getAverage(), 35)
def test_getProduct(self): v = MyVector(21, "r", 1, [2, 40, 44, 55]) self.assertEqual(v.getProduct(), 193600)
def test_multiplicate_Vectors(self): v = MyVector(21, "r", 1, [2, 40, 44, 55]) v.multiplicate_Vectors([2, 2, 2]) self.assertEqual(v.get_values(), [4, 80, 88, 55])
def test_substract_Vectors(self): v = MyVector(21, "r", 1, [2, 40, 44, 55]) v.substract_Vectors([1, 1]) self.assertEqual(v.get_values(), [1, 39, 44, 55])
def test_add_Vectors(self): v = MyVector(21, "r", 1, [2, 40, 44, 55]) v.add_Vectors([1, 1]) self.assertEqual(v.get_values(), [3, 41, 44, 55])
def test_add_Scalar(self): v = MyVector(21, "r", 1, [2, 40, 44, 55]) v.add_Scalar(5) self.assertEqual(v.get_values(), [7, 45, 49, 60])
from DOMAIN.business import MyVector from INFRASTRUCTURE.repository import VectorRepository from application.controller import VectorController from UI.console import VectorUI v1=MyVector(21,"r",1,[2,40,44,55]) v2=MyVector(2,"y",2,[1,2]) repo=VectorRepository([]) repo.addVector(v1) repo.addVector(v2) controller=VectorController(repo) ui=VectorUI(controller) ui.mainMenu()
def test_create(self): v = MyVector(2, "r", 1, [2, 40, 44, 55]) repo = VectorRepository([]) self.assertEqual(repo.getSize(), 0) repo.addVector(v) self.assertEqual(repo.getSize(), 1)