From 7e6315a8432d4b37d93d112446878696aa2cb523 Mon Sep 17 00:00:00 2001 From: "physikerwelt (Moritz Schubotz)" Date: Sun, 24 Oct 2021 14:27:10 +0200 Subject: [PATCH] Add csv reader dependency --- pom.xml | 7 +++- .../sql/check/dbs/SemiManualChecker.java | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2dacc55..389c5f4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.formulasearchengine dbs-sql-check - 1.1.0 + 1.2.0 @@ -24,6 +24,11 @@ presto-parser 0.177 + + com.opencsv + opencsv + 5.5.2 + commons-dbutils commons-dbutils diff --git a/src/main/java/com/formulasearchengine/sql/check/dbs/SemiManualChecker.java b/src/main/java/com/formulasearchengine/sql/check/dbs/SemiManualChecker.java index 4e77ce7..dc8f0f4 100644 --- a/src/main/java/com/formulasearchengine/sql/check/dbs/SemiManualChecker.java +++ b/src/main/java/com/formulasearchengine/sql/check/dbs/SemiManualChecker.java @@ -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; @@ -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()); + + } + } }