package nl.jft.logic.participant;

import nl.jft.logic.LogicConstants;
import nl.jft.logic.util.LogicTestUtil;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.time.LocalDateTime;

import static org.junit.Assert.*;

/**
 * @author Lesley
 */
public class EloTest {

    @Rule
    public final ExpectedException expectedException = ExpectedException.none();

    @Test
    public void construct_negativeRatingOnly_throwsException() {
        expectedException.expect(IllegalArgumentException.class);

        Elo elo = LogicTestUtil.makeElo(-1);
    }

    @Test
    public void construct_negativeRating_throwsException() {
        expectedException.expect(IllegalArgumentException.class);

        Elo elo = LogicTestUtil.makeElo(LogicConstants.INTERNAL_ID, -1, LogicTestUtil.makeDefaultLocalDateTime());
    }

    @Test
    public void construct_negativeTime_throwsException() {
        expectedException.expect(NullPointerException.class);

        Elo elo = LogicTestUtil.makeElo(LogicConstants.INTERNAL_ID, 1500, null);
    }

    @Test
    public void equals_sameObjects_returnsTrue() {
        Elo elo1 = LogicTestUtil.makeDefaultElo();
        Elo elo2 = LogicTestUtil.makeDefaultElo();

        boolean result = elo1.equals(elo2);
        assertTrue(result);
    }

    @Test
    public void equals_otherElo_returnsFalse() throws Exception {
        Elo elo1 = LogicTestUtil.makeDefaultElo();
        Elo elo2 = LogicTestUtil.makeElo(LogicConstants.INTERNAL_ID, 2000, LogicTestUtil.makeDefaultLocalDateTime());

        boolean result = elo1.equals(elo2);
        assertFalse(result);
    }

    @Test
    public void equals_otherObject_returnsFalse() {
        Elo elo1 = LogicTestUtil.makeDefaultElo();
        String elo2 = "elo2";

        boolean result = elo1.equals(elo2);
        assertFalse(result);
    }

    @Test
    public void equals_nullObject_returnsFalse() {
        Elo elo1 = LogicTestUtil.makeDefaultElo();
        Elo elo2 = null;

        boolean result = elo1.equals(elo2);
        assertFalse(result);
    }

    @Test
    public void hashCode_whenCalled_returnsHashCode() {
        Elo elo1 = LogicTestUtil.makeDefaultElo();
        Elo elo2 = LogicTestUtil.makeDefaultElo();

        boolean result = elo1.hashCode() == elo2.hashCode();
        assertTrue(result);
    }

    @Test
    public void getId_whenCalled_returnsId() {
        Elo elo = LogicTestUtil.makeDefaultElo();

        int expected = LogicConstants.INTERNAL_ID;
        int actual = elo.getId();

        assertEquals(expected, actual);
    }

    @Test
    public void getRating_whenCalled_returnsRating() {
        Elo elo = LogicTestUtil.makeDefaultElo();

        double expected = 1500d;
        double actual = elo.getRating();

        assertEquals(expected, actual, 0.0000001d);
    }

    @Test
    public void getTime_whenCalled_returnsTime() {
        Elo elo = LogicTestUtil.makeDefaultElo();

        LocalDateTime expected = LogicConstants.INTERNAL_DATETIME;
        LocalDateTime actual = elo.getTime();

        assertEquals(expected, actual);
    }

}
@@ -1069,32 +1069,33 @@
 , null);%0A    %7D%0A%0A
+%0A
     @Test%0A    pu
@@ -1359,19 +1359,24 @@
 ls_other
-Elo
+Instance
 _returns
@@ -1386,25 +1386,8 @@
 se()
- throws Exception
  %7B%0A 
@@ -1459,60 +1459,297 @@
 2 = 
-LogicTestUtil.makeElo(LogicConstants.INTERNAL_ID, 20
+null;%0A%0A        boolean result = elo1.equals(elo2);%0A        assertFalse(result);%0A    %7D%0A%0A    @Test%0A    public void equals_differentIds_returnsFalse() %7B%0A        Elo elo1 = LogicTestUtil.makeElo(1, 1500, LogicTestUtil.makeDefaultLocalDateTime());%0A        Elo elo2 = LogicTestUtil.makeElo(2, 15
 00, 
@@ -1909,19 +1909,24 @@
 als_
-otherObject
+differentRatings
 _ret
@@ -1972,35 +1972,77 @@
 estUtil.make
-DefaultElo(
+Elo(1, 1500, LogicTestUtil.makeDefaultLocalDateTime()
 );%0A        S
@@ -2044,22 +2044,19 @@
     
-String
+Elo
  elo2 = 
 %22elo
@@ -2055,14 +2055,80 @@
 2 = 
-%22elo2%22
+LogicTestUtil.makeElo(1, 1600, LogicTestUtil.makeDefaultLocalDateTime())
 ;%0A%0A 
@@ -2243,18 +2243,22 @@
 als_
-nullObject
+differentTimes
 _ret
@@ -2312,45 +2312,109 @@
 make
-DefaultElo();%0A        Elo elo2 = null
+Elo(1, 1500, LocalDateTime.MIN);%0A        Elo elo2 = LogicTestUtil.makeElo(1, 1500, LocalDateTime.MAX)
 ;%0A%0A 

Test more branches Elo.