commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1306461 - in /commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo: ./ EloTestCase.java SimplePlayersRank.java
Date Wed, 28 Mar 2012 16:45:45 GMT
Author: simonetripodi
Date: Wed Mar 28 16:45:45 2012
New Revision: 1306461

URL: http://svn.apache.org/viewvc?rev=1306461&view=rev
Log:
added first ELO test implementation

Added:
    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/
    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/EloTestCase.java
  (with props)
    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/SimplePlayersRank.java
  (with props)

Added: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/EloTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/EloTestCase.java?rev=1306461&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/EloTestCase.java
(added)
+++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/EloTestCase.java
Wed Mar 28 16:45:45 2012
@@ -0,0 +1,91 @@
+package org.apache.commons.graph.elo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.commons.graph.elo.GameResult.WIN;
+
+import static org.apache.commons.graph.CommonsGraph.eloRate;
+import static org.apache.commons.graph.CommonsGraph.newDirectedMutableGraph;
+
+import org.apache.commons.graph.DirectedGraph;
+import org.apache.commons.graph.builder.AbstractGraphConnection;
+import org.junit.Test;
+
+/**
+ * Sample taken from <a href="http://www.teamliquid.net/forum/viewmessage.php?topic_id=253017">teamliquid</a>
+ */
+public final class EloTestCase
+{
+
+    @Test
+    public void performElo()
+    {
+        DirectedGraph<String, GameResult> tournament =
+        newDirectedMutableGraph( new AbstractGraphConnection<String, GameResult>()
+        {
+
+            @Override
+            public void connect()
+            {
+                String zenio = addVertex( "Zenio" );
+                String marineking = addVertex( "Marineking" );
+                String hongun = addVertex( "Hongun" );
+                String nestea = addVertex( "Nestea" );
+                String tester = addVertex( "Tester" );
+                String nada = addVertex( "Nada" );
+                String rainbow = addVertex( "Rainbow" );
+                String thewind = addVertex( "Thewind" );
+                String inka = addVertex( "Inka" );
+                String maka = addVertex( "Maka" );
+                String ensnare = addVertex( "Ensnare" );
+                String kyrix = addVertex( "Kyrix" );
+                String killer = addVertex( "Killer" );
+                String slayersboxer = addVertex( "Slayersboxer" );
+                String fruitdealer = addVertex( "Fruitdealer" );
+                String genius = addVertex( "Genius" );
+
+                // no draws
+                addEdge( WIN ).from( zenio ).to( marineking );
+                addEdge( WIN ).from( fruitdealer ).to( hongun );
+                addEdge( WIN ).from( genius ).to( nestea );
+                addEdge( WIN ).from( tester ).to( nada );
+                addEdge( WIN ).from( thewind ).to( rainbow );
+                addEdge( WIN ).from( maka ).to( inka );
+                addEdge( WIN ).from( kyrix ).to( ensnare );
+                addEdge( WIN ).from( slayersboxer ).to( killer );
+                addEdge( WIN ).from( marineking ).to( fruitdealer );
+                addEdge( WIN ).from( tester ).to( genius );
+                addEdge( WIN ).from( thewind ).to( maka );
+                addEdge( WIN ).from( kyrix ).to( slayersboxer );
+                addEdge( WIN ).from( marineking ).to( tester );
+                addEdge( WIN ).from( kyrix ).to( thewind );
+                addEdge( WIN ).from( kyrix ).to( marineking );
+            }
+
+        } );
+
+        PlayersRank<String> playersRank = new SimplePlayersRank();
+
+        eloRate( tournament ).werePlayersArRankedIn( playersRank ).withKFactor( 80 );
+
+        System.out.println( playersRank );
+    }
+
+}

Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/EloTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/EloTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/EloTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/SimplePlayersRank.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/SimplePlayersRank.java?rev=1306461&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/SimplePlayersRank.java
(added)
+++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/SimplePlayersRank.java
Wed Mar 28 16:45:45 2012
@@ -0,0 +1,51 @@
+package org.apache.commons.graph.elo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+import java.util.TreeMap;
+
+final class SimplePlayersRank
+    implements PlayersRank<String>
+{
+
+    private final Map<String, Double> ranks = new TreeMap<String, Double>();
+
+    public Double getRanking( String player )
+    {
+        if ( !ranks.containsKey( player ) )
+        {
+            return 0D;
+        }
+        return ranks.get( player );
+    }
+
+    public void updateRanking( String player, Double ranking )
+    {
+        ranks.put( player, ranking );
+    }
+
+    @Override
+    public String toString()
+    {
+        return ranks.toString();
+    }
+
+}

Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/SimplePlayersRank.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/SimplePlayersRank.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/elo/SimplePlayersRank.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message