Commit 6870a34a authored by Xiaoying Pu's avatar Xiaoying Pu

test passed

parent e222ad25
......@@ -28,6 +28,7 @@ public class Persistence {
} catch (FileNotFoundException | UnsupportedEncodingException e) {
e.printStackTrace(System.out);
}
/*header row, comma separated
Write the header to file
*/
......@@ -46,6 +47,7 @@ public class Persistence {
public void initEntry() {
this.tempRow = new ArrayList<>();
String currentTime = String.valueOf(System.currentTimeMillis());
this.tempRow.add(currentTime);
}
/**
......@@ -63,12 +65,18 @@ public class Persistence {
* Writes the row into the file
*/
public void flush() {
assert this.tempRow.size() == this.colNames.length;
this.tempRow.stream().forEach((s) -> {
System.out.println(s);
});
// plus 1 because the colname does not contain timestamp
// Don't ask me why
assert this.tempRow.size() == this.colNames.length + 1;
String dataRow;
// TODO for loop
dataRow = this.tempRow
.stream()
.reduce("", (s1, s2) -> s1 + "," + s2);
dataRow = dataRow.substring(1);
this.writer.println(dataRow);
this.writer.flush();
}
......
package util;
import org.junit.Test;
/**
*
* @author Xiaoying Pu <xp002@bucknell.edu>
*/
public class PersistenceTest {
private Persistence writer;
public PersistenceTest() {
// {"digit_length", "decision_id", "response"};
this.writer = new Persistence("testPersistence.csv", Header.DIGIT_HEADER);
}
@Test
public void theWholeThing() {
for (int i = 0; i < 10; i++) {
this.writer.initEntry();
this.writer.put(2);
this.writer.put(3);
this.writer.put("correct");
this.writer.flush();
}
}
}
time,digit_length,decision_id,response
1448384635129,2,3,correct
1448384635346,2,3,correct
1448384635346,2,3,correct
1448384635347,2,3,correct
1448384635347,2,3,correct
1448384635347,2,3,correct
1448384635348,2,3,correct
1448384635348,2,3,correct
1448384635348,2,3,correct
1448384635348,2,3,correct
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment