From 0d72ddb5baf58b3e4519d210025dfc36e55de349 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Fri, 28 Jul 2023 00:57:04 +0000 Subject: [PATCH] chore: a bit of coverage work --- packages/cli/bin/move_ship.dart | 3 ++- packages/cli/lib/api.dart | 15 ++++++--------- packages/cli/test/api_test.dart | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/packages/cli/bin/move_ship.dart b/packages/cli/bin/move_ship.dart index f1f49492..83d49f0c 100644 --- a/packages/cli/bin/move_ship.dart +++ b/packages/cli/bin/move_ship.dart @@ -102,7 +102,8 @@ Future command(FileSystem fs, Api api, Caches caches) async { ship, jumpGateWaypoint, ); - await Future.delayed(durationUntil(arrival)); + final durationUntil = arrival.difference(DateTime.timestamp()); + await Future.delayed(durationUntil); } final jumpRequest = JumpShipRequest(systemSymbol: destSystem.symbol); await api.fleet.jumpShip(ship.symbol, jumpShipRequest: jumpRequest); diff --git a/packages/cli/lib/api.dart b/packages/cli/lib/api.dart index c0583a8c..30b7e1b7 100644 --- a/packages/cli/lib/api.dart +++ b/packages/cli/lib/api.dart @@ -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. @@ -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( @@ -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); } diff --git a/packages/cli/test/api_test.dart b/packages/cli/test/api_test.dart index 709be316..76e12d77 100644 --- a/packages/cli/test/api_test.dart +++ b/packages/cli/test/api_test.dart @@ -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); + }); }