package com.airbnb.aerosolve.core.transforms;

import com.airbnb.aerosolve.core.FeatureVector;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * Created by christhetree on 1/29/16.
 */
public class DeleteStringFeatureFamilyTransformTest {
  private static final Logger log = LoggerFactory.getLogger(
      DeleteStringFeatureFamilyTransformTest.class);

  public String makeConfig() {
    return "test_delete_string_feature_family {\n" +
        " transform: delete_string_feature_family\n" +
        " field1: strFeature1\n" +
        "}";
  }

  public FeatureVector makeFeatureVector() {
    Map<String, Set<String>> stringFeatures = new HashMap<>();

    Set list = new HashSet<String>();
    list.add("I am a string in a string feature");
    stringFeatures.put("strFeature1", list);

    FeatureVector featureVector = new FeatureVector();
    featureVector.setStringFeatures(stringFeatures);
    return featureVector;
  }

  @Test
  public void testEmptyFeatureVector() {
    Config config = ConfigFactory.parseString(makeConfig());
    Transform transform = TransformFactory.createTransform(
        config, "test_delete_string_feature_family");
    FeatureVector featureVector = new FeatureVector();
    transform.doTransform(featureVector);

    assertTrue(featureVector.getStringFeatures() == null);
  }

  @Test
  public void testTransform() {
    Config config = ConfigFactory.parseString(makeConfig());
    Transform transform = TransformFactory.createTransform(
        config, "test_delete_string_feature_family");
    FeatureVector featureVector = makeFeatureVector();
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();

    assertTrue(stringFeatures.containsKey("strFeature1"));
    assertEquals(1, stringFeatures.size());

    transform.doTransform(featureVector);

    assertFalse(stringFeatures.containsKey("strFeature1"));
    assertEquals(0, stringFeatures.size());
  }
}

@@ -863,24 +863,74 @@
 ature1%5Cn%22 +%0A
+        %22 fields: %5BstrFeature2, strFeature3%5D%5Cn%22 +%0A
         %22%7D%22;
@@ -1051,21 +1051,30 @@
 %0A    Set
+%3CString%3E
  list
+1
  = new H
@@ -1080,22 +1080,156 @@
 HashSet%3C
-String
+%3E();%0A    list1.add(%22I am a string in string feature 1%22);%0A    stringFeatures.put(%22strFeature1%22, list1);%0A%0A    Set%3CString%3E list2 = new HashSet%3C
 %3E();%0A   
@@ -1233,16 +1233,17 @@
     list
+2
 .add(%22I 
@@ -1257,17 +1257,155 @@
 ring in 
-a
+string feature 2%22);%0A    stringFeatures.put(%22strFeature2%22, list2);%0A%0A    Set%3CString%3E list3 = new HashSet%3C%3E();%0A    list3.add(%22I am a string in
  string 
@@ -1411,16 +1411,18 @@
  feature
+ 3
 %22);%0A    
@@ -1451,24 +1451,165 @@
 rFeature
-1
+3%22, list3);%0A%0A    Set%3CString%3E list4 = new HashSet%3C%3E();%0A    list4.add(%22I am a string in string feature 4%22);%0A    stringFeatures.put(%22strFeature4
 %22, list
+4
 );%0A%0A    
@@ -2532,32 +2532,209 @@
 strFeature1%22));%0A
+    assertTrue(stringFeatures.containsKey(%22strFeature2%22));%0A    assertTrue(stringFeatures.containsKey(%22strFeature3%22));%0A    assertTrue(stringFeatures.containsKey(%22strFeature4%22));%0A
     assertEquals
@@ -2734,17 +2734,17 @@
 tEquals(
-1
+4
 , string
@@ -2857,32 +2857,211 @@
 strFeature1%22));%0A
+    assertFalse(stringFeatures.containsKey(%22strFeature2%22));%0A    assertFalse(stringFeatures.containsKey(%22strFeature3%22));%0A    assertTrue(stringFeatures.containsKey(%22strFeature4%22));%0A
     assertEquals
@@ -3065,9 +3065,9 @@
 als(
-0
+1
 , st

Update tests for DeleteStringFeatureFamilyTransform