def test_bruteforce(self):
        # Given these inputs
        maxHours =10
        testSubjects = {'1.00':(10, 5), '2.00': (9, 5), '3.00': (8, 4), '4.00': (3, 4), '5.00': (1, 1)}

        # when i call this method

        dictionary = ps9.bruteForceAdvisor(testSubjects, maxHours)

        # Then i expect

        self.assertTrue(dictionary == {'1.00':(10,5), '3.00':(8,4), '5.00':(1,1)})
    def test_bruteforce(self):
        # Given these inputs
        maxHours = 10
        testSubjects = {
            '1.00': (10, 5),
            '2.00': (9, 5),
            '3.00': (8, 4),
            '4.00': (3, 4),
            '5.00': (1, 1)
        }

        # when i call this method

        dictionary = ps9.bruteForceAdvisor(testSubjects, maxHours)

        # Then i expect

        self.assertTrue(dictionary == {
            '1.00': (10, 5),
            '3.00': (8, 4),
            '5.00': (1, 1)
        })
示例#3
0
def test_bruteForceAdvisor():
    #shortenedSubjects = {'6.08': (1, 10), '6.09': (3, 7), '6.19': (8, 19), '6.10': (8, 18), '6.00': (10, 1), '6.01': (5, 4), '6.02': (5, 6), '6.03': (2, 9), '6.04': (1, 2), '6.05': (1, 18), '6.06': (5, 19), '6.07': (2, 10), '6.13': (9, 16), '6.18': (10, 4), '6.15': (10, 6), '6.16': (6, 9), '6.12': (6, 3), '6.17': (9, 3), '6.14': (10, 8), '6.11': (6, 8)}
    shortenedSubjects = {'6.00': (10, 1), '6.01': (5, 4), '6.02': (5, 6), '6.04': (1, 2), '6.18': (10, 4), '6.15': (10, 6), '6.12': (6, 3), '6.17': (9, 3)}
    dontmutate = shortenedSubjects.copy()

    failed = False
    expected = {'6.00': (10, 1), '6.04': (1, 2)}
    print
    print "shortenedSubjects = " + str(shortenedSubjects)
    print "Trying bruteForceAdvisor(shortenedSubjects, 3)..."
    actual = ps9.bruteForceAdvisor(shortenedSubjects, 3)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 3), expected " + str(expected) + " but was actually " + str(actual))
    if dontmutate != shortenedSubjects:
        failed = True
        print("ERROR in bruteForceAdvisor: subjects was mutated")
    shortenedSubjects = {'6.00': (10, 1), '6.01': (5, 4), '6.02': (5, 6), '6.04': (1, 2), '6.18': (10, 4), '6.15': (10, 6), '6.12': (6, 3), '6.17': (9, 3)}
    expected = {'6.00': (10, 1), '6.17': (9, 3)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 4)..."
    actual = ps9.bruteForceAdvisor(shortenedSubjects, 4)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 4), expected " + str(expected) + " but was actually " + str(actual))
    
    shortenedSubjects = {'6.00': (10, 1), '6.01': (5, 4), '6.02': (5, 6), '6.04': (1, 2), '6.18': (10, 4), '6.15': (10, 6), '6.12': (6, 3), '6.17': (9, 3)}
    expected = {'6.00': (10, 1), '6.18': (10, 4)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 5)..."
    actual = ps9.bruteForceAdvisor(shortenedSubjects, 5)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 5), expected " + str(expected) + " but was actually " + str(actual))
    shortenedSubjects = {'6.00': (10, 1), '6.01': (5, 4), '6.02': (5, 6), '6.04': (1, 2), '6.18': (10, 4), '6.15': (10, 6), '6.12': (6, 3), '6.17': (9, 3)}
    expected = {'6.00': (10, 1), '6.17': (9, 3)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 6)..."
    actual = ps9.bruteForceAdvisor(shortenedSubjects, 6)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 6), expected " + str(expected) + " but was actually " + str(actual))
    shortenedSubjects = {'6.00': (10, 1), '6.01': (5, 4), '6.02': (5, 6), '6.04': (1, 2), '6.18': (10, 4), '6.15': (10, 6), '6.12': (6, 3), '6.17': (9, 3)}
    expected = {'6.00': (10, 1), '6.12': (6, 3), '6.17': (9, 3)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 7)..."
    actual = ps9.bruteForceAdvisor(shortenedSubjects, 7)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 7), expected " + str(expected) + " but was actually " + str(actual))
    

    shortenedSubjects = {'12.02': (5, 5), '12.03': (2, 1), '12.04': (7, 1), '12.07': (6, 3), '12.06': (2, 5), '12.08': (2, 4), '12.09': (8, 2), '12.15': (10, 7)}
    print
    print "shortenedSubjects = " + str(shortenedSubjects)
    expected = {'12.09': (8, 2), '12.04': (7, 1)}
    actual = ps9.bruteForceAdvisor(shortenedSubjects, 3)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 3), expected " + str(expected) + " but was actually " + str(actual))
    shortenedSubjects = {'12.02': (5, 5), '12.03': (2, 1), '12.04': (7, 1), '12.07': (6, 3), '12.06': (2, 5), '12.08': (2, 4), '12.09': (8, 2), '12.15': (10, 7)}
    expected = {'12.09': (8, 2), '12.03': (2, 1), '12.04': (7, 1)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 4)..."
    actual = ps9.bruteForceAdvisor(shortenedSubjects, 4)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 4), expected " + str(expected) + " but was actually " + str(actual))
    
    shortenedSubjects = {'12.02': (5, 5), '12.03': (2, 1), '12.04': (7, 1), '12.07': (6, 3), '12.06': (2, 5), '12.08': (2, 4), '12.09': (8, 2), '12.15': (10, 7)}
    expected = {'12.09': (8, 2), '12.03': (2, 1), '12.04': (7, 1)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 5)..."
    actual = ps9.bruteForceAdvisor(shortenedSubjects, 5)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 5), expected " + str(expected) + " but was actually " + str(actual))
    shortenedSubjects = {'12.02': (5, 5), '12.03': (2, 1), '12.04': (7, 1), '12.07': (6, 3), '12.06': (2, 5), '12.08': (2, 4), '12.09': (8, 2), '12.15': (10, 7)}
    expected = {'12.09': (8, 2), '12.04': (7, 1), '12.07': (6, 3)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 6)..."
    actual = ps9.bruteForceAdvisor(shortenedSubjects, 6)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 6), expected " + str(expected) + " but was actually " + str(actual))
    shortenedSubjects = {'12.02': (5, 5), '12.03': (2, 1), '12.04': (7, 1), '12.07': (6, 3), '12.06': (2, 5), '12.08': (2, 4), '12.09': (8, 2), '12.15': (10, 7)}
    expected = {'12.09': (8, 2), '12.03': (2, 1), '12.04': (7, 1), '12.07': (6, 3)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 7)..."
    actual = ps9.bruteForceAdvisor(shortenedSubjects, 7)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 7), expected " + str(expected) + " but was actually " + str(actual))
    if failed:
        raise Exception
def test_bruteForceAdvisor():
    #shortenedSubjects = {'6.08': (1, 10), '6.09': (3, 7), '6.19': (8, 19), '6.10': (8, 18), '6.00': (10, 1), '6.01': (5, 4), '6.02': (5, 6), '6.03': (2, 9), '6.04': (1, 2), '6.05': (1, 18), '6.06': (5, 19), '6.07': (2, 10), '6.13': (9, 16), '6.18': (10, 4), '6.15': (10, 6), '6.16': (6, 9), '6.12': (6, 3), '6.17': (9, 3), '6.14': (10, 8), '6.11': (6, 8)}
    shortenedSubjects = {'6.00': (10, 1), '6.01': (5, 4), '6.02': (5, 6), '6.04': (1, 2), '6.18': (10, 4), '6.15': (10, 6), '6.12': (6, 3), '6.17': (9, 3)}
    dontmutate = shortenedSubjects.copy()

    failed = False
    expected = {'6.00': (10, 1), '6.04': (1, 2)}
    print
    print "shortenedSubjects = " + str(shortenedSubjects)
    print "Trying bruteForceAdvisor(shortenedSubjects, 3)..."
    (total_value, actual) = ps9.bruteForceAdvisor(shortenedSubjects, 3)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 3), expected " + str(expected) + " but was actually " + str(actual))
    if dontmutate != shortenedSubjects:
        failed = True
        print("ERROR in bruteForceAdvisor: subjects was mutated")
    shortenedSubjects = {'6.00': (10, 1), '6.01': (5, 4), '6.02': (5, 6), '6.04': (1, 2), '6.18': (10, 4), '6.15': (10, 6), '6.12': (6, 3), '6.17': (9, 3)}
    expected = {'6.00': (10, 1), '6.17': (9, 3)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 4)..."
    (total_value, actual) = ps9.bruteForceAdvisor(shortenedSubjects, 4)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 4), expected " + str(expected) + " but was actually " + str(actual))
    
    shortenedSubjects = {'6.00': (10, 1), '6.01': (5, 4), '6.02': (5, 6), '6.04': (1, 2), '6.18': (10, 4), '6.15': (10, 6), '6.12': (6, 3), '6.17': (9, 3)}
    expected = {'6.00': (10, 1), '6.18': (10, 4)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 5)..."
    (total_value, actual) = ps9.bruteForceAdvisor(shortenedSubjects, 5)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 5), expected " + str(expected) + " but was actually " + str(actual))
    shortenedSubjects = {'6.00': (10, 1), '6.01': (5, 4), '6.02': (5, 6), '6.04': (1, 2), '6.18': (10, 4), '6.15': (10, 6), '6.12': (6, 3), '6.17': (9, 3)}
    expected = {'6.00': (10, 1), '6.17': (9, 3)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 6)..."
    (total_value, actual) = ps9.bruteForceAdvisor(shortenedSubjects, 6)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 6), expected " + str(expected) + " but was actually " + str(actual))
    shortenedSubjects = {'6.00': (10, 1), '6.01': (5, 4), '6.02': (5, 6), '6.04': (1, 2), '6.18': (10, 4), '6.15': (10, 6), '6.12': (6, 3), '6.17': (9, 3)}
    expected = {'6.00': (10, 1), '6.12': (6, 3), '6.17': (9, 3)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 7)..."
    (total_value, actual) = ps9.bruteForceAdvisor(shortenedSubjects, 7)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 7), expected " + str(expected) + " but was actually " + str(actual))
    

    shortenedSubjects = {'12.02': (5, 5), '12.03': (2, 1), '12.04': (7, 1), '12.07': (6, 3), '12.06': (2, 5), '12.08': (2, 4), '12.09': (8, 2), '12.15': (10, 7)}
    print
    print "shortenedSubjects = " + str(shortenedSubjects)
    expected = {'12.09': (8, 2), '12.04': (7, 1)}
    (total_value, actual) = ps9.bruteForceAdvisor(shortenedSubjects, 3)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 3), expected " + str(expected) + " but was actually " + str(actual))
    shortenedSubjects = {'12.02': (5, 5), '12.03': (2, 1), '12.04': (7, 1), '12.07': (6, 3), '12.06': (2, 5), '12.08': (2, 4), '12.09': (8, 2), '12.15': (10, 7)}
    expected = {'12.09': (8, 2), '12.03': (2, 1), '12.04': (7, 1)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 4)..."
    (total_value, actual) = ps9.bruteForceAdvisor(shortenedSubjects, 4)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 4), expected " + str(expected) + " but was actually " + str(actual))
    
    shortenedSubjects = {'12.02': (5, 5), '12.03': (2, 1), '12.04': (7, 1), '12.07': (6, 3), '12.06': (2, 5), '12.08': (2, 4), '12.09': (8, 2), '12.15': (10, 7)}
    expected = {'12.09': (8, 2), '12.03': (2, 1), '12.04': (7, 1)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 5)..."
    (total_value, actual) = ps9.bruteForceAdvisor(shortenedSubjects, 5)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 5), expected " + str(expected) + " but was actually " + str(actual))
    shortenedSubjects = {'12.02': (5, 5), '12.03': (2, 1), '12.04': (7, 1), '12.07': (6, 3), '12.06': (2, 5), '12.08': (2, 4), '12.09': (8, 2), '12.15': (10, 7)}
    expected = {'12.09': (8, 2), '12.04': (7, 1), '12.07': (6, 3)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 6)..."
    (total_value, actual) = ps9.bruteForceAdvisor(shortenedSubjects, 6)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 6), expected " + str(expected) + " but was actually " + str(actual))
    shortenedSubjects = {'12.02': (5, 5), '12.03': (2, 1), '12.04': (7, 1), '12.07': (6, 3), '12.06': (2, 5), '12.08': (2, 4), '12.09': (8, 2), '12.15': (10, 7)}
    expected = {'12.09': (8, 2), '12.03': (2, 1), '12.04': (7, 1), '12.07': (6, 3)}
    print "Trying bruteForceAdvisor(shortenedSubjects, 7)..."
    (total_value, actual) = ps9.bruteForceAdvisor(shortenedSubjects, 7)
    if expected != actual and sumValues(expected) > sumValues(actual):
        failed = True
        print("ERROR in bruteForceAdvisor: For bruteForceAdvisor(shortenedSubjects, 7), expected " + str(expected) + " but was actually " + str(actual))
    if failed:
        raise Exception