Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,122 changes: 2,122 additions & 0 deletions P8-API/P8-API-Tests-Evaluation/Assets/routeBike.json

Large diffs are not rendered by default.

6,412 changes: 6,412 additions & 0 deletions P8-API/P8-API-Tests-Evaluation/Assets/routeBus.json

Large diffs are not rendered by default.

5,562 changes: 5,562 additions & 0 deletions P8-API/P8-API-Tests-Evaluation/Assets/routeCar.json

Large diffs are not rendered by default.

3,002 changes: 3,002 additions & 0 deletions P8-API/P8-API-Tests-Evaluation/Assets/routeData.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions P8-API/P8-API-Tests-Evaluation/Assets/transitStops.json

Large diffs are not rendered by default.

2,124 changes: 2,124 additions & 0 deletions P8-API/P8-API-Tests-Evaluation/Assets/tripBike.json

Large diffs are not rendered by default.

5,398 changes: 5,398 additions & 0 deletions P8-API/P8-API-Tests-Evaluation/Assets/tripBus.json

Large diffs are not rendered by default.

5,536 changes: 5,536 additions & 0 deletions P8-API/P8-API-Tests-Evaluation/Assets/tripCar.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions P8-API/P8-API-Tests-Evaluation/P8-API-Tests-Evaluation.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>P8_API_Tests_Evaluation</RootNamespace>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.10.2" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\P8-API\P8-API.csproj" />
</ItemGroup>

</Project>
61 changes: 61 additions & 0 deletions P8-API/P8-API-Tests-Evaluation/Services/ExtractionServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using MongoDB.Driver;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
using P8_API.Models;
using P8_API.Services;
using System.Collections.Generic;
using System.IO;

namespace P8_API_Tests_Evaluation.Services
{
class ExtractionServiceTests
{
private Mock<IMongoDatabase> _mockDB;
private ExtractionService _extractService;
private ExtractionClusterService _clusterExtractService;
private JsonSerializerSettings _settings;

[SetUp]
public void Setup()
{
_mockDB = new Mock<IMongoDatabase>();
_extractService = new ExtractionService(_mockDB.Object);
_clusterExtractService = new ExtractionClusterService(_mockDB.Object);

_settings = new JsonSerializerSettings() { Culture = new System.Globalization.CultureInfo("fr-FR") };
}

[TestCase("routeBike", ExpectedResult = 2)]
[TestCase("routeCar", ExpectedResult = 4)]
[TestCase("routeBus", ExpectedResult = 2)]
public int ExtractTrip(string filename)
{
// Arange
string positions = File.ReadAllText(@$"../../../Assets/{filename}.json");
List<Position> _testPositions = new List<Position>(JsonConvert.DeserializeObject<Position[]>(positions, _settings));

// Act
List<Trip> result = _extractService.ExtractTrips(_testPositions);

// Assert
return result.Count;
}

[TestCase("routeBike", ExpectedResult = 2)]
[TestCase("routeCar", ExpectedResult = 4)]
[TestCase("routeBus", ExpectedResult = 2)]
public int ExtractTripCluster(string filename)
{
// Arange
string positions = File.ReadAllText(@$"../../../Assets/{filename}.json");
List<Position> _testPositions = new List<Position>(JsonConvert.DeserializeObject<Position[]>(positions, _settings));

// Act
List<Trip> result = _clusterExtractService.ExtractTrips(_testPositions);

// Assert
return result.Count;
}
}
}
74 changes: 74 additions & 0 deletions P8-API/P8-API-Tests-Evaluation/Services/TripServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
using P8_API.Models;
using P8_API.Services;
using System;
using System.Collections.Generic;
using System.IO;

namespace P8_API_Tests_Evaluation.Services
{
class TripServiceTests
{
private Mock<IGoogleService> _googleService;
private Mock<IExtractionService> _extractionService;
private TripService _tripService;
List<TransitStop> _transitStops;

private JsonSerializerSettings _settings;

[SetUp]
public void Setup()
{
_extractionService = new Mock<IExtractionService>();
_googleService = new Mock<IGoogleService>();
_tripService = new TripService(_googleService.Object, _extractionService.Object);
_settings = new JsonSerializerSettings() { Culture = new System.Globalization.CultureInfo("fr-FR") };
// mock specific locations to be a busstation
_googleService.Setup(x => x.NearbyTransit(Convert.ToInt32(20), 59.330064, 18.0685984)).Returns(true);

// Mock transit stops
string transitStops = File.ReadAllText(@"../../../Assets/transitStops.json");
_transitStops = new List<TransitStop>(JsonConvert.DeserializeObject<TransitStop[]>(transitStops));
_googleService.Setup(x => x.NearbyTransit(It.IsAny<int>(), It.IsAny<double>(), It.IsAny<double>())).Returns<int, double, double>((arg0, arg1, arg2) => IsTransitStop(arg0, arg1, arg2));
}

private bool IsTransitStop(int range, double lattiude, double longitude)
{
foreach (TransitStop stop in _transitStops)
{
if (stop.Lattitude == lattiude && stop.Longitude == longitude)
{
return stop.Result;
}
}

return false;
}

[TestCase("tripBike", 0, ExpectedResult = Transport.Bike)]

[TestCase("tripCar", 0, ExpectedResult = Transport.Car)]
[TestCase("tripCar", 1, ExpectedResult = Transport.Car)]
[TestCase("tripCar", 2, ExpectedResult = Transport.Car)]
[TestCase("tripCar", 3, ExpectedResult = Transport.Car)]

[TestCase("tripBus", 0, ExpectedResult = Transport.Walk)]
[TestCase("tripBus", 1, ExpectedResult = Transport.Public)]
[TestCase("tripBus", 2, ExpectedResult = Transport.Public)]
public Transport PredictTransport(string filename, int tripIndex)
{
// Arange
string bikeTrips = File.ReadAllText(@$"../../../Assets/{filename}.json");
List<Trip> _testTrips = new List<Trip>(JsonConvert.DeserializeObject<Trip[]>(bikeTrips, _settings));
Trip selectedTrip = _testTrips[tripIndex];

// Act
Transport predictedTransport = _tripService.PredictTransport(selectedTrip);

// Assert
return predictedTransport;
}
}
}
Loading