package de.lcag.common;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.io.IOException;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class CsvTableTest {

	@BeforeAll
	static void setUpBeforeClass() throws Exception {
	}

	@BeforeEach
	void setUp() throws Exception {
	}

	@Test
	void testSaveAs() throws IOException {
		File aFile = new File("src/test/resources/results/CsvTable/TEST/NameListCopy.csv");
		CsvTable csv = new CsvTable("CsvTable/NameList.csv");

		csv.read();
		csv.saveAs("src/test/resources/results/CsvTable/TEST/NameListCopy.csv");

		aFile.delete();
		aFile.getParentFile().delete();
	}

	@Test
	void testRead() throws IOException {
		CsvTable csv = null;
		int n;

		// TC1: Use a correct CSV table:
		csv = new CsvTable("CsvTable/City_change_history_ok.csv");
		csv.read();
		n = csv.lenght();

		assertEquals(37780, n);

		// TC2: Use a table where all rows end with a seperator although it is not
		// expected
		csv = new CsvTable("CsvTable/City_change_history_toomany_columns.csv");
		csv.read();
		n = csv.lenght();

		assertEquals(37780, n);
	}
}
