def test_greedyAdvisor(): subjects = {} subjects['6.00'] = (10, 1) subjects['6.01'] = (8, 4) subjects['6.02'] = (5, 8) subjects['6.03'] = (1, 1) subjects['6.04'] = (5, 15) newsubjects = subjects.copy() dontmutate = subjects.copy() expected = {} expected['6.04'] = (5, 15) expected['6.00'] = (10, 1) expected['6.03'] = (1, 1) failed = False print print "subjects = " + str(subjects) print "Trying greedyAdvisor(subjects, 17, cmpSum)..." try: actual = ps9.greedyAdvisor(subjects, 17, cmpSum) except Exception, e: failed = True print( "ERROR in greedyAdvisor (probably does not handle a new comparator) " + str(e))
def test_greedyAdvisor(): subjects = {} subjects['6.00'] = (10, 1) subjects['6.01'] = (8, 4) subjects['6.02'] = (5, 8) subjects['6.03'] = (1, 1) subjects['6.04'] = (5, 15) newsubjects = subjects.copy() dontmutate = subjects.copy() expected = {} expected['6.04'] = (5, 15) expected['6.00'] = (10, 1) expected['6.03'] = (1, 1) failed = False print print "subjects = " + str(subjects) print "Trying greedyAdvisor(subjects, 17, cmpSum)..." try: actual = ps9.greedyAdvisor(subjects, 17, keySum) except Exception,e: failed = True print("ERROR in greedyAdvisor (probably does not handle a new comparator) " + str(e))
print("ERROR in greedyAdvisor (probably does not handle a new comparator) " + str(e)) else: if expected != actual: failed = True print("ERROR in greedyAdvisor: For greedyAdvisor(subjects, 17, cmpSum), expected " + str(expected) + " but was actually " + str(actual)) if dontmutate != subjects: failed = True print("ERROR in greedyAdvisor: subjects was mutated") expected = {} expected['6.02'] = (5, 8) subjects = newsubjects.copy() print "Trying greedyAdvisor(subjects, 8, cmpSum)..." try: actual = ps9.greedyAdvisor(subjects, 8, keySum) except Exception,e: failed = True print("ERROR in greedyAdvisor (probably does not handle a new comparator) " + str(e)) else: if expected != actual: failed = True print("ERROR in greedyAdvisor: For greedyAdvisor(subjects, 8, cmpSum), expected " + str(expected) + " but was actually " + str(actual)) # Small Catalog handout tests print smallCatalog = {'6.00': (16, 8), '1.00': (7, 7), '15.01': (9, 6), '6.01': (5, 3)} print "smallCatalog = " + str(smallCatalog) print "Trying greedyAdvisor(smallCatalog, 15, cmpValue)..." expected = {'6.00': (16, 8), '15.01': (9, 6)} actual = ps9.greedyAdvisor(smallCatalog.copy(), 15, ps9.keyValue)
print("ERROR in greedyAdvisor (probably does not handle a new comparator) " + str(e)) else: if expected != actual: failed = True print("ERROR in greedyAdvisor: For greedyAdvisor(subjects, 17, cmpSum), expected " + str(expected) + " but was actually " + str(actual)) if dontmutate != subjects: failed = True print("ERROR in greedyAdvisor: subjects was mutated") expected = {} expected['6.02'] = (5, 8) subjects = newsubjects.copy() print "Trying greedyAdvisor(subjects, 8, cmpSum)..." try: actual = ps9.greedyAdvisor(subjects, 8, cmpSum) except Exception,e: failed = True print("ERROR in greedyAdvisor (probably does not handle a new comparator) " + str(e)) else: if expected != actual: failed = True print("ERROR in greedyAdvisor: For greedyAdvisor(subjects, 8, cmpSum), expected " + str(expected) + " but was actually " + str(actual)) # Small Catalog handout tests print smallCatalog = {'6.00': (16, 8), '1.00': (7, 7), '15.01': (9, 6), '6.01': (5, 3)} print "smallCatalog = " + str(smallCatalog) print "Trying greedyAdvisor(smallCatalog, 15, cmpValue)..." expected = {'6.00': (16, 8), '15.01': (9, 6)} actual = ps9.greedyAdvisor(smallCatalog.copy(), 15, cmpValue)
def test_greedyAdvisor(): subjects = {} subjects['6.00'] = (10, 1) subjects['6.01'] = (8, 4) subjects['6.02'] = (5, 8) subjects['6.03'] = (1, 1) subjects['6.04'] = (5, 15) newsubjects = subjects.copy() dontmutate = subjects.copy() expected = {} expected['6.04'] = (5, 15) expected['6.00'] = (10, 1) expected['6.03'] = (1, 1) failed = False print print("subjects = " + str(subjects)) print("Trying greedyAdvisor(subjects, 17, cmpSum)...") try: actual = ps9.greedyAdvisor(subjects, 17, cmpSum) except Exception as e: failed = True print( "ERROR in greedyAdvisor (probably does not handle a new comparator) " + str(e)) else: if expected != actual: failed = True print( "ERROR in greedyAdvisor: For greedyAdvisor(subjects, 17, cmpSum), expected " + str(expected) + " but was actually " + str(actual)) if dontmutate != subjects: failed = True print("ERROR in greedyAdvisor: subjects was mutated") expected = {} expected['6.02'] = (5, 8) subjects = newsubjects.copy() print("Trying greedyAdvisor(subjects, 8, cmpSum)...") try: actual = ps9.greedyAdvisor(subjects, 8, cmpSum) except Exception as e: failed = True print( "ERROR in greedyAdvisor (probably does not handle a new comparator) " + str(e)) else: if expected != actual: failed = True print( "ERROR in greedyAdvisor: For greedyAdvisor(subjects, 8, cmpSum), expected " + str(expected) + " but was actually " + str(actual)) # Small Catalog handout tests print smallCatalog = { '6.00': (16, 8), '1.00': (7, 7), '15.01': (9, 6), '6.01': (5, 3) } print("smallCatalog = " + str(smallCatalog)) print("Trying greedyAdvisor(smallCatalog, 15, cmpValue)...") expected = {'6.00': (16, 8), '15.01': (9, 6)} actual = ps9.greedyAdvisor(smallCatalog.copy(), 15, cmpValue) if expected != actual: failed = True print( "ERROR in greedyAdvisor: For greedyAdvisor(smallCatalog, 15, ps9.cmpValue), expected " + str(expected) + " but was actually " + str(actual)) expected = {'6.01': (5, 3), '15.01': (9, 6)} print("Trying greedyAdvisor(smallCatalog, 15, cmpWork)...") actual = ps9.greedyAdvisor(smallCatalog.copy(), 15, cmpWork) if expected != actual: failed = True print( "ERROR in greedyAdvisor: For greedyAdvisor(smallCatalog, 15, ps9.cmpWork), expected " + str(expected) + " but was actually " + str(actual)) expected = {'6.00': (16, 8), '6.01': (5, 3)} print("Trying greedyAdvisor(smallCatalog, 15, cmpRatio)...") actual = ps9.greedyAdvisor(smallCatalog.copy(), 15, cmpRatio) if expected != actual: failed = True print( "ERROR in greedyAdvisor: For greedyAdvisor(smallCatalog, 15, ps9.cmpRatio), expected " + str(expected) + " but was actually " + str(actual)) if failed: raise Exception