Skip to content

Commit

Permalink
Merge pull request #312 from HSLdevcom/fix-sharingos
Browse files Browse the repository at this point in the history
Fix sharingos seems good.
  • Loading branch information
Antiik91 authored Jun 20, 2019
2 parents bb3e22e + d9b993f commit a1a6705
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ public BikeRentalStation makeStation(JsonNode node) {
station.x = node.path("longitude").asDouble();
if (node.path("is_enable").asInt() == 0) {
station.state = "Station on";
station.spacesAvailable = node.path("available_capacity").asInt();
station.bikesAvailable = node.path("total_capacity").asInt() - station.spacesAvailable;
station.bikesAvailable = node.path("available_capacity").asInt() < 0 ? 0 :
node.path("available_capacity").asInt();
station.spacesAvailable = station.bikesAvailable >
node.path("total_capacity").asInt() ? 0 :
node.path("total_capacity").asInt() - station.bikesAvailable;
} else if (node.path("is_enable").asInt() == 1) {
station.state = "Station off";
station.spacesAvailable = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void testSharingos() {
assertTrue(source.update());
List<BikeRentalStation> rentalStations = source.getStations();

assertEquals(3, rentalStations.size());
assertEquals(4, rentalStations.size());
for (BikeRentalStation rentalStation : rentalStations) {
System.out.println(rentalStation);
}
Expand Down Expand Up @@ -160,10 +160,19 @@ public void testSharingos() {
assertEquals("1003", openTestStation.id);
assertEquals(25.0424261, openTestStation.x);
assertEquals(60.2932159, openTestStation.y);
assertEquals(2, openTestStation.spacesAvailable);
assertEquals(3, openTestStation.bikesAvailable);
assertEquals(3, openTestStation.spacesAvailable);
assertEquals(2, openTestStation.bikesAvailable);
assertEquals("Station on", openTestStation.state);

BikeRentalStation overflowTestStation = rentalStations.get(3);
assertEquals("Overflow test station", overflowTestStation.name.toString());
assertEquals("1004", overflowTestStation.id);
assertEquals(25.0434261, overflowTestStation.x);
assertEquals(60.2931159, overflowTestStation.y);
assertEquals(0, overflowTestStation.spacesAvailable);
assertEquals(7, overflowTestStation.bikesAvailable);
assertEquals("Station on", overflowTestStation.state);

// Test giving network name to data source
SharingOSBikeRentalDataSource sourceWithCustomNetwork = new SharingOSBikeRentalDataSource("vantaa");
sourceWithCustomNetwork.setUrl("file:src/test/resources/bike/sharingos.json");
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/bike/sharingos.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
"discount": 0,
"is_enable": 0,
"update_time": "2019-05-22T11:15:02+08:00"
},
{
"id": 1004,
"name": "Overflow test station",
"latitude": 60.2931159,
"longitude": 25.0434261,
"total_capacity": 5,
"available_capacity": 7,
"discount": 0,
"is_enable": 0,
"update_time": "2019-05-22T11:15:02+08:00"
}
]
}

0 comments on commit a1a6705

Please sign in to comment.