Fix string validity check
This commit is contained in:
parent
cb5cb37bf0
commit
71e626c054
@ -16,7 +16,7 @@ appender.file.layout.type=PatternLayout
|
|||||||
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
|
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
|
||||||
|
|
||||||
|
|
||||||
#Création des loggers
|
#Création des loggers (par package)
|
||||||
|
|
||||||
loggers = console, commands, csv
|
loggers = console, commands, csv
|
||||||
|
|
||||||
|
@ -65,11 +65,11 @@ public class Read implements Callable <Void> {
|
|||||||
public Read(PrintStream out) {
|
public Read(PrintStream out) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check de l'extension csv (à améliorer)
|
||||||
|
public boolean isCsv(String file) {
|
||||||
|
return file.endsWith(".csv");
|
||||||
|
|
||||||
// public boolean isCsv(String file) {
|
}
|
||||||
// return file.endsWith(".csv");
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -138,7 +138,10 @@ public class Read implements Callable <Void> {
|
|||||||
logger.debug("Source : "+source_path);
|
logger.debug("Source : "+source_path);
|
||||||
|
|
||||||
|
|
||||||
|
if (!isCsv(result_name)) {
|
||||||
|
result_name = result_name+".csv";
|
||||||
|
logger.info("Result file name changed to '"+result_name+"'");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -147,9 +150,9 @@ public class Read implements Callable <Void> {
|
|||||||
|
|
||||||
String filePath = new File("").getAbsolutePath();
|
String filePath = new File("").getAbsolutePath();
|
||||||
|
|
||||||
|
// Instantie l'OCR
|
||||||
GestionnaireCopies ocr = new GestionnaireCopies("../"+directory_name);
|
GestionnaireCopies ocr = new GestionnaireCopies("../"+directory_name);
|
||||||
// Instantie l'ocr
|
|
||||||
|
|
||||||
logger.debug("CSV initialized with : "+ocr.createHashMapforCSV()+" , "+config.getParam().get("Code")+" , "+result_name);
|
logger.debug("CSV initialized with : "+ocr.createHashMapforCSV()+" , "+config.getParam().get("Code")+" , "+result_name);
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public class GenerateCSV {
|
|||||||
int nb = Character.getNumericValue(s.charAt(i));
|
int nb = Character.getNumericValue(s.charAt(i));
|
||||||
|
|
||||||
|
|
||||||
if (nb <= 0 || nb >= 9) {
|
if (nb < 0 || nb > 9) {
|
||||||
|
|
||||||
logger.fatal("Student id's characters are not recognized");
|
logger.fatal("Student id's characters are not recognized");
|
||||||
return false;
|
return false;
|
||||||
@ -72,12 +72,12 @@ public class GenerateCSV {
|
|||||||
// Si etudiant HashMap est null, pas ecrit
|
// Si etudiant HashMap est null, pas ecrit
|
||||||
if (etud != null) {
|
if (etud != null) {
|
||||||
|
|
||||||
//if (this.isValid(etud)) {
|
if (this.isValid(etud)) {
|
||||||
writer.write(etud + ";" + etudiants.get(etud) + System.getProperty("line.separator"));
|
writer.write(etud + ";" + etudiants.get(etud) + System.getProperty("line.separator"));
|
||||||
//}
|
}
|
||||||
// else {
|
else {
|
||||||
// logger.debug("Invalid id not added to csv");
|
logger.debug("Invalid id not added to csv");
|
||||||
// }
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import org.junit.jupiter.api.Test;
|
|||||||
import ch.qos.logback.classic.Level;
|
import ch.qos.logback.classic.Level;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
import picocli.CommandLine.Command;
|
import picocli.CommandLine.Command;
|
||||||
import picocli.CommandLine.HelpCommand;
|
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "TestRead",
|
name = "TestRead",
|
||||||
|
@ -1,47 +1,68 @@
|
|||||||
package csv;
|
package csv;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
||||||
public class TestCSV {
|
public class TestCSV {
|
||||||
|
|
||||||
// @Test
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
// public void createNullCSV() {
|
String length = "8";
|
||||||
// //We check if a CSV object cannot be created !
|
String path = "../export/result.csv";
|
||||||
// CSV c = new CSV();
|
GenerateCSV csv = new GenerateCSV(map,length,path);
|
||||||
// assertEquals(null, c.getStudentNumber());
|
|
||||||
// assertEquals(.0, c.getGrade());
|
@BeforeEach
|
||||||
// }
|
void setUp() {
|
||||||
//
|
map = new HashMap<String,String>();
|
||||||
// @Test
|
length = "8";
|
||||||
// public void checkFalseStudentnumber() {
|
path = "../export/result.csv";
|
||||||
// //We check if the student number is full composed of numeric digits !
|
}
|
||||||
// String s = "056498a198";
|
|
||||||
// assertEquals(false, CSV.checkStudentNumber(s));
|
@Test
|
||||||
// }
|
void testNotNull() {
|
||||||
//
|
|
||||||
// @Test
|
map.put("21705239", "17");
|
||||||
// public void checkStudentNumberTooShort() {
|
csv = new GenerateCSV(map,length,path);
|
||||||
// //We check if the student number is enought long !
|
|
||||||
// String s = "";
|
assertFalse(csv == null);
|
||||||
// assertEquals(false, CSV.checkStudentNumber(s));
|
}
|
||||||
// }
|
|
||||||
//
|
@Test
|
||||||
//
|
void testValid() {
|
||||||
// @Test
|
|
||||||
// public void checkStudentNumberTooLong() {
|
map.put("21435712", "9");
|
||||||
// //We check if the student number is enought short !
|
map.put("21705239", "17");
|
||||||
// String s = "012345678910111213141516";
|
csv = new GenerateCSV(map,length,path);
|
||||||
// assertEquals(false, CSV.checkStudentNumber(s));
|
|
||||||
// }
|
for (String etud : csv.etudiants.keySet()) {
|
||||||
//
|
assertTrue(csv.isValid(etud));
|
||||||
// @Test
|
}
|
||||||
// public void checkCorrectStudentNumber() {
|
|
||||||
// //We check if the student number is correct !
|
}
|
||||||
// String s = "123456789";
|
|
||||||
// assertEquals(true, CSV.checkStudentNumber(s));
|
|
||||||
// }
|
@Test
|
||||||
|
void testNotValid() {
|
||||||
|
|
||||||
|
map.put("21435", "9");
|
||||||
|
map.put("1705239", "17");
|
||||||
|
csv = new GenerateCSV(map,length,path);
|
||||||
|
|
||||||
|
for (String etud : csv.etudiants.keySet()) {
|
||||||
|
assertFalse(csv.isValid(etud));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGeneration() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user