Skip to content

Commit

Permalink
Don't use Enum.GetValues
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Jan 3, 2024
1 parent 5a8ddee commit 083deb5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
14 changes: 8 additions & 6 deletions src/FactorioTools/OilField/Algorithms/DijkstrasResult.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Knapcode.FactorioTools.Data;

namespace Knapcode.FactorioTools.OilField;

public class DijkstrasResult
{
private readonly SquareGrid _grid;

public DijkstrasResult(SquareGrid grid, Dictionary<Location, LocationSet> locationToPrevious, LocationSet reachedGoals)
{
_grid = grid;
LocationToPrevious = locationToPrevious;
ReachedGoals = reachedGoals;
}
Expand Down Expand Up @@ -39,7 +35,13 @@ public List<List<Location>> GetStraightPaths(Location goal)

// Track the number of times each direction was used so when we have to switch directions, we can prefer a
// direction that's been used the most.
var directionHits = Enum.GetValues<Direction>().ToDictionary(x => x, x => 0);
var directionHits = new Dictionary<Direction, int>
{
{ Direction.Up, 0 },
{ Direction.Right, 0 },
{ Direction.Down, 0 },
{ Direction.Left, 0 },
};

var current = goal;
var path = new List<Location>();
Expand Down
28 changes: 16 additions & 12 deletions src/FactorioTools/OilField/OilFieldOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,28 @@ public static OilFieldOptions ForSubstation
}
}

public static IReadOnlyList<PipeStrategy> AllPipeStrategies { get; } = Enum
.GetValues<PipeStrategy>()
.Order()
.ToList();
public static IReadOnlyList<PipeStrategy> AllPipeStrategies { get; } = new[]
{
PipeStrategy.FbeOriginal,
PipeStrategy.Fbe,
PipeStrategy.ConnectedCentersDelaunay,
PipeStrategy.ConnectedCentersDelaunayMst,
PipeStrategy.ConnectedCentersFlute,
};

public static IReadOnlyList<PipeStrategy> DefaultPipeStrategies { get; } = Enum
.GetValues<PipeStrategy>()
public static IReadOnlyList<PipeStrategy> DefaultPipeStrategies { get; } = AllPipeStrategies
.Except(new[] { PipeStrategy.FbeOriginal })
.Order()
.ToList();

public static IReadOnlyList<BeaconStrategy> AllBeaconStrategies { get; } = Enum
.GetValues<BeaconStrategy>()
.Order()
.ToList();
public static IReadOnlyList<BeaconStrategy> AllBeaconStrategies { get; } = new[]
{
BeaconStrategy.FbeOriginal,
BeaconStrategy.Fbe,
BeaconStrategy.Snug,
};

public static IReadOnlyList<BeaconStrategy> DefaultBeaconStrategies { get; } = Enum
.GetValues<BeaconStrategy>()
public static IReadOnlyList<BeaconStrategy> DefaultBeaconStrategies { get; } = AllBeaconStrategies
.Except(new[] { BeaconStrategy.FbeOriginal })
.Order()
.ToList();
Expand Down
16 changes: 16 additions & 0 deletions test/FactorioTools.Test/OilField/OilFieldOptionsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Knapcode.FactorioTools.OilField;

public class OilFieldOptionsTest
{
[Fact]
public void AllPipeStrategies()
{
Assert.Equal(Enum.GetValues<PipeStrategy>(), OilFieldOptions.AllPipeStrategies);
}

[Fact]
public void AllBeaconStrategies()
{
Assert.Equal(Enum.GetValues<BeaconStrategy>(), OilFieldOptions.AllBeaconStrategies);
}
}

0 comments on commit 083deb5

Please sign in to comment.