package edu.uchicago.cs.encsel.parquet;

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

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.junit.Before;
import org.junit.Test;

import edu.uchicago.cs.encsel.model.IntEncoding;
import edu.uchicago.cs.encsel.model.StringEncoding;

public class ParquetWriterHelperTest {

	@Before
	public void deleteFile() throws IOException {
		Files.deleteIfExists(Paths.get("resource/test_col_str.data.DELTAL"));
		Files.deleteIfExists(Paths.get("resource/test_col_str.data.DICT"));
		Files.deleteIfExists(Paths.get("resource/test_col_str.data.PLAIN"));

		Files.deleteIfExists(Paths.get("resource/test_col_int.data.DICT"));
		Files.deleteIfExists(Paths.get("resource/test_col_int.data.BP"));
		Files.deleteIfExists(Paths.get("resource/test_col_int.data.DELTABP"));
		Files.deleteIfExists(Paths.get("resource/test_col_int.data.RLE"));
		Files.deleteIfExists(Paths.get("resource/test_col_int.data.PLAIN"));
	}

	@Test
	public void testWriteStr() throws IOException {

		String file = "resource/test_col_str.data";

		ParquetWriterHelper.singleColumnString(new File(file).toURI(), StringEncoding.DICT);
		ParquetWriterHelper.singleColumnString(new File(file).toURI(), StringEncoding.DELTAL);
		ParquetWriterHelper.singleColumnString(new File(file).toURI(), StringEncoding.PLAIN);
		
		assertTrue(Files.exists(Paths.get("resource/test_col_str.data.DELTAL")));
		assertTrue(Files.exists(Paths.get("resource/test_col_str.data.DICT")));
		assertTrue(Files.exists(Paths.get("resource/test_col_str.data.PLAIN")));
	}

	@Test
	public void testWriteInt() throws IOException {
		String file = "resource/test_col_int.data";

		HardcodedValuesWriterFactory.INSTANCE.setIntBitLength(14);

		ParquetWriterHelper.singleColumnInt(new File(file).toURI(), IntEncoding.DICT);
		ParquetWriterHelper.singleColumnInt(new File(file).toURI(), IntEncoding.BP);
		ParquetWriterHelper.singleColumnInt(new File(file).toURI(), IntEncoding.DELTABP);
		ParquetWriterHelper.singleColumnInt(new File(file).toURI(), IntEncoding.RLE);
		ParquetWriterHelper.singleColumnInt(new File(file).toURI(), IntEncoding.PLAIN);
		

		assertTrue(Files.exists(Paths.get("resource/test_col_int.data.DICT")));
		assertTrue(Files.exists(Paths.get("resource/test_col_int.data.BP")));
		assertTrue(Files.exists(Paths.get("resource/test_col_int.data.DELTABP")));
		assertTrue(Files.exists(Paths.get("resource/test_col_int.data.RLE")));
		assertTrue(Files.exists(Paths.get("resource/test_col_int.data.PLAIN")));
	}
	
	@Test
	public void testDetermineBitLength() {
		assertEquals(13,ParquetWriterHelper.scanIntBitLength(new File("resource/bitlength_test").toURI()));
	}
}

@@ -502,32 +502,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -583,32 +583,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -662,32 +662,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -743,32 +743,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -822,32 +822,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -899,32 +899,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -981,32 +981,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -1059,32 +1059,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -1183,32 +1183,41 @@
 %09String file = %22
+src/test/
 resource/test_co
@@ -1526,32 +1526,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -1611,32 +1611,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -1694,32 +1694,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -1826,16 +1826,25 @@
 file = %22
+src/test/
 resource
@@ -2366,32 +2366,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -2449,32 +2449,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -2530,32 +2530,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -2616,32 +2616,41 @@
 ists(Paths.get(%22
+src/test/
 resource/test_co
@@ -2706,16 +2706,25 @@
 hs.get(%22
+src/test/
 resource
@@ -2870,16 +2870,25 @@
 w File(%22
+src/test/
 resource

fix unit test bug