statistics/src/test/java/cz/xelfi/quoridor/statistics/EloTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 14 Sep 2010 08:56:13 +0200
changeset 264 d60370059c3c
parent 202 3e75ccd5cdac
permissions -rw-r--r--
Changing headers to GPLv3
jaroslav@178
     1
/*
jaroslav@264
     2
 * Quoridor server and related libraries
jaroslav@264
     3
 * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@178
     4
 *
jaroslav@264
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@264
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@264
     7
 * the Free Software Foundation, either version 3 of the License.
jaroslav@178
     8
 *
jaroslav@264
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@264
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@264
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@264
    12
 * GNU General Public License for more details.
jaroslav@178
    13
 *
jaroslav@264
    14
 * You should have received a copy of the GNU General Public License
jaroslav@264
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@264
    16
 * If not, see http://www.gnu.org/licenses/.
jaroslav@178
    17
 */
jaroslav@178
    18
jaroslav@178
    19
package cz.xelfi.quoridor.statistics;
jaroslav@178
    20
jaroslav@178
    21
import org.junit.Test;
jaroslav@178
    22
import static org.junit.Assert.*;
jaroslav@178
    23
jaroslav@178
    24
/**
jaroslav@178
    25
 *
jaroslav@178
    26
 * @author Martin Rexa
jaroslav@178
    27
 */
jaroslav@178
    28
public class EloTest extends Object {
jaroslav@178
    29
jaroslav@178
    30
    public EloTest() throws Exception {
jaroslav@178
    31
    }
jaroslav@178
    32
jaroslav@178
    33
    @Test public void testEloList() throws Exception {
jaroslav@178
    34
        EloList eloList = new EloList();
jaroslav@178
    35
        eloList.putResult("p1", "p2");
jaroslav@178
    36
        assertFalse("empty list", eloList.getFinalList().isEmpty());
jaroslav@178
    37
        eloList.putResult("p3", "p4");
jaroslav@178
    38
        assertTrue("wrong list", eloList.getFinalList().get(0).getElo().equals(eloList.getFinalList().get(1).getElo()));
jaroslav@178
    39
        eloList.putResult("p2", "p1");
jaroslav@178
    40
        eloList.putResult("p2", "p1");
jaroslav@178
    41
        eloList.putResult("p2", "p1");
jaroslav@178
    42
        assertTrue("wrong list", eloList.getFinalList().get(0).player.equals("p2"));
jaroslav@178
    43
    }
jaroslav@178
    44
martin@202
    45
    @Test public void testEloResults() throws Exception {
martin@202
    46
        EloList eloList = new EloList();
martin@202
    47
        setTestPlayer(eloList, "p1", 1335, 120);
martin@202
    48
        setTestPlayer(eloList, "p2", 1380, 20);
martin@202
    49
        setTestPlayer(eloList, "p3", 1264, 110);
martin@202
    50
        setTestPlayer(eloList, "p4", 1281, 140);
martin@202
    51
        printList(eloList);
martin@202
    52
//        eloList.putResult("p1", "p2");
martin@202
    53
        eloList.putResult("p1", "p3");
martin@202
    54
        eloList.putResult("p1", "p4");
martin@202
    55
        printList(eloList);
martin@202
    56
        eloList.putResult("p2", "p1");
martin@202
    57
        eloList.putResult("p1", "p2");
martin@202
    58
        printList(eloList);
martin@202
    59
    }
martin@202
    60
martin@202
    61
    private void setTestPlayer(EloList eloList, String player, double elo, int games){
martin@202
    62
        eloList.players.put(player, elo);
martin@202
    63
        eloList.playerGames.put(player, games);
martin@202
    64
    }
martin@202
    65
martin@202
    66
    private void printList(EloList eloList){
martin@202
    67
        for(EloEntry entry: eloList.getFinalList()){
martin@202
    68
            System.out.println(entry);
martin@202
    69
        }
martin@202
    70
        System.out.println("------------");
martin@202
    71
    }
martin@202
    72
jaroslav@178
    73
}