#### PRG - End-of-term 2022 ####

# 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 ####

# Move the list items between the lists, not changing anything else. Correct answer gives you 0.5
# point, wrong penalizes you with -0.5 points, "I don't know" is worth 0 points.

# For the following variable types, can different values exist across function calls or object
# instances, or is the same value shared?
stack_memory = {
    "I don't know": ["object instance variable", "class variable", "global variable in a module",
                     "local variable in a function", "function argument",
                     "default value for a function argument"],
    "Only one value exists": [],
    "Different values co-exist": [],
}


#### TASK 2 ####

# Implement the following function according to its docstring

def line_beginnings(path):
    """Read the first character on each line of a text file. Empty lines and whitespaces are skipped.

    :param path: Path to a text file
    :return: Single string containing the characters (without whitespaces)
    """


#### TASK 3 ####

# Implement three methods (__init__, __str__, __add__) for the following class according to
# their tests. You do not need to add a docstring to any implemented method.

class RoomOccupation:
    """The percentage of places taken in a room"""


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

class TestRoomOccupation(unittest.TestCase):
    """Test RoomOccupation methods"""

    def test_init(self):
        """Test that the initializer method __init__ takes optional parameters"""
        RoomOccupation(capacity=20)
        RoomOccupation(5, capacity=20)

    def test_str(self):
        """Test string conversion"""
        self.assertEqual("0%", str(RoomOccupation(capacity=40)))
        self.assertEqual("50%", str(RoomOccupation(20, capacity=40)))

    def test_add(self):
        """Test addition to the occupation"""
        occupation = RoomOccupation(capacity=90)
        self.assertEqual("10%", str(occupation + 9))
        self.assertEqual("0%", str(occupation))


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


#### BONUS TASK ####

# In the RoomOccupation class above, make sure that the capacity cannot be exceeded.
