From 4db502c8cadd83640a49d7e5f5c35f17d6d78496 Mon Sep 17 00:00:00 2001 From: sakimotor Date: Mon, 11 Mar 2024 17:00:43 +0100 Subject: [PATCH 1/7] GPS distance tests --- .../fr/u_paris/gla/project/utils/GPSTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/test/java/fr/u_paris/gla/project/utils/GPSTest.java diff --git a/src/test/java/fr/u_paris/gla/project/utils/GPSTest.java b/src/test/java/fr/u_paris/gla/project/utils/GPSTest.java new file mode 100644 index 0000000..de63357 --- /dev/null +++ b/src/test/java/fr/u_paris/gla/project/utils/GPSTest.java @@ -0,0 +1,39 @@ +package fr.u_paris.gla.project.utils; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class GPSTest { + + + @Test + void distance_SameLat(){ + assertDoesNotThrow( + () -> { + GPS.distance(5, 3, 5, 11); + } + ); + } + + @Test + void distance_SameLon(){ + assertDoesNotThrow( + () -> { + GPS.distance(5, 3, 7, 3); + } + ); + } + + @Test + void distance_SamePoint() { + assertEquals(0.0, GPS.distance(5, 3, 5, 3) ); + } + + @Test + void distance_NegativePoint(){ + assertNotEquals(0.0, GPS.distance(-5, 7, -13, 4)); + } + + +} \ No newline at end of file From f37e5596f0396cfa7df1c637fa7294cb1db06bcf Mon Sep 17 00:00:00 2001 From: sakimotor Date: Mon, 11 Mar 2024 18:04:41 +0100 Subject: [PATCH 2/7] CSVTools Tests --- .../gla/project/utils/CSVToolsTest.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java diff --git a/src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java b/src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java new file mode 100644 index 0000000..6ab4895 --- /dev/null +++ b/src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java @@ -0,0 +1,76 @@ +package fr.u_paris.gla.project.utils; + + +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.Arrays; + +import java.util.function.Consumer; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.*; + +class CSVToolsTest { + + + + + @Test + void readCSVFromURL_invalid() { + assertThrowsExactly(IOException.class,() -> { + Consumer test = s -> System.out.println(Arrays.toString(s)); + CSVTools.readCSVFromURL("https://google.fr", + test); + + } + ); + } + + @Test + void readCSVFromURL_valid() { + assertDoesNotThrow(() -> { + Consumer test = s -> System.out.println(Arrays.toString(s)); + CSVTools.readCSVFromURL("https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv", + test); + + } + ); + } + + @Test + void writeCSVToFile() { + + assertDoesNotThrow(() -> { + String[] stuff = {"jsqdsqdsqsqffdfgzava", "pfezegrrbeebn", "dfbsduifzegbczi", "sdfsdfcy"}; + String[][] t = {stuff, stuff}; + Stream test = Arrays.stream(t); + CSVTools.writeCSVToFile("test.csv", test); + + }); + } + + @Test + void writeCSVToFile_specialName() { + + assertDoesNotThrow(() -> { + String[] stuff = {"jsqdsqdsqsqffdfgzava", "pfezegrrbeebn", "dfbsduifzegbczi", "sdfsdfcy"}; + String[][] t = {stuff, stuff}; + Stream test = Arrays.stream(t); + CSVTools.writeCSVToFile("éè'-'_-éè_à.csv", test); + + }); + } + + @Test + void writeCSVToFile_invalidName() { + + assertThrows( IOException.class ,() -> { + String[] stuff = {"jsqdsqdsqsqffdfgzava", "pfezegrrbeebn", "dfbsduifzegbczi", "sdfsdfcy"}; + String[][] t = {stuff, stuff}; + Stream test = Arrays.stream(t); + CSVTools.writeCSVToFile(".", test); + + }); + } +} \ No newline at end of file From 481a59afbc0ed7311490e59d07040a470ee8bb5d Mon Sep 17 00:00:00 2001 From: MAMBILA TETE jean philipp <@mambilat> Date: Mon, 11 Mar 2024 18:10:44 +0100 Subject: [PATCH 3/7] CSVTools Tests --- src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java b/src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java index 6ab4895..0fbd4c8 100644 --- a/src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java +++ b/src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java @@ -18,7 +18,7 @@ class CSVToolsTest { @Test void readCSVFromURL_invalid() { - assertThrowsExactly(IOException.class,() -> { + assertThrows(IOException.class,() -> { Consumer test = s -> System.out.println(Arrays.toString(s)); CSVTools.readCSVFromURL("https://google.fr", test); From 6048d843b4e576b72cb55f7c89572d749d66c021 Mon Sep 17 00:00:00 2001 From: MAMBILA TETE jean philipp <@mambilat> Date: Mon, 18 Mar 2024 10:20:44 +0100 Subject: [PATCH 4/7] CSVTools Tests --- .../gla/project/io/NetworkFormatTest.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/test/java/fr/u_paris/gla/project/io/NetworkFormatTest.java diff --git a/src/test/java/fr/u_paris/gla/project/io/NetworkFormatTest.java b/src/test/java/fr/u_paris/gla/project/io/NetworkFormatTest.java new file mode 100644 index 0000000..a46f12d --- /dev/null +++ b/src/test/java/fr/u_paris/gla/project/io/NetworkFormatTest.java @@ -0,0 +1,80 @@ +package fr.u_paris.gla.project.io; + +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.text.NumberFormat; +import java.time.Duration; +import java.time.LocalTime; +import java.time.format.DateTimeParseException; + +import static org.junit.jupiter.api.Assertions.*; + +class NetworkFormatTest { + + String t = "00:00"; + NumberFormat GPS_test = NetworkFormat.getGPSFormatter(); + + @Test + void parseDurationEqual() { + + assertEquals(Duration.ZERO, NetworkFormat.parseDuration(t)); + } + + @Test + void parseDurationTooBig() { + String y = "119:00"; + assertThrows(DateTimeParseException.class, () -> NetworkFormat.parseDuration(y)); + } + + @Test + void formatDuration() { + assertEquals(t, NetworkFormat.formatDuration(Duration.ZERO)); + } + + @Test + void parseThenFormatDuration(){ + String t = "00:00"; + assertEquals(t, NetworkFormat.formatDuration(NetworkFormat.parseDuration(t))); + } + + @Test + void getGPSFormatterPos() { + double GPS_pos = 1.456489615649813; + assertEquals(String.valueOf(GPS_pos), GPS_test.format(GPS_pos)); + + + } + + @Test + void getGPSFormatterNeg() { + double GPS_neg = -1.456489615649813; + assertEquals(String.valueOf(GPS_neg), GPS_test.format(GPS_neg)); + + + } + @Test + void getGPSFormatterNul() { + int GPS_nul = 0; + assertEquals(String.valueOf(GPS_nul), GPS_test.format(GPS_nul)); + + + } + + @Test + void getGPSFormatterBig() { + String string_int = "4565156498156489"; + String string_float = "5675747274674276474267479751262167"; + BigDecimal GPS_big = new BigDecimal(string_int + "." + string_float); + + + assertEquals(string_int + "." + string_float.substring(0, NetworkFormat.GPS_PRECISION), + GPS_test.format(GPS_big).replace(",", "").replace(" ","")); + + + } + + + +} \ No newline at end of file From 1c291b3142fbf124b579a7c5bcadf7303b1cd8a2 Mon Sep 17 00:00:00 2001 From: MAMBILA TETE jean philipp <@mambilat> Date: Mon, 18 Mar 2024 16:41:29 +0100 Subject: [PATCH 5/7] Tests for classes ScheduleFormat and NetworkFormat complete. --- .../gla/project/io/ScheduleFormatTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/test/java/fr/u_paris/gla/project/io/ScheduleFormatTest.java diff --git a/src/test/java/fr/u_paris/gla/project/io/ScheduleFormatTest.java b/src/test/java/fr/u_paris/gla/project/io/ScheduleFormatTest.java new file mode 100644 index 0000000..4b0f749 --- /dev/null +++ b/src/test/java/fr/u_paris/gla/project/io/ScheduleFormatTest.java @@ -0,0 +1,33 @@ +package fr.u_paris.gla.project.io; + +import org.junit.jupiter.api.Test; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +class ScheduleFormatTest { + + @Test + void getTripSequence() { + String rpz = "4, 5, 19, 21"; + List test = Arrays.asList(4, 5, 19, 21); + + assertEquals(test, ScheduleFormat.getTripSequence(rpz)); + } + + @Test + void getTimeFormatter() { + DateTimeFormatter formatter = ScheduleFormat.getTimeFormatter(); + LocalDateTime date = LocalDateTime.now(); + String test = date.format(formatter); + //format date: YYYY-MM-DDTHH:MM:SS.DECIMAL + assertEquals(date.toString().substring(11, 16), test); + + + } +} \ No newline at end of file From a70ac82141fd1a26b8e6680a5899a0926fdee050 Mon Sep 17 00:00:00 2001 From: MAMBILA TETE jean philipp <@mambilat> Date: Mon, 18 Mar 2024 16:59:27 +0100 Subject: [PATCH 6/7] Fix methods in ScheduleFormat and NetworkFormat --- .../java/fr/u_paris/gla/project/io/NetworkFormat.java | 8 ++++---- .../java/fr/u_paris/gla/project/io/ScheduleFormat.java | 10 +++++++--- .../fr/u_paris/gla/project/io/ScheduleFormatTest.java | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/fr/u_paris/gla/project/io/NetworkFormat.java b/src/main/java/fr/u_paris/gla/project/io/NetworkFormat.java index ff95c99..0113744 100644 --- a/src/main/java/fr/u_paris/gla/project/io/NetworkFormat.java +++ b/src/main/java/fr/u_paris/gla/project/io/NetworkFormat.java @@ -33,10 +33,10 @@ public final class NetworkFormat { private static final DateTimeFormatter DURATION_FORMATTER = DateTimeFormatter .ofPattern("HH:mm:ss"); - private static final NumberFormat DURATION_SECONDS_FORMATTER = NumberFormat + private static final NumberFormat DURATION_INDIVIDUAL_FORMATTER = NumberFormat .getIntegerInstance(Locale.ENGLISH); static { - DURATION_SECONDS_FORMATTER.setMinimumIntegerDigits(2); + DURATION_INDIVIDUAL_FORMATTER.setMinimumIntegerDigits(2); } private static final Temporal ZERO = LocalTime.parse("00:00:00"); @@ -51,8 +51,8 @@ public final class NetworkFormat { } public static String formatDuration(Duration duration) { - return Long.toString(duration.toMinutes()) + ":" - + DURATION_SECONDS_FORMATTER.format(duration.toSecondsPart()); + return DURATION_INDIVIDUAL_FORMATTER.format(duration.toMinutes()) + ":" + + DURATION_INDIVIDUAL_FORMATTER.format(duration.toSecondsPart()); } /** Get a formatter for the numbers in a GPS coordinate pair diff --git a/src/main/java/fr/u_paris/gla/project/io/ScheduleFormat.java b/src/main/java/fr/u_paris/gla/project/io/ScheduleFormat.java index fc4d4ba..8a86594 100644 --- a/src/main/java/fr/u_paris/gla/project/io/ScheduleFormat.java +++ b/src/main/java/fr/u_paris/gla/project/io/ScheduleFormat.java @@ -5,6 +5,7 @@ package fr.u_paris.gla.project.io; import java.time.format.DateTimeFormatter; import java.time.format.ResolverStyle; +import java.util.ArrayList; import java.util.List; /** @@ -32,10 +33,13 @@ public final class ScheduleFormat { * @return the sequence of branching */ public static List getTripSequence(String representation) { - // TODO Read a trip sequence from a string - throw new RuntimeException("Not implemented yet"); - } + List l = new ArrayList<>(); + for(String s : representation.split(",")) + l.add(Integer.parseInt(s)); + return l; + } + public static DateTimeFormatter getTimeFormatter() { return DateTimeFormatter.ofPattern("HH:mm").withResolverStyle(ResolverStyle.LENIENT); diff --git a/src/test/java/fr/u_paris/gla/project/io/ScheduleFormatTest.java b/src/test/java/fr/u_paris/gla/project/io/ScheduleFormatTest.java index 4b0f749..f9eae35 100644 --- a/src/test/java/fr/u_paris/gla/project/io/ScheduleFormatTest.java +++ b/src/test/java/fr/u_paris/gla/project/io/ScheduleFormatTest.java @@ -13,8 +13,8 @@ import static org.junit.jupiter.api.Assertions.*; class ScheduleFormatTest { @Test - void getTripSequence() { - String rpz = "4, 5, 19, 21"; + public void getTripSequence() { + String rpz = "4,5,19,21"; List test = Arrays.asList(4, 5, 19, 21); assertEquals(test, ScheduleFormat.getTripSequence(rpz)); From 6f4af5c428f84df868ae6142b02ed1cff36d6a71 Mon Sep 17 00:00:00 2001 From: MAMBILA TETE jean philipp <@mambilat> Date: Mon, 18 Mar 2024 18:05:47 +0100 Subject: [PATCH 7/7] JavaDoc CSVTools --- .../java/fr/u_paris/gla/project/io/NetworkFormat.java | 8 ++++++++ .../java/fr/u_paris/gla/project/io/ScheduleFormat.java | 3 +++ .../java/fr/u_paris/gla/project/utils/CSVTools.java | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/main/java/fr/u_paris/gla/project/io/NetworkFormat.java b/src/main/java/fr/u_paris/gla/project/io/NetworkFormat.java index 0113744..11663dd 100644 --- a/src/main/java/fr/u_paris/gla/project/io/NetworkFormat.java +++ b/src/main/java/fr/u_paris/gla/project/io/NetworkFormat.java @@ -45,11 +45,19 @@ public final class NetworkFormat { // Tool class } + /** Convert a {@link java.lang.String} into a {@link java.time.Duration} + * @param duration the {@link java.lang.String} + * @return the {@link java.time.Duration} object + */ public static Duration parseDuration(String duration) { LocalTime time = LocalTime.parse("00:" + duration, DURATION_FORMATTER); return Duration.between(time, ZERO); } + /** Format a {@link java.time.Duration} into a {@link java.lang.String} + * @param duration an object of type {@link java.time.Duration} + * @return a String that depicts the duration in format MM:SS + */ public static String formatDuration(Duration duration) { return DURATION_INDIVIDUAL_FORMATTER.format(duration.toMinutes()) + ":" + DURATION_INDIVIDUAL_FORMATTER.format(duration.toSecondsPart()); diff --git a/src/main/java/fr/u_paris/gla/project/io/ScheduleFormat.java b/src/main/java/fr/u_paris/gla/project/io/ScheduleFormat.java index 8a86594..c97b233 100644 --- a/src/main/java/fr/u_paris/gla/project/io/ScheduleFormat.java +++ b/src/main/java/fr/u_paris/gla/project/io/ScheduleFormat.java @@ -41,6 +41,9 @@ public final class ScheduleFormat { } + /** Create a {@link java.time.format.DateTimeFormatter} object used to format Dates + * @return the formatter + */ public static DateTimeFormatter getTimeFormatter() { return DateTimeFormatter.ofPattern("HH:mm").withResolverStyle(ResolverStyle.LENIENT); } diff --git a/src/main/java/fr/u_paris/gla/project/utils/CSVTools.java b/src/main/java/fr/u_paris/gla/project/utils/CSVTools.java index b3194f9..5332a41 100644 --- a/src/main/java/fr/u_paris/gla/project/utils/CSVTools.java +++ b/src/main/java/fr/u_paris/gla/project/utils/CSVTools.java @@ -32,6 +32,11 @@ public final class CSVTools { // Tool class } + /** get a CSV file from a URL, download and parse it, and keep values in memory + * @param url the address of the CSV file + * @param contentLineConsumer the variable used to store the data + * @throws IOException if it's impossible to download the file + */ public static void readCSVFromURL(String url, Consumer contentLineConsumer) throws IOException { ICSVParser parser = new CSVParserBuilder().withSeparator(';').build(); @@ -52,6 +57,11 @@ public final class CSVTools { } } + /** 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 contentLineConsumer) throws IOException { try (FileWriter writer = new FileWriter(filename, StandardCharsets.UTF_8)) {