Exemple #1
0
 def test_addVector(self):
     vector = MyVector("abcd", "r", 1, [0, 0, 0, 0])
     vector.addVector([1, 2, 3, 4, 5, 6])
     self.assertEqual(vector.getValues(), [1, 2, 3, 4])
     vector.setValues([1, 2, 3, 4, 5, 6])
     vector.addVector([1, 2, 3])
     self.assertEqual(vector.getValues(), [2, 4, 6, 4, 5, 6])
Exemple #2
0
 def test_subVector(self):
     vector = MyVector("abcd", "r", 1, [1, 2, 3, 4])
     vector.subVector([2, 2, 2, 2, 2, 2])
     self.assertEqual(vector.getValues(), [-1, 0, 1, 2])
     vector.setValues([1, 2, 3, 4, 5, 6])
     vector.subVector([3, -2, 1])
     self.assertEqual(vector.getValues(), [-2, 4, 2, 4, 5, 6])
Exemple #3
0
 def test_mulVector(self):
     vector = MyVector("abcd", "r", 1, [1, 2, 3, 4])
     vector.multVector([2, 2, 2, 2, 2, 2])
     self.assertEqual(vector.getValues(), [2, 4, 6, 8])
     vector.setValues([1, 2, 3, 4, 5, 6])
     vector.multVector([3, -2, 1])
     self.assertEqual(vector.getValues(), [3, -4, 3, 4, 5, 6])
Exemple #4
0
 def test_addVector(self):
     repo = VectorRepository()
     repo.addVector(MyVector("prim", "r", 1, [1, 2]))
     self.assertEqual(repo.getAllVectors()[0],
                      MyVector("prim", "r", 1, [1, 2]))
     try:
         repo.addVector(MyVector("prim", "g", 3, [1, 2, 3, 4]))
         assert False
     except:
         assert True
Exemple #5
0
 def test_averageOfElements(self):
     vector = MyVector("abcd", "r", 1, [1, 2, 3, 4])
     self.assertEqual(vector.averageOfElements(), 2.5)
     vector.setValues([1, 2, 3, 4, 5, 6])
     self.assertEqual(vector.averageOfElements(), 3.5)
     vector.setValues([3, -4, 3, 4, 5, 6])
     self.assertEqual(vector.averageOfElements(), 17 / 6)
Exemple #6
0
 def test_sumOfElements(self):
     vector = MyVector("abcd", "r", 1, [1, 2, 3, 4])
     self.assertEqual(vector.sumOfElements(), 10)
     vector.setValues([1, 2, 3, 4, 5, 6])
     self.assertEqual(vector.sumOfElements(), 21)
     vector.setValues([3, -4, 3, 4, 5, 6])
     self.assertEqual(vector.sumOfElements(), 17)
Exemple #7
0
 def test_productOfElements(self):
     vector = MyVector("abcd", "r", 1, [1, 2, 3, 4])
     self.assertEqual(vector.productOfElements(), 24)
     vector.setValues([-1, 2, 3, 4, 5, 6])
     self.assertEqual(vector.productOfElements(), -720)
     vector.setValues([3, -4, 3, 4, 5, 6])
     self.assertEqual(vector.productOfElements(), -4320)
Exemple #8
0
 def test_maxOfElements(self):
     vector = MyVector("abcd", "r", 1, [1, 2, 3, 4])
     self.assertEqual(vector.maxOfElements(), 4)
     vector.setValues([-1, 2, 3, 4, 5, 6])
     self.assertEqual(vector.maxOfElements(), 6)
     vector.setValues([3, -4, 3, 4, 6, 5])
     self.assertEqual(vector.maxOfElements(), 6)
Exemple #9
0
 def test_minOfElements(self):
     vector = MyVector("abcd", "r", 1, [1, 2, 3, 4])
     self.assertEqual(vector.minOfElements(), 1)
     vector.setValues([-1, 2, 3, 4, 5, 6])
     self.assertEqual(vector.minOfElements(), -1)
     vector.setValues([3, -4, 3, 4, 5, 6])
     self.assertEqual(vector.minOfElements(), -4)
Exemple #10
0
 def test_setType(self):
     vector = MyVector("abcd", "r", 1, [1, 2, 3, 4])
     vector.setType(3)
     self.assertEqual(vector.getType(), 3)
     vector.setType(5)
     self.assertEqual(vector.getType(), 5)
     try:
         vector.setType("a")
         assert False
     except:
         assert True
 def getVectorOfSums(self):
     if len(self.__repository) == 0:
         raise ValueError("Repository: Empty repository")
     size = self.getMinSize()
     values = []
     for index in range(0, size):
         values.append(self.__repository[0].getValues()[index])
     vector = MyVector("sum", "r", 1, values)
     for index in range(1, len(self.__repository)):
         vector.addVector(self.__repository[index].getValues())
     return vector
 def getProdOfConsecutiveVectors(self):
     if len(self.__repository) == 0:
         raise ValueError("Repository: Empty repository")
     size = self.getMinSize()
     values = []
     for index in range(0, size):
         values.append(1)
     vector = MyVector("prod", "r", 1, values)
     for el in self.__repository:
         vector.multVector(el.getValues())
     return vector.getValues()
Exemple #13
0
 def test_setValues(self):
     vector = MyVector("abcd", "r", 1, [1, 2, 3, 4])
     vector.setValues([1, 2, 3, 4, 5])
     self.assertEqual(vector.getValues(), [1, 2, 3, 4, 5])
     vector.setValues([])
     self.assertEqual(vector.getValues(), [])
     try:
         vector.setValues("a")
         assert False
     except:
         assert True
Exemple #14
0
 def test_setColour(self):
     vector = MyVector("abcd", "r", 1, [1, 2, 3, 4])
     vector.setColour("g")
     self.assertEqual(vector.getColour(), "g")
     vector.setColour("b")
     self.assertEqual(vector.getColour(), "b")
     try:
         vector.setColour("n")
         assert False
     except:
         assert True
Exemple #15
0
def start():
    repo = VectorRepository()
    repo.addVector(MyVector("abc", "r", 1, [1, 2, 3, 4]))
    repo.addVector(MyVector("aaa", "g", 3, [2, 2, 3, 4, 7, 8]))
    repo.addVector(MyVector("test", "b", 3, [4, 5]))
    repo.addVector(MyVector("1", 'r', 2, [10, 3, 9]))
    repo.addVector(MyVector("2", 'y', 4, [1, 3, 6, 9]))

    controller = VectorController(repo)

    ui = UI(controller)
    ui.run()
Exemple #16
0
    def test_create(self):
        vector = MyVector("abcd", "r", 1, [1, 2, 3, 4])
        self.assertEqual(vector.getNameID(), "abcd")
        self.assertEqual(vector.getColour(), 'r')
        self.assertEqual(vector.getType(), 1)
        self.assertEqual(vector.getValues(), [1, 2, 3, 4])

        try:
            vector = MyVector(123, "r", 1, "1, 2, 3, 4")
            assert False
        except:
            assert True

        try:
            vector2 = MyVector("abcd", "g", 1, [1, 2, 3, 4])
            assert False
        except:
            assert True
Exemple #17
0
 def test_getAllVectors(self):
     repo = VectorRepository()
     repo.addVector(MyVector("1", "r", 2, [1, 2, 3]))
     repo.addVector(MyVector("12", "g", 1, [123, 211, 332]))
     repo.addVector(MyVector("311", "b", 4, [2, 1, 3]))
Exemple #18
0
 def test_addScalar(self):
     vector = MyVector("abcd", "r", 1, [0, 0, 0, 0])
     vector.addScalar(2)
     self.assertEqual(vector.getValues(), [2, 2, 2, 2])
     vector.addScalar(-2)
     self.assertEqual(vector.getValues(), [0, 0, 0, 0])
     vector.addScalar(10)
     self.assertEqual(vector.getValues(), [10, 10, 10, 10])
Exemple #19
0
 def test_setNameID(self):
     vector = MyVector("abcd", "r", 1, [1, 2, 3, 4])
     vector.setNameID("abc")
     self.assertEqual(vector.getNameID(), "abc")
     vector.setNameID("a")
     self.assertEqual(vector.getNameID(), "a")
     vector.setNameID("1234")
     self.assertEqual(vector.getNameID(), "1234")
     try:
         vector.setNameID(1234)
         assert False
     except:
         assert True
     vector.setNameID("AnAnas")
     self.assertEqual(vector.getNameID(), "AnAnas")