
package com.uwetrottmann.shopr.algorithm.test;

import static org.fest.assertions.api.Assertions.assertThat;

import com.uwetrottmann.shopr.algorithm.model.ClothingType;
import com.uwetrottmann.shopr.algorithm.model.Color;

import org.junit.Test;

public class LikeDislikeTest {

    @Test
    public void testLikeValue() {
        // all equal
        double[] actual = new double[] {
                0.25, 0.25, 0.25, 0.25
        };
        double[] expected = new double[] {
                0.25 - 0.25 / 3, 0.5, 0.25 - 0.25 / 3, 0.25 - 0.25 / 3
        };
        new ClothingType().likeValue(1, actual);
        assertThat(actual).isEqualTo(expected);

        // one getting bigger than zero
        actual = new double[] {
                0.05, 0.85, 0.05, 0.05
        };
        expected = new double[] {
                0.0, 1.0, 0.0, 0.0
        };
        new ClothingType().likeValue(1, actual);
        assertThat(actual).isEqualTo(expected);
    }

    @Test
    public void testLikeValueWithSimilars() {
        // all equal
        double[] actual = new double[] {
                // BLUE, RED, PINK, VIOLET
                0.25, 0.25, 0.25, 0.25
        };
        double[] expected = new double[] {
                // BLUE, RED, PINK, VIOLET
                0.0, 0.5, 0.25, 0.25
        };
        new Color().likeValue(1, actual);
        assertThat(actual).isEqualTo(expected);

        // one getting bigger than zero
        actual = new double[] {
                0.05, 0.85, 0.05, 0.05
        };
        expected = new double[] {
                0.0, 1.0, 0.0, 0.0
        };
        new Color().likeValue(1, actual);
        assertThat(actual).isEqualTo(expected);
    }

    @Test
    public void testdislikeValue() {
        // all equal
        double[] actual = new double[] {
                0.25, 0.25, 0.25, 0.25
        };
        double[] expected = new double[] {
                0.25 + 0.25 / 3, 0.0, 0.25 + 0.25 / 3, 0.25 + 0.25 / 3
        };
        new ClothingType().dislikeValue(1, actual);
        assertThat(actual).isEqualTo(expected);

        // two zero, keep them zero
        actual = new double[] {
                0.0, 0.5, 0.0, 0.5
        };
        expected = new double[] {
                0.0, 0.0, 0.0, 1.0
        };
        new ClothingType().dislikeValue(1, actual);
        assertThat(actual).isEqualTo(expected);
    }

    @Test
    public void testDislikeLikeValue() {
        // first dislike
        double[] actual = new double[] {
                0.25, 0.25, 0.25, 0.25
        };
        double[] expected = new double[] {
                0.25 + 0.25 / 3, 0.0, 0.25 + 0.25 / 3, 0.25 + 0.25 / 3
        };
        new ClothingType().dislikeValue(1, actual);
        assertThat(actual).isEqualTo(expected);

        // then like again
        // liked value should have highest weight now
        expected = new double[] {
                0.25 + 0.25 / 3 - 0.5 / 3, 0.5, 0.25 + 0.25 / 3 - 0.5 / 3,
                0.25 + 0.25 / 3 - 0.5 / 3
        };
        new ClothingType().likeValue(1, actual);
        assertThat(actual).isEqualTo(expected);
    }

}

@@ -1398,35 +1398,35 @@
 d);%0A%0A        // 
-one
+sum
  getting bigger 
@@ -1422,36 +1422,35 @@
 ing bigger than 
-zero
+1.0
 %0A        actual 
@@ -1482,38 +1482,89 @@
         
-0.05
+// BLUE, RED, PINK, VIOLET%0A                1.0 / 3
 , 0.
-85, 0.05, 0.05
+0, 1.0 / 3, 1.0 / 3
 %0A       
@@ -1593,32 +1593,75 @@
  new double%5B%5D %7B%0A
+                // BLUE, RED, PINK, VIOLET%0A
                 
@@ -1661,37 +1661,39 @@
        0.0, 
-1.0
+0.5
 , 0.
-0
+25
 , 0.
-0
+25
 %0A        %7D;%0A

Update LikeDislikeTest with sum bigger than zero for similar color variant.