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 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.csv");
		assertTrue(file.isFile());
		CsvParser parser = new CsvParser();
		List<IStoreItem> items = parser.parse(file.getAbsolutePath());
		assertEquals("correct num collections", 6, items.size());
		ICollection firstColl = (ICollection) items.get(0);
		assertEquals("correct num rows", 7, 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();
	}

}

@@ -174,16 +174,72 @@
 Parser;%0A
+import info.limpet.data.store.InMemoryStore.StoreGroup;%0A
 import j
@@ -1085,24 +1085,28 @@
 e(%22track
+_one
 .csv%22);%0A
 %09%09assert
@@ -1089,32 +1089,32 @@
 rack_one.csv%22);%0A
-
 %09%09assertTrue(fil
@@ -1221,32 +1221,130 @@
 bsolutePath());%0A
+%09%09assertEquals(%22correct group%22, 1, items.size());%0A%09%09StoreGroup group = (StoreGroup) items.get(0);%0A
 %09%09assertEquals(%22
@@ -1372,21 +1372,21 @@
 ns%22, 6, 
-items
+group
 .size())
@@ -1419,37 +1419,37 @@
 = (ICollection) 
-items
+group
 .get(0);%0A%09%09asser
@@ -1480,9 +1480,10 @@
 s%22, 
-7
+69
 , fi

fix tests