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