Skip to content

Commit

Permalink
Add csv reader dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
physikerwelt committed Oct 24, 2021
1 parent ae50ba6 commit 7e6315a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.formulasearchengine</groupId>
<artifactId>dbs-sql-check</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
Expand All @@ -24,6 +24,11 @@
<artifactId>presto-parser</artifactId>
<version>0.177</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.5.2</version>
</dependency>
<dependency>
<groupId>commons-dbutils</groupId>
<artifactId>commons-dbutils</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.formulasearchengine.sql.check.dbs;

import com.opencsv.bean.CsvToBeanBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -41,4 +46,34 @@ public void writeOutput() {
feedback("You might obtain " + maybePoints + " of "+ totalMaybePoints + " additional points that will be granted by humans.");

}

@SuppressWarnings({"unchecked", "rawtypes"})
public void compareWithResource(InputStream refStream , Double maxPoints, Class clazz ){
try {
feedback("check that the file is a valid csv file");
List list = new CsvToBeanBuilder(new StringReader(currentFileContent))
.withIgnoreLeadingWhiteSpace(true)
.withType(clazz)
.build()
.parse();
addCheckMark();
List refList = new CsvToBeanBuilder(new InputStreamReader(refStream))
.withType(clazz)
.withIgnoreLeadingWhiteSpace(true)
.build()
.parse();
if (refList.size() == list.size()
&& list.containsAll(refList)) {
points+=maxPoints;
addCheckMark();
feedback("+");
} else {
feedback("Solution does not match reference solution.");
}
} catch (AssertionError | Exception e) {
feedback("During evaluation the following error occurred");
feedback(e.getLocalizedMessage());

}
}
}

0 comments on commit 7e6315a

Please sign in to comment.