Fix string validity check

This commit is contained in:
Louis Calas 2019-10-10 09:30:35 +02:00
parent cb5cb37bf0
commit 71e626c054
5 changed files with 78 additions and 55 deletions

View File

@ -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
#Création des loggers
#Création des loggers (par package)
loggers = console, commands, csv

View File

@ -65,11 +65,11 @@ public class Read implements Callable <Void> {
public Read(PrintStream out) {
}
// public boolean isCsv(String file) {
// return file.endsWith(".csv");
//
// }
// Check de l'extension csv (à améliorer)
public boolean isCsv(String file) {
return file.endsWith(".csv");
}
@Override
@ -138,7 +138,10 @@ public class Read implements Callable <Void> {
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();
// Instantie l'OCR
GestionnaireCopies ocr = new GestionnaireCopies("../"+directory_name);
// Instantie l'ocr
logger.debug("CSV initialized with : "+ocr.createHashMapforCSV()+" , "+config.getParam().get("Code")+" , "+result_name);

View File

@ -36,7 +36,7 @@ public class GenerateCSV {
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");
return false;
@ -72,12 +72,12 @@ public class GenerateCSV {
// Si etudiant HashMap est null, pas ecrit
if (etud != null) {
//if (this.isValid(etud)) {
if (this.isValid(etud)) {
writer.write(etud + ";" + etudiants.get(etud) + System.getProperty("line.separator"));
//}
// else {
// logger.debug("Invalid id not added to csv");
// }
}
else {
logger.debug("Invalid id not added to csv");
}
} else {

View File

@ -8,7 +8,6 @@ import org.junit.jupiter.api.Test;
import ch.qos.logback.classic.Level;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.HelpCommand;
@Command(
name = "TestRead",

View File

@ -1,47 +1,68 @@
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;
public class TestCSV {
Map<String,String> map = new HashMap<String,String>();
String length = "8";
String path = "../export/result.csv";
GenerateCSV csv = new GenerateCSV(map,length,path);
@BeforeEach
void setUp() {
map = new HashMap<String,String>();
length = "8";
path = "../export/result.csv";
}
@Test
void testNotNull() {
map.put("21705239", "17");
csv = new GenerateCSV(map,length,path);
assertFalse(csv == null);
}
@Test
void testValid() {
map.put("21435712", "9");
map.put("21705239", "17");
csv = new GenerateCSV(map,length,path);
for (String etud : csv.etudiants.keySet()) {
assertTrue(csv.isValid(etud));
}
}
@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() {
}
// @Test
// public void createNullCSV() {
// //We check if a CSV object cannot be created !
// CSV c = new CSV();
// assertEquals(null, c.getStudentNumber());
// assertEquals(.0, c.getGrade());
// }
//
// @Test
// public void checkFalseStudentnumber() {
// //We check if the student number is full composed of numeric digits !
// String s = "056498a198";
// assertEquals(false, CSV.checkStudentNumber(s));
// }
//
// @Test
// public void checkStudentNumberTooShort() {
// //We check if the student number is enought long !
// String s = "";
// assertEquals(false, CSV.checkStudentNumber(s));
// }
//
//
// @Test
// public void checkStudentNumberTooLong() {
// //We check if the student number is enought short !
// String s = "012345678910111213141516";
// assertEquals(false, CSV.checkStudentNumber(s));
// }
//
// @Test
// public void checkCorrectStudentNumber() {
// //We check if the student number is correct !
// String s = "123456789";
// assertEquals(true, CSV.checkStudentNumber(s));
// }
}
}