From 0ac411e9d3794ae6487afafbfe362061158fb99a Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Sun, 9 Jun 2024 19:59:22 +0200 Subject: [PATCH] Fixed search, random_destination method return ArrayList sizes, implemented random_destination tests and build ran successful --- src/main/java/de/hs_mannheim/domain/System.java | 8 ++++---- .../java/de/hs_mannheim/domain/SystemTest.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index be85240..37e298a 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -72,8 +72,8 @@ public class System { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { String line; - while ((line = reader.readLine()) != null) { - if(line.contains(hometown_or_zip)&&zip_set.size()<200){ + while ((line = reader.readLine()) != null && zip_set.size()<200) { + if(line.contains(hometown_or_zip)){ line = line.replace("\"", ""); zip_set.add(line); } @@ -91,7 +91,7 @@ public class System { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { String line; - while ((line = reader.readLine()) != null) { + while ((line = reader.readLine()) != null && result.size()<3) { line = line.replace("\"", ""); @@ -111,7 +111,7 @@ public class System { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { String line; - while ((line = reader.readLine()) != null) { + while ((line = reader.readLine()) != null && result.size()<3) { line = line.replace("\"", ""); diff --git a/src/test/java/de/hs_mannheim/domain/SystemTest.java b/src/test/java/de/hs_mannheim/domain/SystemTest.java index d84d42b..3ac1f7e 100644 --- a/src/test/java/de/hs_mannheim/domain/SystemTest.java +++ b/src/test/java/de/hs_mannheim/domain/SystemTest.java @@ -82,4 +82,20 @@ public class SystemTest { assertEquals("60.361 l", current_system.calc_l_consumption("10115")); // Kraftstoffverbrauch nach Berlin } + @Test + public void random_destinations(){ + + System current_system = new System("35a75437476f12302f72e55d368485db"); + + current_system.set_current_user_zip("68161"); + + assertEquals(3, current_system.random_destinations_car().size()); // random_destinations_car gibt genau 3 destinations zurück + assertEquals(3, current_system.random_destinations_bike().size()); // random destinations_bike gibt genau 3 destinations zurück + + // random_destinations_car gibt nur destinations mit mindestens 150 km Entfernung zurück + assertEquals(true, Double.parseDouble(current_system.distance(current_system.random_destinations_car().get(0).split(";")[0]).replace(" km", "")) > 150); + // random_destinations_bike gibt nur destinations mit maximal 100 km Entfernung zurück + assertEquals(true, Double.parseDouble(current_system.distance(current_system.random_destinations_bike().get(0).split(";")[0]).replace(" km", "")) < 100); + } + }