package io.github.omskscream.ioc;

import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

/**
 * @author omskscream
 */
public class IOCKeyTest {
    private final IOCKey k1 = IOCKey.of(Typed.STRING);
    private final IOCKey k2 = IOCKey.of(Typed.STRING);
    private final IOCKey k3 = IOCKey.of("name", Typed.STRING);

    private final IOCKey k4 = IOCKey.of(Typed.INTEGER);
    private final IOCKey k5 = IOCKey.of("name", Typed.INTEGER);

    private final IOCKey k6 = IOCKey.of(new Typed<List<String>>(){});
    private final IOCKey k7 = IOCKey.of(new Typed<List<Integer>>(){});

    @Test
    public void equality() {
        assertEquals(k1, k2);       // keys with same Typed are equal
        assertEquals(k2, k1);       // symmetrically

        assertNotEquals(k1, k3);    // but with different names they are not
        assertNotEquals(k1, k4);    // or with different Typed
        assertNotEquals(k1, k5);
        assertNotEquals(k1, k6);
        assertNotEquals(k4, k5);
        assertNotEquals(k5, k6);
        assertNotEquals(k6, k7);
        assertNotEquals(k3, k4);
        assertNotEquals(k3, k6);
        assertNotEquals(k3, k5);    // or with same name and different Typed

    }

    @Test
    public void hashes() {
        assertEquals(k1.hashCode(), k2.hashCode());
        assertNotEquals(k6.hashCode(), k7.hashCode());

        assertNotEquals(k1.hashCode(), k3.hashCode());
        assertNotEquals(k1.hashCode(), k4.hashCode());

        assertNotEquals(k4.hashCode(), k5.hashCode());
        assertNotEquals(k5.hashCode(), k6.hashCode());
        assertNotEquals(k1.hashCode(), k6.hashCode());
        assertNotEquals(k3.hashCode(), k6.hashCode());
    }
}

@@ -251,18 +251,25 @@
  IOCKey 
-k1
+stringKey
  = IOCKe
@@ -313,18 +313,26 @@
  IOCKey 
-k2
+stringKey1
  = IOCKe
@@ -376,18 +376,30 @@
  IOCKey 
-k3
+namedStringKey
  = IOCKe
@@ -452,18 +452,26 @@
  IOCKey 
-k4
+integerKey
  = IOCKe
@@ -516,18 +516,31 @@
  IOCKey 
-k5
+namedIntegerKey
  = IOCKe
@@ -594,18 +594,29 @@
  IOCKey 
-k6
+listStringKey
  = IOCKe
@@ -675,18 +675,30 @@
  IOCKey 
-k7
+listIntegerKey
  = IOCKe
@@ -798,16 +798,36 @@
 als(
-k1, k2);
+stringKey, stringKey1);     
     
@@ -888,16 +888,36 @@
 als(
-k2, k1);
+stringKey1, stringKey);     
     
@@ -965,16 +965,36 @@
 als(
-k1, k3
+stringKey, namedStringKey
 );
+ 
     
@@ -1062,16 +1062,36 @@
 als(
-k1, k4);
+stringKey, integerKey);     
     
@@ -1145,14 +1145,34 @@
 als(
-k1, k5
+stringKey, namedIntegerKey
 );%0A 
@@ -1198,14 +1198,32 @@
 als(
-k1, k6
+stringKey, listStringKey
 );%0A 
@@ -1249,80 +1249,148 @@
 als(
-k4, k5);%0A        assertNotEquals(k5, k6);%0A        assertNotEquals(k6, k7
+integerKey, namedIntegerKey);%0A        assertNotEquals(namedIntegerKey, listStringKey);%0A        assertNotEquals(listStringKey, listIntegerKey
 );%0A 
@@ -1416,14 +1416,34 @@
 als(
-k3, k4
+namedStringKey, integerKey
 );%0A 
@@ -1469,53 +1469,97 @@
 als(
-k3, k6);%0A        assertNotEquals(k3, k5);    
+namedStringKey, listStringKey);%0A        assertNotEquals(namedStringKey, namedIntegerKey);
 // o
@@ -1652,38 +1652,290 @@
     
-assertEquals(k1.hashCode(), k2
+// if keys are equal, their hashes must be equal too%0A        // if keys are not equal, their hashes must be different (to avoid collisions in container)%0A%0A        assertEquals(stringKey.hashCode(), stringKey1.hashCode());%0A%0A        assertNotEquals(stringKey.hashCode(), namedStringKey
 .has
@@ -1968,18 +1968,25 @@
 tEquals(
-k6
+stringKey
 .hashCod
@@ -1994,10 +1994,18 @@
 (), 
-k7
+integerKey
 .has
@@ -2006,32 +2006,106 @@
 ey.hashCode());%0A
+        assertNotEquals(stringKey.hashCode(), namedIntegerKey.hashCode());
 %0A        assertN
@@ -2105,34 +2105,41 @@
 assertNotEquals(
-k1
+stringKey
 .hashCode(), k3.
@@ -2135,18 +2135,29 @@
 Code(), 
-k3
+listStringKey
 .hashCod
@@ -2178,34 +2178,46 @@
 assertNotEquals(
-k1
+namedStringKey
 .hashCode(), k4.
@@ -2213,18 +2213,26 @@
 Code(), 
-k4
+integerKey
 .hashCod
@@ -2241,50 +2241,152 @@
 ));%0A
-%0A        assertNotEquals(k4.hashCode(), k5
+        assertNotEquals(namedStringKey.hashCode(), namedIntegerKey.hashCode());%0A        assertNotEquals(namedStringKey.hashCode(), listStringKey
 .has
@@ -2423,10 +2423,18 @@
 als(
-k5
+integerKey
 .has
@@ -2434,34 +2434,47 @@
 Key.hashCode(), 
-k6
+namedIntegerKey
 .hashCode());%0A  
@@ -2499,80 +2499,127 @@
 als(
-k1.hashCode(), k6.hashCode());%0A        assertNotEquals(k3.hashCode(), k6
+namedIntegerKey.hashCode(), listStringKey.hashCode());%0A        assertNotEquals(listStringKey.hashCode(), listIntegerKey
 .has

Update test for IOCKey class