#### PRG - End-of-term 2021 ####

# This is the assignment for the PRG end-of-term test. This file is a valid Python module, instructions
# are written in the form of comments. Follow the instructions precisely and please note:
#
# - If the module executes any functions when imported (e.g. print), points will be subtracted.
# - If the module fails to be imported (due to errors), the solution is invalid.

import unittest


#### TASK 1 ####

# To the following statements, assign True, False, or None (no answer). Correct answer gives you
# 0.5 point, wrong penalizes you with -0.5 points, None is worth 0 points.

truthfulness = {
    "When opening a file using a 'with' statement, we need to make sure to close the file.": None,
    "Unit-tests ensure that our code does not contain an error (bug).": None,
    "Our classes, by default, create mutable objects.": None,
    "In our classes, we can change the behaviour of built-in functions and operators.": None,
    "Inheritance is a way of re-using existing code.": None,
    "Objects are the same (identical) if they are equal.": None,
}


#### TASK 2 ####

# Implement the following function according to its docstring

def save_current_time(path):
    """Write the current time (when the function was called, time is in no specific format, and date
    may be included) to a given file path.

    :param path: Path (string) to a text file (may not exist)
    """


#### TASK 3 ####

# Rewrite the following class implementation, so that it corresponds to its docstring and passes
# the unit tests.

class Vector:
    """N-dimensional vector in Euclidean space"""

    dimension = 2

    def __init__(self, x, y):
        """Initialize Vector object given a sequence of elements. The number of elements determines
        the vector dimension.

        Args:
           elements (Sequence): Elements of the vector.
        """
        self.x = x
        self.y = y

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y


# Below are unit tests for class Vector - you do not need to edit that code for task 3. Remember
# that the test self.assertEqual(target, output) passes if 'target == output'; otherwise, it fails.

class TestVector(unittest.TestCase):

    def test_init(self):
        """Test that the initializer method __init__ takes a single parameter"""
        Vector([-1, 2.0, 3, 4])

    def test_dimension(self):
        """Test the dimension attribute"""
        self.assertEqual(2, Vector([-1, 2.0]).dimension)
        self.assertEqual(4, Vector([1, 2, 3, 4]).dimension)

    def test_eq(self):
        """Test equality of two Vector instances"""
        self.assertEqual(Vector([-1, 2.0, 3, 4]), Vector([-1, 2.0, 3, 4]))
        self.assertNotEqual(Vector([-1, 0]), Vector([-1, 2.0]))
        self.assertNotEqual(Vector([1, 2]), Vector([1, 2, 3, 4]))
        self.assertNotEqual(Vector([1, 2, 3, 4]), Vector([1, 2]))


if __name__ == "__main__":
    # Execute all unit tests
    unittest.main()


#### BONUS TASK ####

# In the Vector class above, implement a support for vector addition (plus operator). Make sure
# to handle the situation when the vectors have a different dimension. Write a corresponding
# unit-test.
