def test_nonLetter_should_raiseException(self): with self.assertRaises(Exception): self.game = Game("non Letter $ign")
def test_capitalisedInput_shuold_Decapitalise(self): self.game= Game("I aM lOoDaChA") self.assertEqual(self.game.solution, "i am loodacha")
def setUp(self): self.game = Game("solution")
def test_GuessingLetter_should_removeLetterFromAvailableLetters(self): self.game = Game("really anything") self.game.guess = "u" self.assertNotIn("u", self.game.availableLetters)
def test_falseInput_shuold_reduceScore(self): self.game = Game("anything") score = self.game.score self.game.guess = "z" self.assertEqual(self.game.score, score-1)
def test_lowScore_should_loseGame(self): self.game = Game("anything") self.game.score = 0 self.assertFalse(self.game.victory)
def test_spacesinput_should_faltyAndNonyGuessedList(self): self.game = Game("very many spaces are in here") self.assertEqual(5, (self.game.guessed).count(None))
def make_iteration(self, iteration, playerStart = 2, playerEnd = 5): iteration_result = { } localPath = self.experimentPath + '/' + str(iteration) if not os.path.exists(localPath): os.makedirs(localPath) self.tf.logging.set_verbosity(self.tf.logging.ERROR) fileResult = self.experimentPath + '/' + str(iteration) + '/result.csv' fileDone = self.experimentPath + '/' + str(iteration) + '/done.csv' fileFail = self.experimentPath + '/' + str(iteration) + '/fail.csv' fails = 0 games = 0 max_pts = 0 min_pts = 200 sum_turns = 0 sum_points = 0 players = 0 finished = 0 with open(fileResult, 'w') as fr, open(fileDone, 'w') as fd, open(fileFail, 'w') as ff: predictor = self.predictor.getPredictor() for pl in range(playerStart, playerEnd): for rep in range(self.games): games += 1 lineTck = '' line = '' failLine = '' myGame = Game() if not os.path.exists('reports/'): os.makedirs('reports') os.makedirs('reports/' + str(myGame.gameId)) try: myGame.prepareGame(pl, predictor) myGame.execute() myGame.printResult() line += str(myGame.gameId) + ';' with open('reports/' + str(myGame.gameId) + '/raport.txt', 'w') as report: finished += 1 sum_turns += myGame.turn for player in myGame.players: if player.Points > max_pts: max_pts = player.Points if player.Points < min_pts: min_pts = player.Points sum_points += player.Points players += 1 line += str(player.Points) + ';' report.write(str(player.PlayerName) + ' ' + str(player.Points)) failLine += str(player.TicketFail) + ';' lineTck += str(player.TicketDone) + ';' except: e = sys.exc_info()[0] print(e) fails += 1 line += 'fail ' + str(len(myGame.players)) + ' in turn: ' + str(myGame.turn) failLine += 'fail ' + str(len(myGame.players)) + ' in turn: ' + str(myGame.turn) lineTck += 'fail ' + str(len(myGame.players)) + ' in turn: ' + str(myGame.turn) sum_turns += myGame.turn line += '\n' lineTck += '\n' failLine += '\n' fr.write(line) fd.write(lineTck) ff.write(failLine) fr.flush() fd.flush() ff.flush() del myGame iteration_result['games'] = games iteration_result['fails'] = fails if finished == 0: min = '-' max = '-' iteration_result['max'] = max_pts iteration_result['min'] = min_pts iteration_result['players'] = players iteration_result['finished'] = finished if players == 0: iteration_result['avg'] = '-' else: iteration_result['avg'] = sum_points / players iteration_result['turns'] = sum_turns / games return iteration_result