Hide

Problem A
Unit test a linked list

Languages en sv

This is a problem which asks you to write unit tests for a LinkedList implementations following the specification in the attached skeleton of the list. The implementations can have bugs, and your task is to find them! Neither of the bugs is related to the type of the elements added to the list, nor to any specific value inserted (i.e., no lists do have the characteristics of accepting the string "foo" but raising errors for the string "bar".)

This problem can only be solved in Python. The problem is used for examination in course DD1327 at KTH, so it should not be used for other courses that the same students might take.

Code structure

Your task is to write unit tests for LinkedList implementations in the module LinkedList.py using the unittest standard library from python. We will run test discovery on the files you submit (i.e., the same as python -m unittest does), so ensure the files you submit are named test_something.py and contain classes named TestSomething inheriting from unittest.TestCase with member functions named test_something() for each test case. You can split your tests across multiple files, or put all in one file.

Example solution

The following is an example solution NOT solving the problem (it only tests one thing). Note that the file name must match test_*.py.

import unittest

from LinkedList import LinkedList

class TestExample(unittest.TestCase):
    def test_emptyListHasSize0(self):
        list = LinkedList()
        self.assertEqual(list.size(), 0)

Please log in to submit a solution to this problem

Log in