package gavator.test;
import static gavator.algorithm.Algorithms.*;
import gavator.datastructure.*;
import junit.framework.*;
class ToUpperFilter implements Filter<String> {
public String eval(String obj) {
return obj.toUpperCase();
}
}
class ToLowerFilter implements Filter<String> {
public String eval(String obj) {
return obj.toLowerCase();
}
}
class DirtyWordsFilter implements Filter<String> {
public String eval(String obj) {
return obj.replace("dirty words", "***");
}
}
public class FilterPipeTest extends TestCase {
private Pipe lowerPipe, upperPipe, dirtyWordsPipe;
private String string = "abc";
private String dws = "you said dirty words, so...";
public void testFilter() {
Assert.assertEquals("ABC", new ToUpperFilter().eval(string));
Assert.assertEquals("abc", new ToLowerFilter().eval(new ToUpperFilter().eval(string)));
Assert.assertEquals("you said ***, so...", new DirtyWordsFilter().eval(dws));
}
public void testPipe() {
lowerPipe = new Pipe<String>(new ToUpperFilter(), new ToLowerFilter());
upperPipe = new Pipe<String>(new ToLowerFilter(), new ToUpperFilter());
dirtyWordsPipe = new Pipe<String>(lowerPipe, new DirtyWordsFilter());
Assert.assertEquals("abc", lowerPipe.eval("abc"));
Assert.assertEquals("ABC", upperPipe.eval("abc"));
Assert.assertEquals("hehe***", dirtyWordsPipe.eval("hehedirty words"));
Assert.assertEquals("hehe***", pipe("hehedirty words", dirtyWordsPipe));
}
}