/******************************************************************
 * File:        TestLexIndex.java
 * Created by:  Dave Reynolds
 * Created on:  13 Dec 2013
 * 
 * (c) Copyright 2013, Epimorphics Limited
 *
 *****************************************************************/

package com.epimorphics.dclib.sources;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import org.junit.Test;

public class TestLexIndex {
    @Test
    public void testNormalize() {
        assertEquals("", LexIndex.normalize(""));
        assertEquals("a aa bc", LexIndex.normalize("a aa and bc"));
        assertEquals("this is some punc", LexIndex.normalize("this-is:some_punc"));
        assertEquals("world ends", LexIndex.normalize("theWorldEnds"));
        assertEquals("you me", LexIndex.normalize("you and     me"));
        assertEquals("you me", LexIndex.normalize("you      \n & me"));
    }

    @Test
    public void testLookup() {
        LexIndex<String> table = new LexIndex<>();
        table.put("theFirstKey", "first");
        table.put("first key", "second");
        table.put("anotherKey", "third");
        assertNull( table.lookup("no match") );
        assertEquals("third", table.lookup("another key"));
        assertEquals("third", table.lookup("another-key"));
        assertEquals("third", table.lookup("anotherKey "));
        assertEquals("second", table.lookup("first key"));
        assertEquals("second", table.lookup("firstKey"));
        assertEquals("first", table.lookup("theFirstKey"));
    }
    
}

@@ -404,60 +404,424 @@
 ll;%0A
-%0Aimport org.junit.Test;%0A%0Apublic class TestLexIndex %7B
+import static org.junit.Assert.assertThat;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport java.util.Collection;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Apublic class TestLexIndex %7B%0A    %0A%09LexIndex%3CString%3E table = new LexIndex%3C%3E();%0A    %0A    @Before%0A    public void setUp() %7B%0A    %09table.put(%22theFirstKey%22, %22first%22);%0A        table.put(%22first key%22, %22second%22);%0A        table.put(%22anotherKey%22, %22third%22);%0A    %7D%0A
 %0A   
@@ -1275,32 +1275,36 @@
  & me%22));%0A    %7D%0A
+    
 %0A    @Test%0A    p
@@ -1333,186 +1333,8 @@
 ) %7B%0A
-        LexIndex%3CString%3E table = new LexIndex%3C%3E();%0A        table.put(%22theFirstKey%22, %22first%22);%0A        table.put(%22first key%22, %22second%22);%0A        table.put(%22anotherKey%22, %22third%22);%0A
     
@@ -1745,10 +1745,313 @@
  %7D%0A    %0A
+    @Test%0A    public void testLookupAll() %7B%0A        table.put(%22anotherKey%22, %22fourth%22);%0A        Collection%3CString%3E results = table.lookupAll(%22another key%22);%0A        assertTrue(results.contains(%22third%22));%0A        assertTrue(results.contains(%22fourth%22));%0A        assertEquals(2, results.size());%0A    %7D%0A    %0A
 %7D%0A

Test lookupAll