Bugs resolved

This commit is contained in:
AngeHerman 2024-04-08 14:18:18 +02:00
parent ce8a801322
commit 06d80926e0
6 changed files with 51 additions and 29 deletions

View file

@ -105,12 +105,14 @@ public class CSVSchedulesProvider {
}
}
public String[][] next() {
public String[] next() {
if (!hasNext()) {
return null;
}
skipToNext();
return new String[][]{Arrays.copyOf(this.line, this.line.length)};
return Arrays.copyOf(this.line, this.line.length);
// return new String[][]{Arrays.copyOf(this.line, this.line.length)};
}

View file

@ -130,7 +130,7 @@ public final class CSVStreamProvider {
} while (currentSegmentStart == null);
}
public String[][] next() {
public String[] next() {
if (!this.onNext) {
skipToNext();
}
@ -148,7 +148,9 @@ public final class CSVStreamProvider {
this.line[NetworkFormat.VARIANT_INDEX] = Integer
.toString(bifurcation);
fillTransports(bifurcation);
return new String[][]{Arrays.copyOf(this.line, this.line.length)};
return Arrays.copyOf(this.line, this.line.length);
// return new String[][]{Arrays.copyOf(this.line, this.line.length)};
}
/** @param stop1
@ -182,6 +184,7 @@ public final class CSVStreamProvider {
}
private void fillTransports(int bif) {
if(transports != null){
String nameTransport = this.line[NetworkFormat.LINE_INDEX];
String start_p = this.line[NetworkFormat.START_INDEX];
String end_p = this.line[NetworkFormat.STOP_INDEX];
@ -199,5 +202,7 @@ public final class CSVStreamProvider {
}
}
}
}

View file

@ -69,13 +69,28 @@ public final class CSVTools {
* @throws IOException if we can't write the data into the file
*/
public static void writeCSVToFile(String filename,
Stream<String[][]> contentLinesConsumer) throws IOException {
Stream<String[]> contentLinesConsumer) throws IOException {
try (FileWriter writer = new FileWriter(filename, StandardCharsets.UTF_8)) {
CSVWriterBuilder wBuilder = new CSVWriterBuilder(writer).withSeparator(';');
try (ICSVWriter csv = wBuilder.build()) {
contentLinesConsumer.forEachOrdered(line -> Arrays.stream(line).forEach(csv::writeNext));
contentLinesConsumer.forEachOrdered(csv::writeNext);
}
}
}
// /** Save our current CSV variable's data into an actual file
// * @param filename the saved file's name and path
// * @param contentLineConsumer our data variable
// * @throws IOException if we can't write the data into the file
// */
// public static void writeCSVToFile(String filename,
// Stream<String[][]> contentLinesConsumer) throws IOException {
// try (FileWriter writer = new FileWriter(filename, StandardCharsets.UTF_8)) {
// CSVWriterBuilder wBuilder = new CSVWriterBuilder(writer).withSeparator(';');
// try (ICSVWriter csv = wBuilder.build()) {
// contentLinesConsumer.forEachOrdered(line -> Arrays.stream(line).forEach(csv::writeNext));
// }
// }
// }
}

View file

@ -21,7 +21,7 @@ public class CSVStreamProviderTest {
@Test
public void testHasNext() {
// Scénario sans Trace
CSVStreamProvider providerWithoutTrace = new CSVStreamProvider(Collections.emptyIterator());
CSVStreamProvider providerWithoutTrace = new CSVStreamProvider(Collections.emptyIterator(),null);
assertFalse(providerWithoutTrace.hasNext(), "hasNext should return false when no traces are provided");
// Scénario avec Trace
@ -29,10 +29,10 @@ public class CSVStreamProviderTest {
StopEntry stop2 = new StopEntry("Stop2", 2.295, 48.8738);
List<StopEntry> path = Arrays.asList(stop1, stop2);
TraceEntry trace = new TraceEntry("Ligne1");
TraceEntry trace = new TraceEntry("Ligne1","IDFM:03434","Bus");
trace.addPath(path);
CSVStreamProvider providerWithTrace = new CSVStreamProvider(Arrays.asList(trace).iterator());
CSVStreamProvider providerWithTrace = new CSVStreamProvider(Arrays.asList(trace).iterator(),null);
assertTrue(providerWithTrace.hasNext(), "hasNext should return true when traces are provided");
}
@ -45,10 +45,10 @@ public class CSVStreamProviderTest {
StopEntry start = new StopEntry("Début", 2.3522, 48.8566); // Paris
StopEntry end = new StopEntry("Fin", 2.295, 48.8738); // Proche de Paris
TraceEntry traceEntry = new TraceEntry("Ligne1");
TraceEntry traceEntry = new TraceEntry("Ligne1","IDFM:03434","Bus");
traceEntry.addPath(Arrays.asList(start, end)); // Ajout d'un chemin à la trace
CSVStreamProvider provider = new CSVStreamProvider(Collections.singletonList(traceEntry).iterator());
CSVStreamProvider provider = new CSVStreamProvider(Collections.singletonList(traceEntry).iterator(),null);
assertTrue(provider.hasNext(), "Doit avoir un prochain élément");

View file

@ -43,7 +43,7 @@ class IDFMNetworkExtractorTest {
public void testAddCandidate() throws Exception {
UnidentifiedStopEntry unidentifiedStop = new UnidentifiedStopEntry(2.3522, 48.8566); // Coordonnées pour Paris
List<StopEntry> path = new ArrayList<>(Arrays.asList(unidentifiedStop));
TraceEntry trace = new TraceEntry("Ligne1");
TraceEntry trace = new TraceEntry("Ligne1","IDFM:03434","Bus");
trace.addPath(path);
StopEntry candidate = new StopEntry("Proche Candidat", 2.3523, 48.8567); // Coordonnées proches

View file

@ -9,7 +9,7 @@ public class TraceEntryTest {
//addTerminus
@Test
public void testAddTerminus() {
TraceEntry traceEntry = new TraceEntry("Ligne 1");
TraceEntry traceEntry = new TraceEntry("Ligne 1","IDFM:03434","Bus");
String terminus1 = "Terminus A";
String terminus2 = "Terminus B";
@ -26,7 +26,7 @@ public class TraceEntryTest {
//addPath
@Test
public void testAddPath() {
TraceEntry traceEntry = new TraceEntry("Ligne 1");
TraceEntry traceEntry = new TraceEntry("Ligne 1","IDFM:03434","Bus");
StopEntry stop1 = new StopEntry("Station 1", 2.300, 48.850);
StopEntry stop2 = new StopEntry("Station 2", 2.310, 48.855);
List<StopEntry> path = Arrays.asList(stop1, stop2);
@ -42,7 +42,7 @@ public class TraceEntryTest {
//Verfier si le nom de la ligne lname est correctement initialiser
@Test
public void testTraceEntryName() {
TraceEntry traceEntry = new TraceEntry("Ligne 1");
TraceEntry traceEntry = new TraceEntry("Ligne 1","IDFM:03434","Bus");
assertEquals("Ligne 1", traceEntry.lname, "Le nom de la ligne doit être 'Ligne 1'.");
}
}