Skip to content

Commit

Permalink
chore: a bit of coverage work
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Jul 28, 2023
1 parent d32567e commit 0d72ddb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/cli/bin/move_ship.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ Future<void> command(FileSystem fs, Api api, Caches caches) async {
ship,
jumpGateWaypoint,
);
await Future<void>.delayed(durationUntil(arrival));
final durationUntil = arrival.difference(DateTime.timestamp());
await Future<void>.delayed(durationUntil);
}
final jumpRequest = JumpShipRequest(systemSymbol: destSystem.symbol);
await api.fleet.jumpShip(ship.symbol, jumpShipRequest: jumpRequest);
Expand Down
15 changes: 6 additions & 9 deletions packages/cli/lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,8 @@ extension ShipyardUtils on Shipyard {
WaypointSymbol get waypointSymbol => WaypointSymbol.fromString(symbol);

/// Returns true if the Shipyard has the given ship type.
bool hasShipType(ShipType shipType) {
return shipTypes.any((s) => s.type == shipType);
}
bool hasShipType(ShipType shipType) =>
shipTypes.any((s) => s.type == shipType);
}

/// Extensions onto MarketTransaction to make it easier to work with.
Expand Down Expand Up @@ -691,10 +690,6 @@ extension AgentUtils on Agent {
WaypointSymbol.fromString(headquarters);
}

/// Returns the duration until the given date time.
Duration durationUntil(DateTime dateTime) =>
dateTime.difference(DateTime.now());

/// Creates a ConnectedSystem from a System and a distance.
ConnectedSystem connectedSystemFromSystem(System system, int distance) {
return ConnectedSystem(
Expand All @@ -708,11 +703,13 @@ ConnectedSystem connectedSystemFromSystem(System system, int distance) {
}

/// Compute the trade symbol for the given mount symbol.
TradeSymbol? tradeSymbolForMountSymbol(ShipMountSymbolEnum mountSymbol) {
return TradeSymbol.fromJson(mountSymbol.value);
/// TradeSymbols are a superset of ShipMountSymbols so this should never fail.
TradeSymbol tradeSymbolForMountSymbol(ShipMountSymbolEnum mountSymbol) {
return TradeSymbol.fromJson(mountSymbol.value)!;
}

/// Compute the mount symbol for the given trade symbol.
/// This will return null if the trade symbol is not a mount symbol.
ShipMountSymbolEnum? mountSymbolForTradeSymbol(TradeSymbol tradeSymbol) {
return ShipMountSymbolEnum.fromJson(tradeSymbol.value);
}
28 changes: 28 additions & 0 deletions packages/cli/test/api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,32 @@ void main() {
ShipSymbol.fromString('A-1A'),
]);
});
test('FactionUtils', () {
final faction = Faction(
description: '',
symbol: FactionSymbols.AEGIS,
name: '',
headquarters: 'S-A-W',
traits: [],
isRecruiting: true,
);
expect(faction.headquartersSymbol, WaypointSymbol.fromString('S-A-W'));
});
test('AgentUtils', () {
final agent = Agentco
symbol: 'A-1',
headquarters: 'S-A-W',
credits: 0,
startingFaction: FactionSymbols.AEGIS.value,
);
expect(agent.headquartersSymbol, WaypointSymbol.fromString('S-A-W'));
});
test('tradeSymbolForMountSymbol', () {
for (final mountSymbol in ShipMountSymbolEnum.values) {
final tradeSymbol = tradeSymbolForMountSymbol(mountSymbol);
expect(mountSymbolForTradeSymbol(tradeSymbol), mountSymbol);
}
// Non-mount symbols will fail however:
expect(mountSymbolForTradeSymbol(TradeSymbol.ADVANCED_CIRCUITRY), isNull);
});
}

0 comments on commit 0d72ddb

Please sign in to comment.