improve tests

This commit is contained in:
sbriat 2023-09-14 17:28:42 +02:00
parent f69afc4481
commit a7c73080a7
3 changed files with 37 additions and 9 deletions

View File

@ -10,12 +10,11 @@ export class CarpoolPathCreator {
private readonly passengerWaypoints: Point[],
) {}
public createCarpoolPath = (): WayStep[] => {
const passengerWaysteps: WayStep[] = this._createPassengerWaysteps();
if (this.driverWaypoints.length == 2) {
}
return passengerWaysteps;
};
public createCarpoolPath = (): WayStep[] =>
this._createMixedWaysteps(
this._createDriverWaysteps(),
this._createPassengerWaysteps(),
);
private _createDriverWaysteps = (): WayStep[] =>
this.driverWaypoints.map(
@ -48,7 +47,7 @@ export class CarpoolPathCreator {
});
if (
this.driverWaypoints.filter((driverWaypoint: Point) =>
this._isSamePoint(driverWaypoint, passengerWaypoint),
passengerWaypoint.isSame(driverWaypoint),
).length > 0
) {
waystep.actors.push(
@ -64,8 +63,18 @@ export class CarpoolPathCreator {
return waysteps;
};
private _isSamePoint = (point1: Point, point2: Point): boolean =>
point1.lon === point2.lon && point1.lat === point2.lat;
private _createMixedWaysteps = (
driverWaysteps: WayStep[],
passengerWaysteps: WayStep[],
): WayStep[] =>
driverWaysteps.length == 2
? [driverWaysteps[0], ...passengerWaysteps, driverWaysteps[1]]
: this._createComplexMixedWaysteps(driverWaysteps, passengerWaysteps);
private _createComplexMixedWaysteps = (
driverWaysteps: WayStep[],
passengerWaysteps: WayStep[],
): WayStep[] => [];
private _getTarget = (index: number, waypoints: Point[]): Target =>
index == 0

View File

@ -22,6 +22,9 @@ export class Point extends ValueObject<PointProps> {
return this.props.lat;
}
isSame = (point: this): boolean =>
point.lon == this.lon && point.lat == this.lat;
protected validate(props: PointProps): void {
if (props.lon > 180 || props.lon < -180)
throw new ArgumentOutOfRangeException('lon must be between -180 and 180');

View File

@ -10,6 +10,22 @@ describe('Point value object', () => {
expect(pointVO.lat).toBe(48.689445);
expect(pointVO.lon).toBe(6.17651);
});
it('should check if two points are identical', () => {
const pointVO = new Point({
lat: 48.689445,
lon: 6.17651,
});
const identicalPointVO = new Point({
lat: 48.689445,
lon: 6.17651,
});
const differentPointVO = new Point({
lat: 48.689446,
lon: 6.17651,
});
expect(pointVO.isSame(identicalPointVO)).toBeTruthy();
expect(pointVO.isSame(differentPointVO)).toBeFalsy();
});
it('should throw an exception if longitude is invalid', () => {
try {
new Point({