コード例 #1
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)
コード例 #2
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 )
コード例 #3
0
ファイル: tests.py プロジェクト: krishRohra/PythonAssignments
def test1():
    '''
    This test case basically checks checks to see if the number of elements in the linkedHashTable
    falls below ((1-LOAD_LIMIT)*noOFBuckets) then the noOfBuckets should be reduced to half and all
    the elements present in the table should be rehashed again provided the noOfBuckets do not fall
    below the MIN_BUCKETS. So Firstly, a hashTable is created of size 50 and 50 elements are added
    to the hashTable. As the size exceeds the loadLimit,reHashing occurs.Finally 49 elements are removed
    from the hashTable and only one element '50' is left in the hashTable.
    '''
    print()
    print('First test case: ')
    test1=LinkedHashTable(50)

    addCounter=1
    for _ in range(50):
        test1.add(addCounter)
        addCounter+=1
    print_set(test1)

    removeCounter=1
    for _ in range(49):
        test1.remove(removeCounter)
        removeCounter+=1
    print_set(test1)
コード例 #4
0
ファイル: tests.py プロジェクト: coolPrat/Python_labs
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)
コード例 #5
0
ファイル: tests.py プロジェクト: coolPrat/Python_labs
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)
コード例 #6
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)
コード例 #7
0
ファイル: tests.py プロジェクト: krishRohra/PythonAssignments
def test2():
    '''
    This test case checks if the noOfBuckets is doubled if the loadLimit is exceeded,
    then the 'contains' method is tested. First, '5' is present in the hashTable and
    then all the elements are removed from the hashTable and then again it is checked
    if 5 is present in the hashTable and the expected answer is false.
    '''
    print()
    print('Second test case:')
    test2=LinkedHashTable(4)
    print('Initial No. of Buckets: '+str(test2.initial_num_buckets))
    counter=1
    for _ in range(60):
        test2.add(counter)
        counter+=1
    print_set(test2)

    print( "'5' in table?", test2.contains( 5 ) )
    for element in test2:
        test2.remove(element)
    print( "'5' in table?", test2.contains( 5 ) )
コード例 #8
0
ファイル: tests.py プロジェクト: AnushaBalusu/PythonCodes
def test3():
    '''
    Test that adds some words and some numbers as strings. Then some of them are deleted and the table is shown
    :return: None
    '''
    table = LinkedHashTable( 1 )
    table.add( "Hello" )
    table.add( "1" )
    table.add( "from" )
    table.add( "2" )
    table.add( "the" )
    table.add( "3" )
    table.add( "other" )
    table.add( "4" )
    table.add( "side!" )
    table.add( "5" )

    print_set( table )

    table.remove( "1" )
    table.remove( "3" )
    table.remove( "5" )

    print_set( table )
コード例 #9
0
ファイル: tests.py プロジェクト: AnushaBalusu/PythonCodes
def test2():
    '''
    Test that adds few words, and then random words and deleted and the table is printed again.
    :return: None
    '''
    table = LinkedHashTable( 3 )
    table.add( "Hello" )
    table.add( "it's" )
    table.add( "me" )
    table.add( "I" )
    table.add( "was" )
    table.add( "wondering" )

    print_set( table )

    table.add( "if" )
    table.add( "after" )
    table.add( "all" )
    table.add( "these" )
    table.add( "years" )
    table.add( "you'd" )
    table.add( "like" )
    table.add( "to" )
    table.add( "meet" )

    print_set( table )

    table.remove( "I" )
    table.remove( "years" )

    print_set( table )
コード例 #10
0
ファイル: tests.py プロジェクト: AnushaBalusu/PythonCodes
def test1():
    '''
    Test that adds few integers to the hash table. And then deletes one and checks it's presence in the table
    :return: None
    '''
    table = LinkedHashTable( 100 )
    table.add("0")
    table.add("1")
    table.add("2")
    table.add("3")
    table.add("4")

    print_set( table )

    print( "4 in table?", table.contains("4") )
    table.remove("4")
    print( "4 in table?", table.contains("4") )

    print_set( table )
コード例 #11
0
ファイル: tests.py プロジェクト: AnushaBalusu/PythonCodes
def test0():
    '''
    Example test method provided
    :return: None
    '''
    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 )
コード例 #12
0
ファイル: tests.py プロジェクト: lokesh91a/Python-Codes
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' ")
コード例 #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
ファイル: tests.py プロジェクト: vinCurious/LinkedHashTable
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-----------------------")
コード例 #15
0
ファイル: tests.py プロジェクト: lokesh91a/Python-Codes
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" ) )
コード例 #16
0
ファイル: tests.py プロジェクト: vinCurious/LinkedHashTable
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-----------------------")
コード例 #17
0
ファイル: tests.py プロジェクト: lokesh91a/Python-Codes
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" ) )
コード例 #18
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 )
コード例 #19
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"))
コード例 #20
0
ファイル: tests.py プロジェクト: krishRohra/PythonAssignments
def test0():
    '''
    Already Given
    '''
    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 )
コード例 #21
0
ファイル: tests.py プロジェクト: lokesh91a/Python-Codes
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' ")
コード例 #22
0
ファイル: tests.py プロジェクト: coolPrat/Python_labs
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)))
コード例 #23
0
ファイル: tests.py プロジェクト: lokesh91a/Python-Codes
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"))
コード例 #24
0
ファイル: tests.py プロジェクト: krishRohra/PythonAssignments
def test3():
    '''
    This test case checks for the various conditions while removing from the hashTable.
    Firstly, a few elements are added to the hashTable and then,
    1. The elements in the middle are removed and then the set is printed to check for the expected output
    2. The first element added to the table,that is,'Front' is removed and the elements in the hashTable
    are printed.
    3.The element which was added last to the table,that is,'Back', is removed and the elements in the hashTable are printed
    to check for the expected output
    :return:
    '''
    print()
    print('Third test case:)')
    test3=LinkedHashTable(30)
    test3.add('Front')
    test3.add('middle1')
    test3.add('middle2')
    test3.add('middle3')
    test3.add('middle4')
    test3.add('middle5')
    test3.add('Back')
    print_set(test3)

    test3.remove('middle3')
    print_set(test3)
    test3.remove('middle4')
    print_set(test3)
    test3.remove('middle2')
    print_set(test3)

    test3.remove('Front')
    print_set(test3)

    test3.remove('Back')
    print_set(test3)
    test3.remove('middle5')
    print_set(test3)
コード例 #25
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__())
コード例 #26
0
ファイル: tests.py プロジェクト: vinCurious/LinkedHashTable
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-----------------------")
コード例 #27
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__())
コード例 #28
0
ファイル: tests.py プロジェクト: vinCurious/LinkedHashTable
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-----------------------")
コード例 #29
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" ) )
コード例 #30
0
ファイル: tests.py プロジェクト: lokesh91a/Python-Codes
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"))
コード例 #31
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" ) )
コード例 #32
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)
コード例 #33
0
def test0():
    #To test the resizing capacity of the table
    print("\n**********************************TEST CASE 1")
    table = LinkedHashTable( 16 )
    table.add( "Hello" )
    table.add( "Addy" )
    table.add( "Maddy" )
    table.add( "Paddy" )
    print( "\nInitial Table: ",end='')
    print_set(table )
    print( "Initial number of buckets: ",table.initial_num_buckets )

    print("\nRemoving 'Addy'...")
    table.remove("Addy")
    print( "Updated Table: ",end='')
    print_set( table )
    print( "Number of buckets after removing 'Addy': ",table.initial_num_buckets )

    print("\nRemoving 'Hello'...")
    table.remove( "Hello" )
    print( "Updated Table: ",end='')
    print_set( table )
    print( "Number of buckets after resizing: ",table.initial_num_buckets )

    print("\nRemoving 'Maddy'...")
    table.remove( "Maddy" )
    print( "Updated table after removing 'Maddy': ", end='' )
    print_set( table )


    #To test the ability of the table to avoid duplicity of objects being added
    print("\n**********************************TEST CASE 2")
    table = LinkedHashTable ( 100 )
    print("Adding 'to','do', 'is', 'to', 'be'.....")
    table.add( "to" )
    table.add( "do" )
    table.add( "is" )
    table.add( "to" )
    table.add( "be" )

    print("Adding 'to' two more times...")
    table.add( "to" )
    table.add( "to" )
    print( "\nInitial Table: ",end='')
    print_set( table )

    print( "'to' in table?", table.contains( "to" ) )
    print("Removing 'to'...")
    table.remove("to")
    print( "'to' in table?", table.contains( "to" ) )
    print( "Updated Table on removing 'to': ",end='')
    print_set(table)
    print("\nAdding 'Hello' and 'play'..")
    table.add("Hello")
    table.add("play")
    print( "Updated Table on adding 'Hello' and 'play': ",end='')
    print_set(table)
    print("\nRemoving 'Hello' and 'be'...")
    table.remove("Hello")
    table.remove("be")
    print( "Updated Table on removing 'Hello' and 'be': ",end='')
    print_set( table )


    #Class example (to test add(), remove() and contains() test thoroughly)
    #QUESTION: WHY DOES THE EXECUTION OF THIS FILE HALT AT THE BELOW LINE AT TIMES?
    print("\n**********************************TEST CASE 3")
    table = LinkedHashTable( 10 )
    table.add( "batman" )
    table.add( "has" )
    table.add( "lots" )
    table.add( "of" )
    table.add( "gizmos" )
    table.add( "on" )
    table.add( "his" )
    table.add( "belt" )
    print( "\nInitial Table: ",end='')
    print_set( table )

    print( "'gizmos' in table?", table.contains( "gizmos" ) )
    print( "'batman' in table?", table.contains( "batman" ) )
    print( "'has' in table?", table.contains( "has" ) )
    print("\nRemoving 'batman','of','on','belt','has','lots','gizmos' from the table...")
    table.remove( "batman" )
    table.remove( "has" )
    table.remove( "lots" )
    table.remove( "of" )
    table.remove( "gizmos" )
    table.remove( "belt" )
    print("Table size when two elements remain...: ", table.size)
    print("\nRemoving 'on'..")
    table.remove( "on" )
    print("\nUpdated Table after removing 'on' : ", end='')
    print_set( table )
    print("table.front.obj: ",table.front.obj)
    print("Table size when one element remain...: ", table.size)
    print("\nRemoving 'his'..")
    table.remove( "his" )
    print("\nUpdated Table after removing 'batman','of','on','belt','has','lots','gizmos' : ", end='')
    if table.size == 0:
        print ("No more objects in the hash table!")
    else:
            print_set( table )