/*
 * Licensed 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.
 */

package org.autobet.ai;

import org.junit.Test;

import static org.autobet.ai.TeamRaterStatsCollector.GameResult.DRAW;
import static org.autobet.ai.TeamRaterStatsCollector.GameResult.LOSE;
import static org.autobet.ai.TeamRaterStatsCollector.GameResult.WIN;
import static org.junit.Assert.assertEquals;

public class TeamRatersStatsApproximationTest
{
    @Test
    public void test()
    {
        TeamRaterStatsCollector.TeamRaterStats.Builder stats = TeamRaterStatsCollector.TeamRaterStats.builder();
        stats.incrementHome(-2, LOSE);
        stats.incrementHome(-2, LOSE);
        stats.incrementHome(-2, LOSE);
        stats.incrementHome(-2, LOSE);
        stats.incrementHome(-2, DRAW);
        stats.incrementHome(-2, DRAW);
        stats.incrementHome(-2, DRAW);

        stats.incrementHome(-1, LOSE);
        stats.incrementHome(-1, LOSE);
        stats.incrementHome(-1, LOSE);
        stats.incrementHome(-1, DRAW);
        stats.incrementHome(-1, DRAW);
        stats.incrementHome(-1, WIN);

        stats.incrementHome(0, LOSE);
        stats.incrementHome(0, LOSE);
        stats.incrementHome(0, DRAW);
        stats.incrementHome(0, DRAW);
        stats.incrementHome(0, DRAW);
        stats.incrementHome(0, WIN);
        stats.incrementHome(0, WIN);

        stats.incrementHome(1, LOSE);
        stats.incrementHome(1, DRAW);
        stats.incrementHome(1, DRAW);
        stats.incrementHome(1, WIN);
        stats.incrementHome(1, WIN);
        stats.incrementHome(1, WIN);

        stats.incrementHome(2, DRAW);
        stats.incrementHome(2, DRAW);
        stats.incrementHome(2, DRAW);
        stats.incrementHome(2, WIN);
        stats.incrementHome(2, WIN);
        stats.incrementHome(2, WIN);
        stats.incrementHome(2, WIN);

        TeamRatersStatsApproximation approximation = new TeamRatersStatsApproximation(stats.build());

        assertEquals(approximation.getHomeDrawChances(-2), 0.4, 0.01);
        assertEquals(approximation.getHomeLoseChances(-2), 0.6, 0.01);
        assertEquals(approximation.getHomeWinChances(-2), 0, 0.01);

        assertEquals(approximation.getHomeDrawChances(-1), 0.4, 0.01);
        assertEquals(approximation.getHomeLoseChances(-1), 0.45, 0.01);
        assertEquals(approximation.getHomeWinChances(-1), 0.15, 0.01);

        assertEquals(approximation.getHomeDrawChances(0), 0.39, 0.01);
        assertEquals(approximation.getHomeLoseChances(0), 0.30, 0.01);
        assertEquals(approximation.getHomeWinChances(0), 0.30, 0.01);

        assertEquals(approximation.getHomeDrawChances(1), 0.39, 0.01);
        assertEquals(approximation.getHomeLoseChances(1), 0.16, 0.01);
        assertEquals(approximation.getHomeWinChances(1), 0.45, 0.01);

        assertEquals(approximation.getHomeDrawChances(2), 0.39, 0.01);
        assertEquals(approximation.getHomeLoseChances(2), 0, 0.01);
        assertEquals(approximation.getHomeWinChances(2), 0.6, 0.01);
    }
}

@@ -1078,264 +1078,63 @@
 ats.
-incrementHome(-2, LOSE);%0A        stats.incrementHome(-2, LOSE);%0A        stats.incrementHome(-2, LOSE);%0A        stats.incrementHome(-2, LOSE);%0A        stats.incrementHome(-2, DRAW);%0A        stats.incrementHome(-2, DRAW);%0A        stats.incrementHome(-2, DRAW
+addHome(-2, LOSE, 4);%0A        stats.addHome(-2, DRAW, 3
 );%0A%0A
@@ -1143,33 +1143,27 @@
       stats.
-increment
+add
 Home(-1, LOS
@@ -1167,164 +1167,47 @@
 LOSE
-);%0A        stats.incrementHome(-1, LOSE);%0A        stats.incrementHome(-1, LOSE);%0A        stats.incrementHome(-1, DRAW);%0A        stats.incrementHome(-1, DRAW
+, 3);%0A        stats.addHome(-1, DRAW, 2
 );%0A 
@@ -1254,33 +1254,27 @@
       stats.
-increment
+add
 Home(0, LOSE
@@ -1277,46 +1277,11 @@
 LOSE
-);%0A        stats.incrementHome(0, LOSE
+, 2
 );%0A 
@@ -1289,33 +1289,27 @@
       stats.
-increment
+add
 Home(0, DRAW
@@ -1312,426 +1312,157 @@
 DRAW
-);%0A        stats.incrementHome(0, DRAW);%0A        stats.incrementHome(0, DRAW);%0A        stats.incrementHome(0, WIN);%0A        stats.incrementHome(0, WIN);%0A%0A        stats.incrementHome(1, LOSE);%0A        stats.incrementHome(1, DRAW);%0A        stats.incrementHome(1, DRAW);%0A        stats.incrementHome(1, WIN);%0A        stats.incrementHome(1, WIN);%0A        stats.incrementHome(1, WIN);%0A%0A        stats.incrementHome(2, DRAW
+, 3);%0A        stats.addHome(0, WIN, 2);%0A%0A        stats.incrementHome(1, LOSE);%0A        stats.addHome(1, DRAW, 2);%0A        stats.addHome(1, WIN, 3
 );%0A
+%0A
     
@@ -1475,215 +1475,60 @@
 ats.
-incrementHome(2, DRAW);%0A        stats.incrementHome(2, DRAW);%0A        stats.incrementHome(2, WIN);%0A        stats.incrementHome(2, WIN);%0A        stats.incrementHome(2, WIN);%0A        stats.incrementHome(2, WIN
+addHome(2, DRAW, 3);%0A        stats.addHome(2, WIN, 4
 );%0A%0A

Refactor TeamRatersStatsApproximationTest