def testGoals(self): player = Player("foo") opponent = Player("bar") bulkAppend(player, 5, opponent, 5, 0, 1002) sut = Goals() result = sut.getFact(player, player.games[0], None) self.assertIsNone(result) result = sut.getFact(player, player.games[1], None) self.assertEqual(result, "That game featured foo's 10th goal.") result = sut.getFact(player, player.games[10 - 1], None) self.assertEqual(result, "That game featured foo's 50th goal.") result = sut.getFact(player, player.games[12], None) self.assertIsNone(result) result = sut.getFact(player, player.games[100 - 1], None) self.assertEqual(result, "That game featured foo's 500th goal.") result = sut.getFact(player, player.games[110 - 1], None) self.assertIsNone(result) result = sut.getFact(player, player.games[700 - 1], None) self.assertIsNone(result) result = sut.getFact(player, player.games[770 - 1], None) self.assertIsNone(result) result = sut.getFact(player, player.games[1000 - 1], None) self.assertEqual(result, "That game featured foo's 5000th goal.") result = sut.getFact(player, player.games[1001], None) self.assertIsNone(result)
def testGames(self): player = Player("foo") opponent = Player("bar") bulkAppend(player, 6, opponent, 4, 0, 1002) sut = Games() result = sut.getFact(player, player.games[0], None) self.assertIsNone(result) result = sut.getFact(player, player.games[1], None) self.assertIsNone(result) result = sut.getFact(player, player.games[10 - 1], None) self.assertEqual(result, "That was foo's 10th game.") result = sut.getFact(player, player.games[12], None) self.assertIsNone(result) result = sut.getFact(player, player.games[100 - 1], None) self.assertEqual(result, "That was foo's 100th game.") result = sut.getFact(player, player.games[110 - 1], None) self.assertIsNone(result) result = sut.getFact(player, player.games[700 - 1], None) self.assertEqual(result, "That was foo's 700th game.") result = sut.getFact(player, player.games[770 - 1], None) self.assertIsNone(result) result = sut.getFact(player, player.games[1000 - 1], None) self.assertEqual(result, "That was foo's 1000th game.") result = sut.getFact(player, player.games[1001], None) self.assertIsNone(result)
def test(self): sut = Unstable() player = Player("foo") opponent = Player("bar") game = addGame(player, 5, opponent, 5, 0, -5) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result) game = addGame(player, 10, opponent, 0, 0, -5) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result) game = addGame(player, 0, opponent, 10, 1, 5) result = sut.applies(player, game, opponent, None) self.assertTrue(result) result = sut.applies(opponent, game, player, None) self.assertTrue(result) game = addGame(player, 0, opponent, 10, 1, 5) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result)
def testOver50Lose(self): ach = AgainstTheOdds() player = Player("foo") player.elo = 0 opponent = Player("bar") opponent.elo = 50 game = addGame(player, 0, opponent, 10, 0, 50) result = ach.applies(player, game, opponent, None) self.assertFalse(result)
def testOver50_2(self): ach = AgainstTheOdds() player = Player("foo") player.elo = 0 opponent = Player("baz") opponent.elo = 50 game = addGame(opponent, 0, player, 10, 0, 10) result = ach.applies(player, game, opponent, None) self.assertTrue(result)
def testUnder100(self): ach = AgainstAllOdds() player = Player("foo") player.elo = 0 opponent = Player("bar") opponent.elo = 99 game = addGame(player, 10, opponent, 0, 0, -50) result = ach.applies(player, game, opponent, None) self.assertFalse(result)
def testOver100(self): ach = AgainstAllOdds() player = Player("foo") player.elo = 0 opponent = Player("bar") opponent.elo = 100 game = addGame(player, 10, opponent, 0, 0, -1) result = ach.applies(player, game, opponent, None) self.assertTrue(result)
def test(self): sut = NothingIfNotConsistent() player = Player("foo") opponent = Player("bar") for i in range(0, 4): game = addGame(player, 2, opponent, 8, i) result = sut.applies(player, game, opponent, None) self.assertFalse(result) game = addGame(player, 2, opponent, 8, 4) result = sut.applies(player, game, opponent, None) self.assertTrue(result)
def testWinsThenDraw(self): player = Player("foo") opponent = Player("bar") bulkAppend(player, 6, opponent, 4, 0, 10) player.games.append(Game(player.name, 5, opponent.name, 5, 10)) sut = Wins() result = sut.getFact(player, player.games[9], None) self.assertEqual(result, "That was foo's 10th win.") result = sut.getFact(player, player.games[10], None) self.assertIsNone(result)
def testGoalsThenNone(self): player = Player("foo") opponent = Player("bar") bulkAppend(player, 5, opponent, 5, 0, 10) player.games.append(Game(player.name, 0, opponent.name, 10, 10)) sut = Goals() result = sut.getFact(player, player.games[9], None) self.assertEqual(result, "That game featured foo's 50th goal.") result = sut.getFact(player, player.games[10], None) self.assertIsNone(result)
def test(self): sut = UpUpAndAway() player = Player("foo") opponent = Player("bar") self._prep(sut, player, opponent) game = addGame(player, 6, opponent, 4, 8, -1) result = sut.applies(player, game, opponent, None) self.assertTrue(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result)
def testUnder50(self): ach = AgainstTheOdds() player = Player("foo") player.elo = 0 opponent = Player("bar") opponent.elo = 49 game = Game(player.name, 10, opponent.name, 0, 0) game.skillChangeToBlue = -50 player.game(game) opponent.game(game) result = ach.applies(player, game, opponent, None) self.assertFalse(result)
def testGoalsFirst10(self): player = Player("foo") opponent = Player("bar") bulkAppend(player, 1, opponent, 9, 0, 11) sut = Goals() result = sut.getFact(player, player.games[8], None) self.assertIsNone(result) result = sut.getFact(player, player.games[9], None) self.assertEqual(result, "That game featured foo's 10th goal.") result = sut.getFact(player, player.games[10], None) self.assertIsNone(result)
def testOver50_2(self): ach = AgainstTheOdds() player = Player("foo") player.elo = 0 opponent = Player("baz") opponent.elo = 50 game = Game(opponent.name, 0, player.name, 10, 0) game.skillChangeToBlue = 10 player.game(game) opponent.game(game) result = ach.applies(player, game, opponent, None) self.assertTrue(result)
def test(self): sut = Dedication() player = Player("foo") opponent = Player("bar") timeBetweenGames = 60 * 60 * 24 * 59 for i in range(0, 7): game = addGame(player, 5, opponent, 5, i * timeBetweenGames) result = sut.applies(player, game, opponent, None) self.assertFalse(result) game = addGame(player, 5, opponent, 5, 7 * timeBetweenGames) result = sut.applies(player, game, opponent, None) self.assertTrue(result)
def testOver100(self): ach = AgainstAllOdds() player = Player("foo") player.elo = 0 opponent = Player("bar") opponent.elo = 100 game = Game(player.name, 10, opponent.name, 0, 0) game.skillChangeToBlue = -1 player.game(game) opponent.game(game) result = ach.applies(player, game, opponent, None) self.assertTrue(result)
def test(self): ladder = TableFootballLadder(self.getLadder("testLadder.txt")) player = Player("foo") opponent = Player("baz") game = addGame(opponent, 0, player, 10, 6000000003) ladder.games.append(game) sut = EarlyBird() result = sut.applies(player, game, opponent, ladder) self.assertTrue(result) result = sut.applies(opponent, game, player, ladder) self.assertFalse(result)
def test(self): player = Player('foo') player.achieve([FlawlessVictory().__class__], Game('foo', 4, 'red', 6, 1)) actual = sut.getPlayerAchievementsJson(player) self.assertEqual(len(actual), 25) self.assertEqual(len([a for a in actual if 'time' in a]), 1) self.assertIn('name', actual[0]) self.assertIn('description', actual[0]) self.assertIn('time', actual[0])
def test(self): ladder = TableFootballLadder(os.path.join(__location__, "testLadder.txt"), False) player = Player("foo") opponent = Player("baz") game = Game(opponent.name, 0, player.name, 10, 6000000003) ladder.addGame(game) sut = EarlyBird() result = sut.applies(player, game, opponent, ladder) self.assertTrue(result) result = sut.applies(opponent, game, player, ladder) self.assertFalse(result)
def test(self): sut = PokeMaster() player = Player("foo") opponent = Player("bar") game = addGame(player, 0, opponent, 10, 0) for i in range(0, 10): game = addGame(player, i, opponent, 10 - i, i) result = sut.applies(player, game, opponent, None) self.assertFalse(result) game = addGame(player, 10, opponent, 0, 10) result = sut.applies(player, game, opponent, None) self.assertTrue(result)
def testFirstGame(self): ladder = TableFootballLadder(os.path.join(__location__, "emptyLadder.txt"), False) player = Player("foo") opponent = Player("baz") game = addGame(opponent, 0, player, 10, 0) ladder.games.append(game) sut = EarlyBird() result = sut.applies(player, game, opponent, ladder) self.assertTrue(result) result = sut.applies(opponent, game, player, ladder) self.assertFalse(result)
def testInterrupted(self): sut = Consistency() player = Player("foo") opponent = Player("bar") for i in range(0, 4): game = addGame(player, 2, opponent, 8, i) result = sut.applies(player, game, opponent, None) self.assertFalse(result) game = addGame(player, 3, opponent, 7, 4) result = sut.applies(player, game, opponent, None) self.assertFalse(result) game = addGame(player, 2, opponent, 8, 5) result = sut.applies(player, game, opponent, None) self.assertFalse(result)
def testGamesAgainstSingleReport(self): player = Player("foo") opponent = Player("baz") bulkAppend(player, 6, opponent, 4, 0, 1002) sut = GamesAgainst() result = sut.getFact(player, player.games[10 - 1], opponent) self.assertEqual(result, "That was foo and baz's 10th encounter.") result = sut.getFact(opponent, player.games[10 - 1], player) self.assertIsNone(result) result = sut.getFact(opponent, player.games[700 - 1], player) self.assertEqual(result, "That was baz and foo's 700th encounter.") result = sut.getFact(player, player.games[700 - 1], opponent) self.assertIsNone(result)
def testDoubleDomination(self): sut = TheDominator() player = Player("foo") opponent = Player("bar") for i in range(0, 19): game = addGame(player, 10, opponent, 0, i, -1) result = sut.applies(player, game, opponent, None) if i != 9: self.assertFalse(result) game = addGame(player, 10, opponent, 0, 20, -1) result = sut.applies(player, game, opponent, None) self.assertTrue(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result)
def test(self): sut = Consistency() player = Player("foo") opponent = Player("bar") for i in range(0, 4): game = Game(player.name, 2, opponent.name, 8, i) player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertFalse(result) game = Game(player.name, 2, opponent.name, 8, 4) player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertTrue(result)
def test(self): sut = Dedication() player = Player("foo") opponent = Player("bar") timeBetweenGames = 60*60*24* 59 for i in range(0, 7): game = Game(player.name, 5, opponent.name, 5, i * timeBetweenGames) player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertFalse(result) game = Game(player.name, 5, opponent.name, 5, 7 * timeBetweenGames) player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertTrue(result)
def testGamesAgainst(self): player = self._create() opponent = Player("baz") bulkAppend(player, 6, opponent, 4, 5, 1002) sut = GamesAgainst() result = sut.getFact(player, player.games[0], opponent) self.assertIsNone(result) result = sut.getFact(player, player.games[1], opponent) self.assertIsNone(result) result = sut.getFact(player, player.games[10 + 4 - 1], opponent) self.assertEqual(result, "That was foo and baz's 10th encounter.") result = sut.getFact(player, player.games[12], opponent) self.assertIsNone(result) result = sut.getFact(player, player.games[100 + 4 - 1], opponent) self.assertEqual(result, "That was foo and baz's 100th encounter.") result = sut.getFact(player, player.games[110 + 4 - 1], opponent) self.assertIsNone(result) result = sut.getFact(player, player.games[700 + 4 - 1], opponent) self.assertEqual(result, "That was foo and baz's 700th encounter.") result = sut.getFact(player, player.games[770 + 4 - 1], opponent) self.assertIsNone(result) result = sut.getFact(player, player.games[1000 + 4 - 1], opponent) self.assertEqual(result, "That was foo and baz's 1000th encounter.") result = sut.getFact(player, player.games[1001], opponent) self.assertIsNone(result)
def testGoalsAgainst(self): player = self._create() opponent = Player("baz") bulkAppend(player, 5, opponent, 5, 5, 1002) sut = GoalsAgainst() result = sut.getFact(player, player.games[0], opponent) self.assertIsNone(result) result = sut.getFact(player, player.games[1 + 4], opponent) self.assertEqual(result, "That game featured foo's 10th goal against baz.") result = sut.getFact(player, player.games[10 + 4 - 1], opponent) self.assertEqual(result, "That game featured foo's 50th goal against baz.") result = sut.getFact(player, player.games[12], opponent) self.assertIsNone(result) result = sut.getFact(player, player.games[100 + 4 - 1], opponent) self.assertEqual(result, "That game featured foo's 500th goal against baz.") result = sut.getFact(player, player.games[110 + 4 - 1], opponent) self.assertIsNone(result) result = sut.getFact(player, player.games[700 + 4 - 1], opponent) self.assertIsNone(result) result = sut.getFact(player, player.games[770 + 4 - 1], opponent) self.assertIsNone(result) result = sut.getFact(player, player.games[1000 + 4 - 1], opponent) self.assertEqual(result, "That game featured foo's 5000th goal against baz.") result = sut.getFact(player, player.games[1001], opponent) self.assertIsNone(result)
def testSignificantGames(self): player = Player("foo") bulkAppend(player, 5, Player("bar"), 5, 5, 20) player.games[0].skillChangeToBlue = 2 player.games[1].skillChangeToBlue = -3 player.games[2].skillChangeToBlue = 4 player.games[3].skillChangeToBlue = -1 sut = SignificantGames() result = sut.getFact(player, player.games[0], None) self.assertEqual(result, "That was foo's 3rd most significant game.") result = sut.getFact(player, player.games[1], None) self.assertEqual(result, "That was foo's 2nd most significant game.") result = sut.getFact(player, player.games[2], None) self.assertEqual(result, "That was foo's most significant game.") result = sut.getFact(player, player.games[3], None) self.assertEqual(result, "That was foo's 4th most significant game.")
def testFirstGameSince(self): player = Player("foo") opponent = Player("bar") game = Game(player.name, 5, opponent.name, 5, 10) player.games.append(game) opponent.games.append(game) opponent.games.append(Game(opponent.name, 5, "baz", 5, 11)) retireTime = (60 * 60 * 24 * constants.DAYS_INACTIVE) game = Game(player.name, 5, opponent.name, 5, 11 + retireTime) player.games.append(game) opponent.games.append(game) sut = FirstGameSince() result = sut.getFact(player, player.games[-1], None) self.assertEqual( result, "That was foo's first game since retiring on 1970-02-12.") result = sut.getFact(opponent, opponent.games[-1], None) self.assertIsNone(result)
def testTwice(self): sut = Consistency() player = Player("foo") opponent = Player("bar") for i in range(0, 4): game = addGame(player, 2, opponent, 8, i) result = sut.applies(player, game, opponent, None) self.assertFalse(result) game = addGame(player, 2, opponent, 8, 4) result = sut.applies(player, game, opponent, None) self.assertTrue(result) for i in range(5, 9): game = addGame(player, 2, opponent, 8, i) result = sut.applies(player, game, opponent, None) self.assertFalse(result) game = addGame(player, 2, opponent, 8, 9) result = sut.applies(player, game, opponent, None) self.assertTrue(result)
def testInterrupted(self): sut = TheDominator() player = Player("foo") opponent = Player("bar") for i in range(0, 9): game = addGame(player, 10, opponent, 0, i, -1) result = sut.applies(player, game, opponent, None) self.assertFalse(result) baz = Player("baz") game = addGame(player, 10, baz, 0, 9, -1) result = sut.applies(player, game, baz, None) self.assertFalse(result) game = addGame(player, 0, opponent, 10, 10, -1) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result)
def testStreaks2nd(self): ladder = TableFootballLadder(self.getLadder("testStreak.txt")) streaky = ladder.players['streak'] bulkAppend(streaky, 6, Player('baz'), 4, 5000000012, 5) sut = Streaks() result = sut.getFact(streaky, streaky.games[-2], None) self.assertIsNone(result) result = sut.getFact(streaky, streaky.games[-1], None) self.assertEqual( result, "At 5 games, streak was on their 2nd longest winning streak.")
def testNonContiguous(self): sut = UpUpAndAway() player = Player("foo") opponent = Player("bar") for i in range(7): game = addGame(player, 6, opponent, 4, i, -1) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result) game = addGame(player, 4, opponent, 6, 8, 1) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result) game = addGame(player, 6, opponent, 4, 9, -1) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result)
def test(self): sut = Comrades() player = Player("foo") opponent = Player("bar") for i in range(0, 99): game = addGame(player, 5, opponent, 5, 0) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result) game = addGame(player, 5, opponent, 5, 0) result = sut.applies(player, game, opponent, None) self.assertTrue(result) result = sut.applies(opponent, game, player, None) self.assertTrue(result) game = addGame(player, 5, opponent, 5, 0) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result)
def testStreaks2nd(self): l = TableFootballLadder(os.path.join(__location__, "testStreak.txt"), False) streaky = l.players['streak'] bulkAppend(streaky, 6, Player('baz'), 4, 5000000012, 3) sut = Streaks() result = sut.getFact(streaky, streaky.games[-2], None) self.assertIsNone(result) result = sut.getFact(streaky, streaky.games[-1], None) self.assertEqual( result, "At 3 games, streak was on their 2nd longest winning streak.")
def test(self): sut = Comrades() player = Player("foo") opponent = Player("bar") for i in range(0, 99): game = Game(player.name, 5, opponent.name, 5, 0) player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result) game = Game(player.name, 5, opponent.name, 5, 0) player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertTrue(result) result = sut.applies(opponent, game, player, None) self.assertTrue(result) game = Game(player.name, 5, opponent.name, 5, 0) player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result)
def testInterrupted(self): sut = TheDominator() player = Player("foo") opponent = Player("bar") for i in range(0, 9): game = Game(player.name, 10, opponent.name, 0, i) game.skillChangeToBlue = -1 player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertFalse(result) baz = Player("baz") game = Game(player.name, 10, baz.name, 0, 9) game.skillChangeToBlue = -1 player.game(game) result = sut.applies(player, game, baz, None) self.assertFalse(result) game = Game(player.name, 0, opponent.name, 10, 10) game.skillChangeToBlue = -1 player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result)
def test(self): sut = PokeMaster() player = Player("foo") opponent = Player("bar") game = Game(player.name, 0, opponent.name, 10, 0) player.game(game) opponent.game(game) for i in range(0, 10): game = Game(player.name, i, opponent.name, 10 - i, i) player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertFalse(result) game = Game(player.name, 10, opponent.name, 0, 10) player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertTrue(result)
def test(self): sut = Unstable() player = Player("foo") opponent = Player("bar") game = Game(player.name, 5, opponent.name, 5, 0) game.skillChangeToBlue = -5 player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result) game = Game(player.name, 10, opponent.name, 0, 0) game.skillChangeToBlue = -5 player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result) game = Game(player.name, 0, "bar", 10, 1) game.skillChangeToBlue = 5 player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertTrue(result) result = sut.applies(opponent, game, player, None) self.assertTrue(result) game = Game(player.name, 0, "bar", 10, 1) game.skillChangeToBlue = 5 player.game(game) opponent.game(game) result = sut.applies(player, game, opponent, None) self.assertFalse(result) result = sut.applies(opponent, game, player, None) self.assertFalse(result)