Beispiel #1
0
    def setUp(self):
        """setup object to test"""
        self.ll = UnorderedList()
        #create a list with max index 3
        self.ll.add("ett")
        self.ll.add("två")
        self.ll.add("tre")

        self.num = UnorderedList()
Beispiel #2
0
 def setUp(cls):
     cls.ul = UnorderedList()
     cls.ul.append(5)
     cls.ul.append(7)
     cls.ul.append(9)
     cls.ul.append(7)
     cls.ul.append(6)
     cls.ul.append("Last one")
Beispiel #3
0
    def test_insert(self):
        """ Test insert method. """

        # Raise ValueExistentError.
        self.ulist = UnorderedList()
        with self.assertRaises(ValueExistentError):
            self.ulist.insert(0, "test")

        # Raise IndexOutOfRangeError.
        self.ulist.add("test node")
        with self.assertRaises(IndexOutOfRangeError):
            self.ulist.insert(-1, "test")
        with self.assertRaises(IndexOutOfRangeError):
            self.ulist.insert(1, "test")
    def __init__(self):
        "init method, creats list class"
        self.node_list = UnorderedList()

        while True:
            self.menu()

            choice = input("Välj ett alternativ ")
            while not self.try_input(choice):
                print(" input måste vara en siffra")
                choice = input("Välj ett alternativ ")

            choice = int(choice)

            if choice == 1:
                self.choice_one()

            if choice == 2:
                self.choice_two()

            if choice == 3:

                self.choice_three()

            if choice == 4:
                self.choice_four()

            if choice == 5:
                self.choice_five()

            if choice == 6:
                self.choice_six()

            if choice == 7:
                self.choice_seven()

            if choice == 8:
                self.choice_eight()

            if choice == 9:
                self.choice_nine()

            if choice == 10:
                break
Beispiel #5
0
    def __init__(self):
        """ Ctor. """

        self.ulist = UnorderedList()
        self.choices = {
            "1": self.ulist.is_empty,
            "2": self.ulist.add,
            "3": self.ulist.insert,
            "4": self.ulist.set,
            "5": self.ulist.size,
            "6": self.ulist.get,
            "7": self.ulist.index_of,
            "8": self.ulist.print_list,
            "9": self.ulist.remove,
            "a": self.ulist.add_random_items,
            "i": sort.insertion_sort,
            "b": sort.bubble_sort,
            "0": "Program terminated.",
        }
Beispiel #6
0
class TestList(unittest.TestCase):
    """ Test Class """

    studlist = UnorderedList()

    def test_a_empty_list(self):
        """ Test is_empty() """
        self.assertEqual(self.studlist.is_empty(), True)

    def test_b_nr_of_elements(self):
        """ Test size() and add() """
        self.studlist.add(30)
        self.studlist.add(55)
        self.studlist.add(10)
        self.studlist.add(25)
        self.studlist.add(40)

        self.assertEqual(self.studlist.size(), 5)

    def test_c_set_data(self):
        """ Test set() and get()"""
        self.studlist.set(3, 999)
        self.assertEqual(self.studlist.get(3), 999)

    def test_d_search(self):
        """ Test search() """
        self.assertTrue(self.studlist.search(25))
        self.assertFalse(self.studlist.search(888))

    def test_e_remove(self):
        """ Test remove() """
        current_size = self.studlist.size()
        self.assertTrue(self.studlist.search(30))
        self.studlist.remove(30)
        self.assertFalse(self.studlist.search(30))
        self.assertNotEqual(current_size, self.studlist.size())
Beispiel #7
0
 def setUp(self):
     """ Create object for all tests """
     self.node_list = UnorderedList()
Beispiel #8
0
    def setUp(self):
        """ Setup the objects. """

        self.ulist = UnorderedList()
        self.ulist.add("test node")
Beispiel #9
0
    def __init__(self):
        """ Initialize Unordered List class and start"""

        self.my_list = UnorderedList()
        self.start()
from sys import path
path.append('D:\Data_structure\Chapter3')
from unorderedlist import UnorderedList,Node
import timeit

mylist=UnorderedList()
syslist=[]


popmy = timeit.Timer("mylist.add(0)", "from __main__ import mylist")
print("Time for mylist is",popmy.timeit(number=1000))

popsys=timeit.Timer("syslist.append(0)","from __main__ import syslist")
print("Time for syslist is",popsys.timeit(number=1000))
Beispiel #11
0
    def setUp(self):
        """ Create list """

        self.unordered_list = UnorderedList()
Beispiel #12
0
 def setUp(self):
     """ Create object for all tests """
     # Arrange
     self.list = UnorderedList()
Beispiel #13
0
#!/usr/bin/env python3
""" Main file """

from unorderedlist import UnorderedList

ul = UnorderedList()

ul.add(20)
ul.add(10)
ul.add(30)
ul.add(40)
ul.add(50)

ul.print_list()
Beispiel #14
0
    recursive_insertion_sort(items, n-1)
    # tilldelar sista och näst sita elementet temp-variabler
    last = items.get(n-1)
    j = n-2

    while j >= 0 and items.get(j) > last:
        value_j = items.get(j)
        #value_jplus = items.get(j+1)
        items.set(j+1, value_j)

        j -= 1

    items.set(j+1, last)
    return items




if __name__ == "__main__":

    lista = UnorderedList()
    lista.append(1)
    lista.append(2)
    lista.append(1)
    lista.append(4)
    lista.append(5)
    print(lista.print_list())

    new = (insertion_sort(lista))
    print(new.print_list())
Beispiel #15
0
 def __init__(self):
     """initate object"""
     self.uol = UnorderedList()
     self.uol.add('ett')
     self.uol.add('två')
Beispiel #16
0
 def __init__(self):
     """initate object"""
     self.uol = UnorderedList()
Beispiel #17
0
 def __init__(self):
     """ Initialize class """
     self.list = UnorderedList()
     self.start()
Beispiel #18
0
    def setUp(self):
        """ Create object for all tests """

        self.unordered_list = UnorderedList()
        self.unordered_list.add("Patrik")
        self.unordered_list.add("Karlsson")
Beispiel #19
0
 def __init__(self):
     self.list = UnorderedList()
     self.menu = """Menu: