Permalink
Browse files

Added Scala test cases to ensure consistent tokenization between Java…

… and Scala.
  • Loading branch information...
lintool committed Jan 6, 2017
1 parent 3458da6 commit 91e9e3488ca4f2b53a490f8baedb3773b6c71d4e
@@ -24,23 +24,23 @@
import static org.junit.Assert.assertEquals;
public class TokenizerTest {
private static final String[] EXAMPLES = {
// Public so we can share test cases across Java and Scala.
public static final String[] EXAMPLES = {
"It is Perfect! But there's something missing.",
"There are perfect 2 pigs here, before the big bad wolf came."
};
// There has got to be a more concise way to do this...
private static final List<List<String>> EXPECTED = Lists.newArrayList(
// Public so we can share test cases across Java and Scala.
public static final List<List<String>> EXPECTED = Lists.newArrayList(
(List<String>) Lists.newArrayList("it", "is", "perfect", "but", "there's", "something", "missing"),
(List<String>) Lists.newArrayList("there", "are", "perfect", "pigs", "here", "before", "the", "big", "bad",
"wolf", "came"));
// There has got to be a more concise way to do this...
@Test
public void testJavaTokenization() throws Exception {
for (int i = 0; i < EXAMPLES.length; i++) {
assertEquals(EXPECTED.get(i), Tokenizer.tokenize(EXAMPLES[i]));
}
}
// TODO: We should add a test case to make sure the Scala tokenizer behaves the same way.
}
@@ -0,0 +1,37 @@
/**
* Bespin: reference implementations of "big data" algorithms
*
* Licensed 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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 io.bespin.scala.util
import org.scalatest.junit.AssertionsForJUnit
import scala.collection.JavaConversions._
import org.junit.Assert._
import org.junit.Test
class TokenizerTest extends AssertionsForJUnit {
class MockTokenizer extends Tokenizer {}
@Test def testScalaTokenization {
val tokenizer = new MockTokenizer()
for (i <- 0 until io.bespin.java.util.TokenizerTest.EXAMPLES.length ) {
assertEquals(io.bespin.java.util.TokenizerTest.EXPECTED.get(i).toList,
tokenizer.tokenize(io.bespin.java.util.TokenizerTest.EXAMPLES(i)))
}
}
}

0 comments on commit 91e9e34

Please sign in to comment.