示例#1
0
def test2():
    """
        This method tests for adding duplicate elements and testing remove method for non-existing elements
        """
    print("-----------------------TEST2 START-----------------------")
    table2 = LinkedHashTable(4)
    table2.add("to")
    table2.add("be")
    table2.add("or")
    table2.add("not")
    table2.add("to1")
    table2.add("be1")

    print("\nHash Table: ")
    print_set(table2)
    print("adding duplicate 'to1'")
    table2.add("to1")
    print("Hash Table: ")
    print_set(table2)

    print("\nHash Table: ")
    print_set(table2)
    print("removing non-existing element 'here'")
    table2.remove("here")
    print("Hash Table: ")
    print_set(table2)
    print("-----------------------TEST2 END-----------------------")
示例#2
0
def test3():
    """
        This method tests for rehashing and downsizing scenarios
        """
    print("-----------------------TEST3 START-----------------------")
    table3 = LinkedHashTable(12)
    table3.add("to")
    table3.add("be")
    table3.add("or")
    table3.add("not")
    table3.add("to1")
    table3.add("be1")
    table3.add("to2")
    table3.add("be2")

    print("\nHash Table: ")
    print_set(table3)

    print(
        "Testing whether the table increases when loadlimit is reached by adding 'here'"
    )
    table3.add("here")
    print("\nHash Table: ")
    print_set(table3)

    print(
        "Testing whether the table downsizes when size goes below loadlimit by removing element 'here'"
    )
    table3.remove("here")

    print("\nHash Table: ")
    print_set(table3)

    print("-----------------------TEST3 END-----------------------")
示例#3
0
def test3():
    """
    This is last test which checks the following things

    adds 4 objects
    removes 3 of them
    Now, it tries to remove the object which doesn't exist which raises an
    exception "Trying to remove ' + obj +  ' which doesnt exist"
    """
    print("\nTest 3 : ")
    table = LinkedHashTable(1)
    table.add("I")
    table.add("am")
    table.add("last")
    table.add("test")

    print_set(table)
    print("Size " + str(table.size))
    print("'I' in table?", table.contains("I"))
    print("'am' in table?", table.contains("am"))
    print("'last' in table?", table.contains("last"))

    table.remove("I")
    table.remove("am")
    table.remove("last")

    print()
    print_set(table)
    print("Size " + str(table.size))
    print("'I' in table?", table.contains("I"))
    print("'am' in table?", table.contains("am"))
    print("'last' in table?", table.contains("last"))

    table.remove(" 'remove' ")
示例#4
0
def test1():
    """
    This test checks the size, ordering, remove, contains and add
    adds some objects in order
    try to add duplicate objects
    check contains on some objects
    removes some objects
    check contains on removed objects
    """
    print("Test 1 :")
    table = LinkedHashTable()
    table.add("This")
    table.add("is")
    table.add("test")
    table.add("one")
    table.add("which")
    table.add("checks")
    table.add("the")
    table.add("ordering")
    table.add("of")
    table.add("the")
    table.add("data")
    table.add("entered")
    table.add("in")
    table.add("hashset")

    #checks for duplicate values
    table.add("ordering")
    table.add("entered")
    table.add("hashset")
    table.add("one")

    print_set(table)
    print("Size " + str(table.size))

    #Checks the contains function
    print("'This' in table?", table.contains("This"))
    print("'is' in table?", table.contains("is"))
    print("'test' in table?", table.contains("test"))
    print("'one' in table?", table.contains("one"))
    print("'of' in table?", table.contains("of"))
    print("'the' in table?", table.contains("the"))
    print("'hashset' in table?", table.contains("hashset"))

    print('\nRemoving some data')
    table.remove("ordering")
    table.remove("This")
    table.remove("is")
    table.remove("the")
    table.remove("hashset")
    table.remove("test")

    print_set(table)
    print("Size " + str(table.size))

    print("'ordering' in table?", table.contains("ordering"))
    print("'hashset' in table?", table.contains("hashset"))
    print("'the' in table?", table.contains("the"))
示例#5
0
def test3():
    """
    This Test check remove Functionality of the hash map
    add 10 elements
    check size
    check contains
    remove 3 elements
    check size
    check contains
    remove element which was already removed to check exception
    :return:
    """
    print("\nTest three : \n")
    table = LinkedHashTable(1)
    table.add("deepak")
    table.add("sri")
    table.add("nora")
    table.add("rit")
    table.add("sahil")
    table.add("lokesh")
    table.add("payal")
    table.add("hanna")
    table.add("surya")
    table.add("anna")

    print_set(table)
    print("Size " + str(table.size))

    print("'hanna' in table?", table.contains("hanna"))
    print("'surya' in table?", table.contains("surya"))
    print("pearl(Not Inserted)  in table?", table.contains("pearl"))
    print("'deepak' in table?", table.contains("deepak"))
    print("'rit' in table?", table.contains("rit"))
    print("'anurag'(Not Inserted) in table?", table.contains("anurag"))
    print("Size " + str(table.size))

    table.remove("hanna")
    table.remove("surya")
    table.remove("deepak")

    print("Removed: deepak surya and hanna")
    print_set(table)
    print("Size " + str(table.size))
    print("'deepak' in table?", table.contains("deepak"))
    print("'surya' in table?", table.contains("surya"))
    print("'hanna' in table?", table.contains("hanna"))

    print(
        "Re-Removing an element: Deepak (already removed) should raise exception"
    )
    try:
        table.remove("deepak")
    except Exception as details:
        print("Exceptions was raise :" + str(details))
        print(details.__str__())
示例#6
0
文件: tests.py 项目: QQW233/CSCI-605
def test2():
    '''
    Tests if it works correctly when a table size extension and rehashing is needed.
    '''
    table = LinkedHashTable(10)

    for i in range(15):
        table.add(chr(ord('a') + i))

    print("Test case 2:\nExpected: a b c d e f g h i j k l m n o ")
    print("Actual: ", end = '')
    print_set(table)
示例#7
0
def test2():
    string = "to to to to are four to's"
    print("String being added: " + string)
    allGood = True
    table = LinkedHashTable( 100 )
    stringset = string.split(" ")
    for i in stringset:
        table.add(i)
    print("table: ", end= " ")
    print_set(table)
    table.remove("to")
    print( "'to' in table?", table.contains( "to" ) )
    print("table: ", end= " ")
    print_set(table)
示例#8
0
文件: tests.py 项目: QQW233/CSCI-605
def test3():
    '''
    Tests if it works correctly when a table size reduction and rehashing is needed.
    '''
    table = LinkedHashTable(10)

    for i in range(15):
        table.add(chr(ord('a') + i))

    for i in range(14, 1, -1):
        table.remove(chr(ord('a') + i))

    print("Test case 3:\nExpected: a b ")
    print("Actual: ", end = '')
    print_set(table)
示例#9
0
def test0():
    table = LinkedHashTable(100)
    table.add("to")
    table.add("do")
    table.add("is")
    table.add("to")
    table.add("be")

    print_set(table)

    print("'to' in table?", table.contains("to"))
    table.remove("to")
    print("'to' in table?", table.contains("to"))

    print_set(table)
示例#10
0
文件: tests.py 项目: QQW233/CSCI-605
def test1():
    '''
    Tests the corner case that all keys in the LinkedHashTable are removed 
    and then insert new keys. 
    '''

    table = LinkedHashTable(10)

    table.add('test')
    table.add('case')
    table.remove('test')
    table.remove('case')
    table.add('update')

    print("Test case 1:\nExpected: update ")
    print("Actual: ", end = '')
    print_set( table )
示例#11
0
def test2():
    """
    This test try to insert duplicate values in linked  hash map and check size of the hash map
    by this test we can check logical implementation of add method.
    :return:
    """
    print("\nTest Second  \n:")
    table = LinkedHashTable()
    table.add("deepak")
    table.add("sri")
    table.add("nora")
    table.add("emily")
    table.add("brain")
    table.add("cathy")
    table.add("surya")
    table.add("anurag")
    table.add("sahil")
    table.add("lokesh")
    table.add("payal")
    table.add("hanna")
    table.add("surya")
    table.add("anna")
    table.add("arpit")
    table.add("avinav")

    # adding same element multiple times for checking
    #logical implementation of add method
    table.add("anna")
    table.add("brain")
    table.add("deepak")
    table.add("nora")
    table.add("hanna")
    table.add("surya")
    table.add("anna")

    print_set(table)
    print("Size " + str(table.size))

    print("'deepak' in table?", table.contains("deepak"))
    print("'sri' in table?", table.contains("sri"))
    print("'nora' in table?", table.contains("nora"))
    print("'emily' in table?", table.contains("emily"))
    print("'hanna' in table?", table.contains("hanna"))
    print("'surya' in table?", table.contains("surya"))
    print("'anna' in table?", table.contains("anna"))
示例#12
0
def test1():
    allGood = True
    table = LinkedHashTable( 1 )
    string = "batman has lots of gizmos in his belt"
    stringset = string.split(" ")
    for i in stringset:
        table.add(i)
    print("table: ", end= " ")
    print_set(table)
    for j in stringset:
        if table.contains(j) is False:
            print("OMG!")
            allGood = False
    print("allGood: " + str(allGood))
    for j in stringset:
        table.remove(j)
    print("table: ", end= " ")
    print_set(table)
示例#13
0
def test1():
    """
    This Test add 10 elements in has map and remove all of them to check the:
     Size after and before removal
     Contains after and before the removal
     Note: By removing all elements we also covered the testing of re-hashing and downsizing of
     hash table
    :return: None
    """
    print("\n Test First \n: ")
    table = LinkedHashTable()
    table.add("brain")
    table.add("cathy")
    table.add("surya")
    table.add("anurag")
    table.add("deepak")
    table.add("sri")
    table.add("nora")
    table.add("arpit")
    table.add("avinav")
    table.add("7102198")

    print_set(table)
    print("Size of the set: " + str(table.size))
    print("'rit' in table?", table.contains("rit"))
    print("'anurag' in table?", table.contains("anurag"))
    print("'7102198' in table?", table.contains("7102198"))

    table.remove("deepak")
    table.remove("sri")
    table.remove("nora")
    table.remove("7102198")
    table.remove("brain")
    table.remove("cathy")
    table.remove("surya")
    table.remove("anurag")
    table.remove("arpit")
    table.remove("avinav")

    print_set(table)
    print("Size " + str(table.size))
    print("'avinav' in table?", table.contains("avinav"))
    print("'rit' in table?", table.contains("rit"))
    print("'anurag' in table?", table.contains("anurag"))
示例#14
0
def test0():
    """ already provided test for adding, printing and removing elements
     """
    print("-----------------------TEST0 START-----------------------")
    table = LinkedHashTable(100)
    table.add("to")
    table.add("do")
    table.add("is")
    table.add("to")
    table.add("be")

    print_set(table)

    #
    print("'to' in table?", table.contains("to"))
    table.remove("to")
    print("'to' in table?", table.contains("to"))

    print_set(table)
    print("-----------------------TEST0 END-----------------------")
示例#15
0
文件: tests.py 项目: QQW233/CSCI-605
def test0():
    '''
    Tests the basic add and remove key function.
    '''
    table = LinkedHashTable( 100 )
    table.add( "to" )
    table.add( "do" )
    table.add( "is" )
    table.add( "to" )
    table.add( "be" )

    print_set( table )

    print( "'to' in table?", table.contains( "to" ) )
    table.remove( "to" )
    print( "'to' in table?", table.contains( "to" ) )

    print("Test case 0:\nExpected: do is be ")
    print("Actual: ", end = '')
    print_set( table )
示例#16
0
def test2():
    """
    Adds few objects in the hashset
    check contains function on few
    Now, in this test all elements which were added are removed from the hashset
    size is checked
    Now, again contains is checked for few
    :return:
    """
    print("\nTest 2 : ")
    table = LinkedHashTable()
    table.add("This")
    table.add("is")
    table.add("test")
    table.add("2")
    table.add("which")
    table.add("checks")
    table.add("the")
    table.add("hashset")

    print_set(table)
    print("Size " + str(table.size))
    print("'2' in table?", table.contains("2"))
    print("'three' in table?", table.contains("three"))
    print("'hashset' in table?", table.contains("hashset"))

    table.remove("This")
    table.remove("is")
    table.remove("test")
    table.remove("2")
    table.remove("which")
    table.remove("checks")
    table.remove("the")
    table.remove("hashset")

    print_set(table)
    print("Size " + str(table.size))
    print("'two' in table?", table.contains("two"))
    print("'three' in table?", table.contains("three"))
    print("'hashset' in table?", table.contains("hashset"))
示例#17
0
def test3():
    string = "abcd"
    table = LinkedHashTable( 100 )
    for i in range(10):
        table.add(string + str(i))
    print("table: ", end= " ")
    print_set(table)
    print("**************************************************************")
    for s in table:
        table.remove(s)
        print("----------------------------------------------------------")
        print("table: ", end= " ")
        print_set(table)
    for i in range(10):
        table.add(i)
    print("table: ", end= " ")
    print_set(table)
    print("**************************************************************")
    for s in table:
        table.add(s)
        print("----------------------------------------------------------")
        print("table: ", end= " ")
        print_set(table)
    print("is 10 in?" + str(table.contains(10)))
示例#18
0
def test1():
    """
    This method tests removing of front, middle and back element
    """
    print("-----------------------TEST1 START-----------------------")
    table1 = LinkedHashTable(4)
    table1.add("to")
    table1.add("be")
    table1.add("or")
    table1.add("not")
    table1.add("to1")
    table1.add("be1")

    print("Hash Table: ")
    print_set(table1)
    print("\n'to' in table?", table1.contains("to"))
    print("Removing front i.e. 'to'", )
    table1.remove("to")
    print("'to' in table?", table1.contains("to"))
    print("Hash Table: ")
    print_set(table1)

    print("\n'not' in table?", table1.contains("not"))
    table1.remove("not")
    print("Removing middle elemtnt i.e 'not'", )
    print("'not' in table?", table1.contains("not"))
    print("Hash Table: ")
    print_set(table1)

    print("\n'be1' in table?", table1.contains("be1"))
    table1.remove("be1")
    print("Removing last elemtnt i.e 'be1'", )
    print("'be1' in table?", table1.contains("be1"))
    print("Hash Table: ")
    print_set(table1)
    print("-----------------------TEST1 END-----------------------")