
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 com.uwetrottmann.shopr.algorithm.model.Price;

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);

        // sum getting bigger than 1.0
        actual = new double[] {
                // BLUE, RED, PINK, VIOLET
                1.0 / 3, 0.0, 1.0 / 3, 1.0 / 3
        };
        expected = new double[] {
                // BLUE, RED, PINK, VIOLET
                0.0, 0.5, 0.25, 0.25
        };
        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);

        // liking with similars, make all non-similar are zero
        actual = new double[] {
                1.0 / 7, 1.0 / 7, 1.0 / 7, 1.0 / 7, 1.0 / 7, 1.0 / 7, 1.0 / 7
        };
        expected = new double[] {
                0.5 + 1.0 / 7, 1 - (0.5 + 1.0 / 7), 0.0, 0.0, 0.0, 0.0, 0.0
        };
        new Price().dislikeValue(6, actual);
        new Price().dislikeValue(5, actual);
        new Price().dislikeValue(4, actual);
        new Price().dislikeValue(3, actual);
        new Price().dislikeValue(2, actual);
        new Price().likeValue(0, actual);
        assertThat(actual).isEqualTo(expected);
    }

}

@@ -3300,19 +3300,19 @@
 s, make 
-all
+one
  non-sim
@@ -3320,12 +3320,8 @@
 lar 
-are 
 zero
@@ -3434,32 +3434,90 @@
  / 7%0A        %7D;%0A
+        double nonSimilarVal = 1.0 / 6 - ((1.0 / 7) / 4);%0A
         expected
@@ -3554,31 +3554,15 @@
     
-0.5 + 1.0 / 7, 1 - (0.5
+1.0 / 6
  + 1
@@ -3571,34 +3571,48 @@
  / 7
-)
 , 
-0.0, 0.0, 0.0, 0.0, 0.0
+1.0 / 6, nonSimilarVal, nonSimilarVal,
 %0A   
@@ -3608,35 +3608,32 @@
 larVal,%0A        
-%7D;%0A
         new Pric
@@ -3629,177 +3629,66 @@
    n
-ew Price().dislikeValue(6, actual);%0A        new Price().dislikeValue(5, actual);%0A        new Price().dislikeValue(4, actual);%0A        new Price().dislikeValue(3, actual)
+onSimilarVal,%0A                nonSimilarVal, 0.0%0A        %7D
 ;%0A  
@@ -3718,17 +3718,17 @@
 keValue(
-2
+6
 , actual

Modify dislike,like test to only dislike once. Now reproducing issue.