-- lobby/stats.lua
TestLobbyStats = {}
    function TestLobbyStats:setUp()
        lobby.savedata = {}
        lobby.savedata.stats = {}
    end

    function TestLobbyStats:testSoloVisit1()
        lobby.update_stats('0', 'solo')
        lu.assertNotNil(lobby.savedata)
        lu.assertNotNil(lobby.savedata.stats)
        stats = lobby.savedata.stats['0']
        lu.assertNotNil(stats)
        lu.assertEquals(stats.solo_play, 1)
        lu.assertEquals(stats.multi_play, 0)
        lu.assertEquals(stats.winner_traitor, 0)
        lu.assertEquals(stats.winner_team, 0)
        lu.assertEquals(stats.max_players, 0)
        lu.assertEquals(stats.player_count, 0)
    end

    function TestLobbyStats:testSoloVisitN()
        lobby.update_stats('1', 'solo')
        lobby.update_stats('1', 'solo')
        lobby.update_stats('1', 'solo')
        lobby.update_stats('1', 'solo')
        lobby.update_stats('1', 'solo')
        lobby.update_stats('1', 'solo')
        stats = lobby.savedata.stats['1']
        lu.assertNotNil(stats)
        lu.assertEquals(stats.solo_play, 6)
        lu.assertEquals(stats.multi_play, 0)
        lu.assertEquals(stats.winner_traitor, 0)
        lu.assertEquals(stats.winner_team, 0)
        lu.assertEquals(stats.max_players, 0)
        lu.assertEquals(stats.player_count, 0)
    end

    function TestLobbyStats:testMultiVisit1()
        lobby.update_stats('0', 'player', '', 0)
        lobby.update_stats('5', 'player', '', 5)
        lobby.update_stats('42', 'player', '', 42)
        stats = lobby.savedata.stats['0']
        lu.assertNotNil(stats)
        lu.assertEquals(stats.solo_play, 0)
        lu.assertEquals(stats.multi_play, 1)
        lu.assertEquals(stats.winner_traitor, 0)
        lu.assertEquals(stats.winner_team, 0)
        lu.assertEquals(stats.max_players, 0)
        lu.assertEquals(stats.player_count, 0)
        stats = lobby.savedata.stats['5']
        lu.assertNotNil(stats)
        lu.assertEquals(stats.solo_play, 0)
        lu.assertEquals(stats.multi_play, 1)
        lu.assertEquals(stats.winner_traitor, 0)
        lu.assertEquals(stats.winner_team, 0)
        lu.assertEquals(stats.max_players, 5)
        lu.assertEquals(stats.player_count, 5)
        stats = lobby.savedata.stats['42']
        lu.assertNotNil(stats)
        lu.assertEquals(stats.solo_play, 0)
        lu.assertEquals(stats.multi_play, 1)
        lu.assertEquals(stats.winner_traitor, 0)
        lu.assertEquals(stats.winner_team, 0)
        lu.assertEquals(stats.max_players, 42)
        lu.assertEquals(stats.player_count, 42)
    end

    function TestLobbyStats:testMultiVisitN()
        lobby.update_stats('N', 'player', '', 3)
        lobby.update_stats('N', 'player', '', 3)
        lobby.update_stats('N', 'player', '', 3)
        lobby.update_stats('N', 'player', '', 3)
        lobby.update_stats('N', 'player', '', 3)
        lobby.update_stats('N', 'player', '', 3)
        lobby.update_stats('N', 'player', '', 3)
        stats = lobby.savedata.stats['N']
        lu.assertNotNil(stats)
        lu.assertEquals(stats.multi_play, 7)
    end

    function TestLobbyStats:testTeamPlays()
        -- stats #1
        lobby.update_stats('2', 'player', '', 4)
        lobby.update_stats('2', '', 'traitor')
        stats = lobby.savedata.stats['2']
        lu.assertEquals(stats.solo_play, 0)
        lu.assertEquals(stats.multi_play, 1)
        lu.assertEquals(stats.winner_traitor, 1)
        lu.assertEquals(stats.winner_team, 0)
        lu.assertEquals(stats.max_players, 4)
        lu.assertEquals(stats.player_count, 4)

        -- stats #2
        lobby.update_stats('2', 'player', '', 2)
        lobby.update_stats('2', '', 'team')
        lu.assertEquals(stats.solo_play, 0)
        lu.assertEquals(stats.multi_play, 2)
        lu.assertEquals(stats.winner_traitor, 1)
        lu.assertEquals(stats.winner_team, 1)
        lu.assertEquals(stats.max_players, 4)
        lu.assertEquals(stats.player_count, 3)

        -- stats #3
        lobby.update_stats('2', 'player', '', 3)
        lobby.update_stats('2', '', 'traitor')
        lu.assertEquals(stats.solo_play, 0)
        lu.assertEquals(stats.multi_play, 3)
        lu.assertEquals(stats.winner_traitor, 2)
        lu.assertEquals(stats.winner_team, 1)
        lu.assertEquals(stats.max_players, 4)
        lu.assertEquals(stats.player_count, 3)

        -- stats #4
        lobby.update_stats('2', 'player', '', 7)
        lobby.update_stats('2', '', 'team')
        lu.assertEquals(stats.solo_play, 0)
        lu.assertEquals(stats.multi_play, 4)
        lu.assertEquals(stats.winner_traitor, 2)
        lu.assertEquals(stats.winner_team, 2)
        lu.assertEquals(stats.max_players, 7)
        lu.assertEquals(stats.player_count, 4)
    end

    -- Test for mixed plays, ignoring solo plays completely
    -- (i.e., player_count _only_ averages team plays)
    function TestLobbyStats:testMixedPlays()
        lobby.update_stats('3', 'player', '', 4)
        lobby.update_stats('3', '', 'team')
        lobby.update_stats('3', 'player', '', 4)
        lobby.update_stats('3', '', 'team')
        lobby.update_stats('3', 'player', '', 4)
        lobby.update_stats('3', '', 'team')
        lobby.update_stats('3', 'player', '', 4)
        lobby.update_stats('3', '', 'traitor')
        lobby.update_stats('3', 'solo')
        lobby.update_stats('3', 'solo')
        lobby.update_stats('3', 'solo')
        stats = lobby.savedata.stats['3']
        lu.assertEquals(stats.solo_play, 3)
        lu.assertEquals(stats.multi_play, 4)
        lu.assertEquals(stats.winner_traitor, 1)
        lu.assertEquals(stats.winner_team, 3)
        lu.assertEquals(stats.max_players, 4)
        lu.assertEquals(stats.player_count, 4) -- 4 team plays x 4 players / 4 rounds
    end

--[[ TestLobbyStats ]]--

