Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT
# the functions to be tested: class Library: def __init__(self, fn): pass self.fn = fn self.shelf = shelve.open(fn) def add_Player(self, team): pass self.shelf[team] = team def add_Score(self, team): pass self.shelf[team.scores] = team def close(self): pass self.shelf.close() class Player: def __init__(self, team, scores): self.team, self.scores = team, scores def __eq__(self, other): if type(other) is type(self): return self.__dict__ == other.__dict__ return False def __ne__(self, other): return not self.__eq__(other)
class Players: def __init__(self, shelf, player, score_input, score): self.shelf = shelve.open('shelf_scores.shlf') self.player = player self.score_input = score_input self.score = score def add_player(self, shelf): while True: msg = 'Add a player: ' player = raw_input(msg).strip() if player: score = 0 while True: msg = 'Add a score for ' + player + ': ' score_input = raw_input(msg).strip() if score_input.isdigit(): if int(score_input) > int(score): print score_input, '>', score, ', new high score:', score_input shelf[player] = score_input score = score_input else: print score_input, '<', score, ', pass' else: print "Score empty or not recognized, exiting player", player break else: print 'No player, exiting' break Players.read_scores(self, shelf) def read_scores(self, shelf): for player in sorted(shelf.keys()): print 'Player', player, 'high score:', shelf[player] shelf.close() if __name__ == "__main__": shelf = shelve.open('shelf_scores.shlf') player = 'Anonymous' score_input = 0 score = 0 instance = Players(shelf, player, score_input, score) Players.add_player(instance, shelf) shelf.close()
# the unittest: class TestScores(unittest.TestCase): def setUp(self): self.game_fn = 'shelf_scores.shlf' self.team = players2.Library('Joe', 'Sally','Jim') self.scores = players2.Player(10, 20, 30) self.game = players2.Player(self.game_fn, self.team, self.scores) self.game.add_Player(self.team) self.game.add_Score(self.scores) def test_add_Player(self): observed = self.game.add_Player(self.team) self.assertEquals(observed, self.team) def test_add_Score(self): observed = self.game.add_Score(self.team) self.assertEquals(observed, self.team) def tearDown(self): self.game.close() if __name__ == "__main__": unittest.main()
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.