Commit e85956fc authored by Christophe Rhodes's avatar Christophe Rhodes
Browse files

updates to 09

parent 11c8af80
import org.junit.Before;
public class NaiveStringMatchTest extends StringMatchTest {
@Before
public void setUp() {
matcher = new NaiveStringMatch();
}
}
public class RKStringMatch extends StringMatch {
public int match(String text, String pattern) {
return -1;
}
}
import org.junit.Before;
public class RKStringMatchTest extends StringMatchTest {
@Before
public void setUp() {
matcher = new RKStringMatch();
}
}
public abstract class StringMatch {
public OpCounter counter = new OpCounter();
public abstract int match(String text, String pattern);
}
class StringMatchCount {
public static void main(String args[]) {
String P = "ab";
String T = "aaaaaaaaaa";
StringMatch matcher = new NaiveStringMatch();
matcher.match(T, P);
System.out.println("char reads: " + matcher.counter.report());
}
}
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.Before;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
abstract public class StringMatchTest {
public StringMatch matcher;
@Test
public void testZeroPattern() {
assertEquals(0, matcher.match("abcde", ""));
}
@Test
public void testZeroText() {
assertEquals(-1, matcher.match("", "abcde"));
assertEquals(0, matcher.match("", ""));
}
@Test
public void testTable() throws FileNotFoundException {
Scanner in = new Scanner(new File("../match.txt"));
while(in.hasNext()) {
String text = in.next();
String pattern = in.next();
int pos = in.nextInt();
if(pos != matcher.match(text, pattern))
fail(text + " " + pattern + " " + pos);
}
}
}
abcde f -1
abcde a 0
abcde b 1
abcde c 2
abcde d 3
abcde e 4
abcde af -1
abcde bf -1
abcde cf -1
abcde df -1
abcde ef -1
abcde fa -1
abcde fb -1
abcde fc -1
abcde fd -1
abcde fe -1
abcde ab 0
abcde bc 1
abcde cd 2
abcde de 3
abcde abf -1
abcde bcf -1
abcde cdf -1
abcde def -1
abcde afb -1
abcde bfc -1
abcde cfd -1
abcde dfe -1
abcde fab -1
abcde fbc -1
abcde fcd -1
abcde fde -1
abcde abc 0
abcde bcd 1
abcde cde 2
abcde abcf -1
abcde bcdf -1
abcde cdef -1
abcde abfc -1
abcde bcfd -1
abcde cdfe -1
abcde afbc -1
abcde bfcd -1
abcde cfde -1
abcde fabc -1
abcde fbcd -1
abcde fcde -1
abcde abcd 0
abcde bcde 1
abcde abcdf -1
abcde bcdef -1
abcde abcfd -1
abcde bcdfe -1
abcde abfcd -1
abcde bcfde -1
abcde afbcd -1
abcde bfcde -1
abcde fabcd -1
abcde fbcde -1
abcde abcde 0
abcde abcdef -1
abcde fabcde -1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment