package info.limpet.data;

import java.io.File;
import java.util.List;

import info.limpet.ICollection;
import info.limpet.IStore.IStoreItem;
import info.limpet.data.csv.CsvParser;
import info.limpet.data.store.InMemoryStore.StoreGroup;
import junit.framework.TestCase;

public class TestCsvParser extends TestCase
{

	public void testIntervals() throws Exception
	{
		File file = getDataFile("intervals.csv");
		assertTrue(file.isFile());
		List<IStoreItem> items = new CsvParser().parse(file.getAbsolutePath());
		assertTrue(items.size() == 1);
		ICollection firstColl = (ICollection) items.get(0);
		assertEquals("correct num rows", 69, firstColl.size());
	}

	public void testFrequencs() throws Exception
	{
		File file = getDataFile("frequences.csv");
		assertTrue(file.isFile());
		List<IStoreItem> items = new CsvParser().parse(file.getAbsolutePath());
		assertTrue(items.size() == 1);
		ICollection firstColl = (ICollection) items.get(0);
		assertEquals("correct num rows", 11, firstColl.size());
	}

	public void testMultiColumn() throws Exception
	{
		File file = getDataFile("track_one.csv");
		assertTrue(file.isFile());
		CsvParser parser = new CsvParser();
		List<IStoreItem> items = parser.parse(file.getAbsolutePath());
		assertEquals("correct group", 1, items.size());
		StoreGroup group = (StoreGroup) items.get(0);
		assertEquals("correct num collections", 6, group.size());
		ICollection firstColl = (ICollection) group.get(0);
		assertEquals("correct num rows", 69, firstColl.size());
	}

	public void testMultiColumnUSA() throws Exception
	{
		File file = getDataFile("usa.csv");
		assertTrue(file.isFile());
		CsvParser parser = new CsvParser();
		List<IStoreItem> items = parser.parse(file.getAbsolutePath());
		assertEquals("correct group", 1, items.size());
		StoreGroup group = (StoreGroup) items.get(0);
		assertEquals("correct num collections", 3, group.size());
		ICollection firstColl = (ICollection) group.get(0);
		assertEquals("correct num rows", 1708, firstColl.size());
	}
	
	private File getDataFile(String name)
	{
		File file = new File(getFileName(name));
		return file;
	}

	private String getFileName(String name)
	{
		StringBuilder builder = new StringBuilder();
		builder.append("..");
		builder.append(File.separator);
		builder.append("info.limpet.sample_data");
		builder.append(File.separator);
		builder.append("data");
		builder.append(File.separator);
		builder.append(name);
		return builder.toString();
	}

}

@@ -387,16 +387,21 @@
 taFile(%22
+data/
 interval
@@ -401,32 +401,32 @@
 ntervals.csv%22);%0A
-
 %09%09assertTrue(fil
@@ -737,16 +737,21 @@
 taFile(%22
+data/
 frequenc
@@ -1090,16 +1090,21 @@
 taFile(%22
+data/
 track_on
@@ -1599,16 +1599,29 @@
 taFile(%22
+americas_cup/
 usa.csv%22
@@ -2277,32 +2277,32 @@
 ile.separator);%0A
+
 %09%09builder.append
@@ -2368,68 +2368,8 @@
 r);%0A
-%09%09builder.append(%22data%22);%0A%09%09builder.append(File.separator);%0A
 %09%09bu

fix test file paths