/*
 * Copyright 2012 Takao Nakaguchi
 *
 * 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 org.trie4j.doublearray;

import junit.framework.Assert;

import org.junit.Test;
import org.trie4j.patricia.simple.PatriciaTrie;
import org.trie4j.Trie;
import org.trie4j.TrieTestSet;

public class TailDoubleArrayWithConcatTailBuilderTest extends TrieTestSet{
	@Override
	protected Trie trieWithWords(String... words) {
		PatriciaTrie trie = new PatriciaTrie();
		for(String w : words) trie.insert(w);
		return new TailDoubleArray(trie);
	}

	@Test
	public void test() throws Exception{
		Trie da = newDA(new PatriciaTrie());
		Assert.assertFalse(da.contains("hello"));
	}

	@Test
	public void test2() throws Exception{
		Trie trie = new PatriciaTrie();
		trie.insert("hello");
		Trie da = newDA(trie);
		Assert.assertTrue(da.contains("hello"));
		Assert.assertFalse(da.contains("hi"));
	}

	@Test
	public void test3() throws Exception{
		Trie trie = new PatriciaTrie();
		trie.insert("hello");
		trie.insert("hi");
		Trie da = newDA(trie);
		Assert.assertTrue(da.contains("hello"));
		Assert.assertTrue(da.contains("hi"));
		Assert.assertFalse(da.contains("world"));
	}

	@Test
	public void test4() throws Exception{
		Trie trie = new PatriciaTrie();
		trie.insert("hello");
		trie.insert("hi");
		trie.insert("world");
		Trie da = newDA(trie);
		Assert.assertTrue(da.contains("hello"));
		Assert.assertTrue(da.contains("hi"));
		Assert.assertTrue(da.contains("world"));
	}

	@Test
	public void test5() throws Exception{
		Trie trie = new PatriciaTrie();
		trie.insert("hello");
		trie.insert("world");
		Trie da = newDA(trie);
		Assert.assertTrue(da.contains("hello"));
		Assert.assertFalse(da.contains("hi"));
		Assert.assertTrue(da.contains("world"));
	}

	private Trie newDA(Trie trie){
		return new TailDoubleArray(trie);
	}
	
	public static void main(String[] args) throws Exception{
		Trie t = new PatriciaTrie();
		t.insert("hello");
//		t.insert("hi");
		DoubleArray da = new DoubleArray(t);
		System.out.println("hello: " + da.contains("hello"));
		System.out.println("hi: " + da.contains("hi"));
		System.out.println("world: " + da.contains("world"));
	}
}

@@ -621,16 +621,44 @@
 array;%0A%0A
+import java.util.Iterator;%0A%0A
 import j
@@ -748,24 +748,74 @@
 triciaTrie;%0A
+import org.trie4j.tail.builder.ConcatTailBuilder;%0A
 import org.t
@@ -2333,16 +2333,309 @@
 ));%0A%09%7D%0A%0A
+%09@Test%0A%09public void test_cps() throws Exception%7B%0A%09%09Trie trie = new PatriciaTrie();%0A%09%09trie.insert(%22hello%22);%0A%09%09trie.insert(%22hi%22);%0A%09%09trie.insert(%22world%22);%0A%09%09Trie da = newDA(trie);%0A%09%09Iterator%3CString%3E it = da.commonPrefixSearch(%22hellow%22).iterator();%0A%09%09Assert.assertEquals(%22hello%22, it.next());%0A%09%7D%0A%09%0A
 %09private
@@ -2691,23 +2691,47 @@
 ray(trie
+, new ConcatTailBuilder()
 );%0A%09%7D%0A
-%09
 %0A%09public

add test