/*
 * Copyright (c) 2015, Cloudera, Inc. All Rights Reserved.
 *
 * Cloudera, Inc. licenses this file to you 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
 *
 * This software 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 com.cloudera.oryx.app.als;

import org.junit.Test;

import com.cloudera.oryx.common.OryxTest;

/**
 * Tests {@link MultiRescorerProvider} (implementations).
 */
public final class MultiRescorerProviderTest extends OryxTest {
  
  @Test
  public void testMultiRecommendRescorer() {
    RescorerProvider multi =
        new MultiRescorerProvider(new SimpleModRescorerProvider(2), new SimpleModRescorerProvider(3));
    
    Rescorer provider = multi.getRecommendRescorer(new String[]{"ABCDE"}, null);
    assertNull(provider);
    
    provider = multi.getRecommendRescorer(new String[]{"AB"}, null);
    assertNotNull(provider);
    assertFalse(provider instanceof MultiRescorer);
    assertTrue(provider.isFiltered("ABC"));
    assertFalse(provider.isFiltered("AB"));

    provider = multi.getRecommendRescorer(new String[]{"ABCDEF"}, null);
    assertNotNull(provider);
    assertTrue(provider instanceof MultiRescorer);
    assertTrue(provider.isFiltered("ABC"));
    assertTrue(provider.isFiltered("AB"));
    assertFalse(provider.isFiltered("ABCDEFABCDEF"));
  }
  
  @Test
  public void testMultiRecommendToAnonymousRescorer() {
    RescorerProvider multi = 
        new MultiRescorerProvider(new SimpleModRescorerProvider(2), new SimpleModRescorerProvider(3));
    
    Rescorer provider = multi.getRecommendToAnonymousRescorer(new String[]{"ABCDE"}, null);
    assertNull(provider);
    
    provider = multi.getRecommendToAnonymousRescorer(new String[]{"AB"}, null);
    assertNotNull(provider);
    assertFalse(provider instanceof MultiRescorer);
    assertTrue(provider.isFiltered("ABC"));
    assertFalse(provider.isFiltered("AB"));

    provider = multi.getRecommendToAnonymousRescorer(new String[]{"ABCDEF"}, null);
    assertNotNull(provider);
    assertTrue(provider instanceof MultiRescorer);
    assertTrue(provider.isFiltered("ABC"));
    assertTrue(provider.isFiltered("AB"));
    assertFalse(provider.isFiltered("ABCDEF"));
  }
  
  @Test
  public void testMultiMostPopularItemsRescorer() {
    RescorerProvider multi =
        new MultiRescorerProvider(new SimpleModRescorerProvider(2), new SimpleModRescorerProvider(3));
    Rescorer provider = multi.getMostPopularItemsRescorer(null);
    assertNotNull(provider);
    assertTrue(provider instanceof MultiRescorer);
    assertTrue(provider.isFiltered("ABC"));
    assertTrue(provider.isFiltered("AB"));
    assertFalse(provider.isFiltered("ABCDEF"));
  }
  
  @Test
  public void testMultiMostSimilarItemsRescorer() {
    RescorerProvider multi = 
        new MultiRescorerProvider(new SimpleModRescorerProvider(2), new SimpleModRescorerProvider(3));
    PairRescorer provider = multi.getMostSimilarItemsRescorer(null);
    assertNotNull(provider);
    assertTrue(provider instanceof MultiPairRescorer);
    assertTrue(provider.isFiltered("AB", "ABC"));
    assertTrue(provider.isFiltered("AB", "ABCDEF"));
    assertFalse(provider.isFiltered("ABCDEF", "ABCDEFABCDEF"));
  }
  
}

@@ -876,32 +876,24 @@
 ider multi =
-%0A       
  new MultiRe
@@ -899,32 +899,41 @@
 escorerProvider(
+%0A        
 new SimpleModRes
@@ -1055,32 +1055,43 @@
 ring%5B%5D%7B%22ABCDE%22%7D,
+ (String%5B%5D)
  null);%0A    asse
@@ -1166,32 +1166,43 @@
  String%5B%5D%7B%22AB%22%7D,
+ (String%5B%5D)
  null);%0A    asse
@@ -1420,32 +1420,43 @@
 ing%5B%5D%7B%22ABCDEF%22%7D,
+ (String%5B%5D)
  null);%0A    asse
@@ -1764,33 +1764,24 @@
 der multi = 
-%0A        
 new MultiRes
@@ -1786,32 +1786,41 @@
 escorerProvider(
+%0A        
 new SimpleModRes
@@ -1931,32 +1931,41 @@
 onymousRescorer(
+%0A        
 new String%5B%5D%7B%22AB
@@ -1970,16 +1970,27 @@
 ABCDE%22%7D,
+ (String%5B%5D)
  null);%0A
@@ -2092,16 +2092,27 @@
 %5D%7B%22AB%22%7D,
+ (String%5B%5D)
  null);%0A
@@ -2357,16 +2357,27 @@
 BCDEF%22%7D,
+ (String%5B%5D)
  null);%0A
@@ -2686,24 +2686,16 @@
  multi =
-%0A       
  new Mul
@@ -2705,32 +2705,41 @@
 escorerProvider(
+%0A        
 new SimpleModRes
@@ -2841,32 +2841,43 @@
 arItemsRescorer(
+(String%5B%5D) 
 null);%0A    asser
@@ -3178,25 +3178,16 @@
 multi = 
-%0A        
 new Mult
@@ -3204,16 +3204,25 @@
 rovider(
+%0A        
 new Simp
@@ -3344,16 +3344,27 @@
 escorer(
+(String%5B%5D) 
 null);%0A 

Fix compiler warning