fix pricing (km instead of meters)
This commit is contained in:
parent
9b091bc041
commit
a81c1eb33c
|
@ -16,12 +16,12 @@ func (s *MMS43PricingService) Prices(params PricingParams) (map[string]Price, er
|
||||||
// Trip is free
|
// Trip is free
|
||||||
passengerAmount = 0.0
|
passengerAmount = 0.0
|
||||||
} else {
|
} else {
|
||||||
// Price is 0.15€/km for passenger distance (convert meters to km)
|
// Price is 0.15€/km for passenger distance
|
||||||
passengerAmount = 0.15 * (float64(params.SharedMobility.PassengerDistance) / 1000.0)
|
passengerAmount = 0.15 * float64(params.SharedMobility.PassengerDistance)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Driver indemnification is always 0.30€/km for driver distance (convert meters to km)
|
// Driver indemnification is always 0.30€/km for driver distance
|
||||||
driverAmount := 0.30 * (float64(params.SharedMobility.DriverDistance) / 1000.0)
|
driverAmount := 0.30 * float64(params.SharedMobility.DriverDistance)
|
||||||
|
|
||||||
return map[string]Price{
|
return map[string]Price{
|
||||||
"passenger": {
|
"passenger": {
|
||||||
|
|
|
@ -21,13 +21,13 @@ func TestMMS43Prices(t *testing.T) {
|
||||||
Priority: false,
|
Priority: false,
|
||||||
},
|
},
|
||||||
SharedMobility: SharedMobilityParams{
|
SharedMobility: SharedMobilityParams{
|
||||||
PassengerDistance: 10000, // 10km in meters
|
PassengerDistance: 10, // 10km in meters
|
||||||
DriverDistance: 15000, // 15km in meters
|
DriverDistance: 15, // 15km in meters
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPrices: map[string]Price{
|
expectedPrices: map[string]Price{
|
||||||
"passenger": {Amount: 0.0, Currency: "EUR"}, // Free for first trip
|
"passenger": {Amount: 0.0, Currency: "EUR"}, // Free for first trip
|
||||||
"driver": {Amount: 4.5, Currency: "EUR"}, // 15km * 0.30€/km
|
"driver": {Amount: 4.5, Currency: "EUR"}, // 15km * 0.30€/km
|
||||||
},
|
},
|
||||||
expectedError: false,
|
expectedError: false,
|
||||||
},
|
},
|
||||||
|
@ -39,13 +39,13 @@ func TestMMS43Prices(t *testing.T) {
|
||||||
Priority: false,
|
Priority: false,
|
||||||
},
|
},
|
||||||
SharedMobility: SharedMobilityParams{
|
SharedMobility: SharedMobilityParams{
|
||||||
PassengerDistance: 20000, // 20km in meters
|
PassengerDistance: 20, // 20km in meters
|
||||||
DriverDistance: 25000, // 25km in meters
|
DriverDistance: 25, // 25km in meters
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPrices: map[string]Price{
|
expectedPrices: map[string]Price{
|
||||||
"passenger": {Amount: 0.0, Currency: "EUR"}, // Free for second trip
|
"passenger": {Amount: 0.0, Currency: "EUR"}, // Free for second trip
|
||||||
"driver": {Amount: 7.5, Currency: "EUR"}, // 25km * 0.30€/km
|
"driver": {Amount: 7.5, Currency: "EUR"}, // 25km * 0.30€/km
|
||||||
},
|
},
|
||||||
expectedError: false,
|
expectedError: false,
|
||||||
},
|
},
|
||||||
|
@ -57,13 +57,13 @@ func TestMMS43Prices(t *testing.T) {
|
||||||
Priority: false,
|
Priority: false,
|
||||||
},
|
},
|
||||||
SharedMobility: SharedMobilityParams{
|
SharedMobility: SharedMobilityParams{
|
||||||
PassengerDistance: 10000, // 10km in meters
|
PassengerDistance: 10, // 10km in meters
|
||||||
DriverDistance: 10000, // 10km in meters
|
DriverDistance: 10, // 10km in meters
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPrices: map[string]Price{
|
expectedPrices: map[string]Price{
|
||||||
"passenger": {Amount: 1.5, Currency: "EUR"}, // 10km * 0.15€/km
|
"passenger": {Amount: 1.5, Currency: "EUR"}, // 10km * 0.15€/km
|
||||||
"driver": {Amount: 3.0, Currency: "EUR"}, // 10km * 0.30€/km
|
"driver": {Amount: 3.0, Currency: "EUR"}, // 10km * 0.30€/km
|
||||||
},
|
},
|
||||||
expectedError: false,
|
expectedError: false,
|
||||||
},
|
},
|
||||||
|
@ -75,13 +75,13 @@ func TestMMS43Prices(t *testing.T) {
|
||||||
Priority: false,
|
Priority: false,
|
||||||
},
|
},
|
||||||
SharedMobility: SharedMobilityParams{
|
SharedMobility: SharedMobilityParams{
|
||||||
PassengerDistance: 30000, // 30km in meters
|
PassengerDistance: 30, // 30km in meters
|
||||||
DriverDistance: 35000, // 35km in meters
|
DriverDistance: 35, // 35km in meters
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPrices: map[string]Price{
|
expectedPrices: map[string]Price{
|
||||||
"passenger": {Amount: 4.5, Currency: "EUR"}, // 30km * 0.15€/km
|
"passenger": {Amount: 4.5, Currency: "EUR"}, // 30km * 0.15€/km
|
||||||
"driver": {Amount: 10.5, Currency: "EUR"}, // 35km * 0.30€/km
|
"driver": {Amount: 10.5, Currency: "EUR"}, // 35km * 0.30€/km
|
||||||
},
|
},
|
||||||
expectedError: false,
|
expectedError: false,
|
||||||
},
|
},
|
||||||
|
@ -111,13 +111,13 @@ func TestMMS43Prices(t *testing.T) {
|
||||||
Priority: false,
|
Priority: false,
|
||||||
},
|
},
|
||||||
SharedMobility: SharedMobilityParams{
|
SharedMobility: SharedMobilityParams{
|
||||||
PassengerDistance: 100000, // 100km in meters
|
PassengerDistance: 100, // 100km in meters
|
||||||
DriverDistance: 120000, // 120km in meters
|
DriverDistance: 120, // 120km in meters
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPrices: map[string]Price{
|
expectedPrices: map[string]Price{
|
||||||
"passenger": {Amount: 15.0, Currency: "EUR"}, // 100km * 0.15€/km
|
"passenger": {Amount: 15.0, Currency: "EUR"}, // 100km * 0.15€/km
|
||||||
"driver": {Amount: 36.0, Currency: "EUR"}, // 120km * 0.30€/km
|
"driver": {Amount: 36.0, Currency: "EUR"}, // 120km * 0.30€/km
|
||||||
},
|
},
|
||||||
expectedError: false,
|
expectedError: false,
|
||||||
},
|
},
|
||||||
|
@ -129,13 +129,13 @@ func TestMMS43Prices(t *testing.T) {
|
||||||
Priority: false,
|
Priority: false,
|
||||||
},
|
},
|
||||||
SharedMobility: SharedMobilityParams{
|
SharedMobility: SharedMobilityParams{
|
||||||
PassengerDistance: 4000, // 4km in meters
|
PassengerDistance: 4, // 4km in meters
|
||||||
DriverDistance: 5000, // 5km in meters
|
DriverDistance: 5, // 5km in meters
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPrices: map[string]Price{
|
expectedPrices: map[string]Price{
|
||||||
"passenger": {Amount: 0.6, Currency: "EUR"}, // 4km * 0.15€/km (first paid trip)
|
"passenger": {Amount: 0.6, Currency: "EUR"}, // 4km * 0.15€/km (first paid trip)
|
||||||
"driver": {Amount: 1.5, Currency: "EUR"}, // 5km * 0.30€/km
|
"driver": {Amount: 1.5, Currency: "EUR"}, // 5km * 0.30€/km
|
||||||
},
|
},
|
||||||
expectedError: false,
|
expectedError: false,
|
||||||
},
|
},
|
||||||
|
@ -147,13 +147,13 @@ func TestMMS43Prices(t *testing.T) {
|
||||||
Priority: false,
|
Priority: false,
|
||||||
},
|
},
|
||||||
SharedMobility: SharedMobilityParams{
|
SharedMobility: SharedMobilityParams{
|
||||||
PassengerDistance: 2000, // 2km in meters
|
PassengerDistance: 2, // 2km in meters
|
||||||
DriverDistance: 3000, // 3km in meters
|
DriverDistance: 3, // 3km in meters
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPrices: map[string]Price{
|
expectedPrices: map[string]Price{
|
||||||
"passenger": {Amount: 0.3, Currency: "EUR"}, // 2km * 0.15€/km
|
"passenger": {Amount: 0.3, Currency: "EUR"}, // 2km * 0.15€/km
|
||||||
"driver": {Amount: 0.9, Currency: "EUR"}, // 3km * 0.30€/km
|
"driver": {Amount: 0.9, Currency: "EUR"}, // 3km * 0.30€/km
|
||||||
},
|
},
|
||||||
expectedError: false,
|
expectedError: false,
|
||||||
},
|
},
|
||||||
|
@ -189,8 +189,8 @@ func TestMMS43PricingEdgeCases(t *testing.T) {
|
||||||
History: -1, // Edge case: negative history
|
History: -1, // Edge case: negative history
|
||||||
},
|
},
|
||||||
SharedMobility: SharedMobilityParams{
|
SharedMobility: SharedMobilityParams{
|
||||||
PassengerDistance: 10000,
|
PassengerDistance: 10,
|
||||||
DriverDistance: 10000,
|
DriverDistance: 10,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,8 +207,8 @@ func TestMMS43PricingEdgeCases(t *testing.T) {
|
||||||
History: 100,
|
History: 100,
|
||||||
},
|
},
|
||||||
SharedMobility: SharedMobilityParams{
|
SharedMobility: SharedMobilityParams{
|
||||||
PassengerDistance: 10000,
|
PassengerDistance: 10,
|
||||||
DriverDistance: 10000,
|
DriverDistance: 10,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,4 +218,5 @@ func TestMMS43PricingEdgeCases(t *testing.T) {
|
||||||
assert.InDelta(t, 1.5, prices["passenger"].Amount, 0.001)
|
assert.InDelta(t, 1.5, prices["passenger"].Amount, 0.001)
|
||||||
assert.InDelta(t, 3.0, prices["driver"].Amount, 0.001)
|
assert.InDelta(t, 3.0, prices["driver"].Amount, 0.001)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue