48 lines
1.0 KiB
Python
Raw Normal View History

2023-11-30 15:58:09 +01:00
from unittest import TestCase
from vector import Vector
class TestVector(TestCase):
def test_should_create_vector_dim_5(self):
dim = 5
vector = Vector(dim)
actual = vector.get_dimension()
expected = dim
self.assertEqual(expected, actual)
def test_should_create_zero_vector(self):
dim = 5
vector = Vector(dim)
actual = vector.get_data()
expected = [0, 0, 0, 0, 0]
self.assertEqual(expected, actual)
def test_should_create_vector(self):
data = list(range(5))
vector = Vector(data)
actual = vector.get_data()
expected = [0, 1, 2, 3, 4]
self.assertEqual(expected, actual)
def test_should_add_vectors(self):
v1 = Vector([1, 2])
v2 = Vector([3, 4])
expected = Vector([4, 6])
actual = v1 + v2
self.assertEqual(expected, actual)
def test_should_raise_error_while_adding_vectors(self):
v1 = Vector(1)
v2 = Vector(2)
self.assertRaises(ValueError, lambda: v1 + v2)