package info.limpet.data2;

import java.util.ArrayList;
import java.util.List;

import info.limpet.ICommand;
import info.limpet.IStoreItem;
import info.limpet.impl.MockContext;
import info.limpet.impl.NumberDocument;
import info.limpet.impl.NumberDocumentBuilder;
import info.limpet.impl.StoreGroup;
import info.limpet.operations.filter.MaxFilterOperation;

import javax.measure.unit.SI;

import org.junit.Test;

import junit.framework.TestCase;

public class TestFilter extends TestCase
{
  @Test
  public void testFilterIndexed()
  {
    ArrayList<IStoreItem> selection = new ArrayList<IStoreItem>();
    MockContext context = new MockContext(){

      @Override
      public String getInput(String title, String description,
          String defaultText)
      {
        return "6";
      }};
    StoreGroup store = new StoreGroup("data");

    NumberDocumentBuilder builder = new NumberDocumentBuilder("doc 1", SI.METER, null, SI.SECOND);
    builder.add(10d, 4d);
    builder.add(20d, 5d);
    builder.add(30d, 6d);
    builder.add(40d, 7d);
    builder.add(50d, 8d);
    builder.add(60d, 7d);
    builder.add(70d, 6d);
    
    NumberDocument doc = builder.toDocument();
    selection.add(doc);
    
    List<ICommand> oper = new MaxFilterOperation().actionsFor(selection, store, context);
    assertNotNull("operations present", oper);
    assertEquals("correct operations", 1, oper.size());
    
    // ok, run it
    oper.get(0).execute();
    
    NumberDocument nd = (NumberDocument) oper.get(0).getOutputs().get(0);
    assertNotNull("have output", nd);
    assertEquals("correct length", 4, nd.size());
    assertEquals("correct units", SI.METER, nd.getUnits());
    assertEquals("correct index units", SI.SECOND, nd.getIndexUnits());   
  }
}

@@ -483,16 +483,18 @@
 tCase%0A%7B%0A
+ %0A
   @Test%0A
@@ -645,156 +645,8 @@
 xt()
-%7B%0A%0A      @Override%0A      public String getInput(String title, String description,%0A          String defaultText)%0A      %7B%0A        return %226%22;%0A      %7D%7D
 ;%0A  
@@ -1229,17 +1229,17 @@
 tions%22, 
-1
+0
 , oper.s
@@ -1247,24 +1247,459 @@
 ze());%0A    %0A
+    // ok, give it a singleton%0A    NumberDocumentBuilder sBuilder = new NumberDocumentBuilder(%22singleton%22, SI.CELSIUS, null, null);%0A    sBuilder.add(6d);%0A    NumberDocument singleton = sBuilder.toDocument();%0A    %0A    selection.add(singleton);%0A    %0A    oper = new MaxFilterOperation().actionsFor(selection, store, context);%0A    assertNotNull(%22operations present%22, oper);%0A    assertEquals(%22correct operations%22, 2, oper.size());%0A        %0A
     // ok, r
@@ -2029,18 +2029,431 @@
 nits());
+%0A
    
+ %0A    // have a got at applying the minimum filter%0A    singleton.setValue(5d);%0A    %0A    // ok, run it%0A    oper.get(1).execute();%0A    %0A    nd = (NumberDocument) oper.get(1).getOutputs().get(0);%0A    assertNotNull(%22have output%22, nd);%0A    assertEquals(%22correct length%22, 6, nd.size());%0A    assertEquals(%22correct units%22, SI.METER, nd.getUnits());%0A    assertEquals(%22correct index units%22, SI.SECOND, nd.getIndexUnits());
 %0A  %7D%0A%7D%0A

extend tests