def test_11(self): bbstats = self.database() result = quiz.select( bbstats, ['player', 'year', 'salary'], filters= [('=', ['year'], 2013), ('=', ['team'], 'BOS'), ('!=', ['year'], ['salary']) # This last one is to make sure your code is general enough, # though admittedly it doesn't make too much sense w.r.t. the # English description for this query! ], order_by=('salary', 'desc')) self.assertTrue(len(result) >= 10) self.assertEqual( result[:10], [['Peavy, Jake', 2013, 16157271], ['Lackey, John', 2013, 15950000], ['Ortiz, David', 2013, 14500000], ['Dempster, Ryan', 2013, 13250000], ['Victorino, Shane', 2013, 13000000], ['Lester, Jon', 2013, 11625000], ['Pedroia, Dustin', 2013, 10250000], ['Drew, Stephen', 2013, 9500000], ['Ellsbury, Jacoby', 2013, 9000000], ['Hanrahan, Joel', 2013, 7040000]])
def test_14(self): bbstats = self.database() result = quiz.select(bbstats, ['player', 'year', 'team', 'SB', 'CS'], filters=[('>=', ['SB'], 40), ('<=', ['CS'], 5)], order_by=('SB', 'desc')) self.assertEqual(result, [['Ellsbury, Jacoby', 2013, 'BOS', 52, 4], ['Trout, Mike', 2012, 'LAA', 49, 5], ['Cabrera, Everth', 2012, 'SDN', 44, 4]])
def test_13(self): bbstats = self.database() result = quiz.select(bbstats, ['year', 'average'], filters=[('=', ['player'], 'Ortiz, David')], order_by=('year', 'asc')) self.assertEqual( result, [[2010, 0.27], [2011, 0.309], [2012, 0.318], [2013, 0.309], [2014, 0.263], [2015, 0.273], [2016, 0.315]])
def test_10(self): bbstats = self.database() result = quiz.select(bbstats, ['player', 'year', 'team']) self.assertTrue(len(result) >= 5) self.assertEqual( result[:5], [['Laird, Gerald', 2010, 'DET'], ['Rzepczynski, Marc', 2010, 'TOR'], ['Brown, Corey', 2013, 'WAS'], ['Canzler, Russ', 2011, 'TBA'], ['Thole, Josh', 2015, 'TOR']])
def test_09(self): db = [['state', 'capital', 'population'], ['Massachusetts', 'Boston', 6547629], ['California', 'Sacramento', 37253956], ['New York', 'Albany', 19378102]] result = quiz.select(db, ['state', 'capital'], filters=[('>', ['population'], 10000000)]) self.assertEqual( result, [['California', 'Sacramento'], ['New York', 'Albany']])
def test_12(self): bbstats = self.database() result = quiz.select( bbstats, ['player', 'year', 'team', 'average'], filters= [('>', ['AB'], 100), ('=', 'AL', ['league']), ('!=', 13, 16) # This last one is to make sure your code is general enough, # though admittedly it doesn't make too much sense w.r.t. the # English description for this query! ], order_by=('average', 'desc')) self.assertTrue(len(result) >= 14) expect = [['Hamilton, Josh', 2010, 'TEX', 0.359], ['Cabrera, Miguel', 2013, 'DET', 0.348], ['Morneau, Justin', 2010, 'MIN', 0.345], ['Cabrera, Miguel', 2011, 'DET', 0.344], ['Altuve, Jose', 2014, 'HOU', 0.341], ['Young, Michael', 2011, 'TEX', 0.338], ['Cabrera, Miguel', 2015, 'DET', 0.338], ['Gonzalez, Adrian', 2011, 'BOS', 0.338], ['Altuve, Jose', 2016, 'HOU', 0.338], ['Martinez, Victor', 2014, 'DET', 0.335], ['Perez, Salvador', 2011, 'KCA', 0.331], ['Martinez, Victor', 2011, 'DET', 0.33], ['Iglesias, Jose', 2013, 'BOS', 0.33], ['Cabrera, Miguel', 2012, 'DET', 0.33]] # Note: 15th player has lower average, so top 14 is unambiguous # ['De Aza, Alejandro', 2011, 'CHA', 0.329] # Allow any valid sort ordering on field 3 (average). Only check top 14, since there # may be other players with 0.329 average swapping in for De Aza. result = result[:14] for r in expect: self.assertIn(r, result) for i in range(len(expect)): self.assertEqual(expect[i][3], result[i][3])