Skip to content

Commit

Permalink
set up upgrade tree test
Browse files Browse the repository at this point in the history
  • Loading branch information
myangelkamikaze committed Nov 12, 2023
1 parent afddcc7 commit b116b56
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public partial class UpgradeTreeUpgradePlanViewModel : ObservableObject

public bool AlreadyPlanned => Plan is EquipmentUpgradePlanItemViewModel plan && EquipmentUpgradePlanManager.PlannedUpgrades.Contains(plan);

private IEquipmentPlanItemViewModel? Plan { get; set; }
public IEquipmentPlanItemViewModel? Plan { get; private set; }

public int RequiredCount { get; }

Expand Down
39 changes: 38 additions & 1 deletion ElectronicObserverCoreTests/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CommunityToolkit.Mvvm.DependencyInjection;
using ElectronicObserver.Data;
using ElectronicObserver.Database;
using ElectronicObserver.Services;
using ElectronicObserver.TestData;
using ElectronicObserver.Utility;
using ElectronicObserver.Window.Tools.AutoRefresh;
using ElectronicObserver.Window.Tools.EquipmentUpgradePlanner;
using ElectronicObserver.Window.Tools.SortieRecordViewer.Sortie.Battle;
using ElectronicObserver.Window.Tools.SortieRecordViewer.Sortie.Battle.Phase;
using ElectronicObserver.Window.Tools.SortieRecordViewer.SortieDetail;
Expand Down Expand Up @@ -52,15 +55,20 @@ public async void ConfigureServices(IServiceCollection services)
kcdb.MasterEquipments.Add(equipment);
}

InitializeKcDatabase(kcdb);

Ioc.Default.ConfigureServices(new ServiceCollection()
.AddSingleton<IKCDatabase>(kcdb)
.AddSingleton<ColorService>()
.AddSingleton<AutoRefreshTranslationViewModel>()
.AddSingleton<SortieDetailTranslationViewModel>()
.AddSingleton<EquipmentUpgradePlannerTranslationViewModel>()
.AddSingleton<PhaseFactory>()
.AddSingleton<BattleFactory>()
.AddSingleton<DataSerializationService>()
.AddSingleton<ToolService>()
.AddSingleton<TimeChangeService>()
.AddSingleton<EquipmentUpgradePlanManager>()
.BuildServiceProvider());

Directory.CreateDirectory("Record");
Expand All @@ -71,4 +79,33 @@ public async void ConfigureServices(IServiceCollection services)
// Download data
await SoftwareUpdater.CheckUpdateAsync();
}

/// <summary>
/// hack: this should ideally be removed
/// </summary>
private static void InitializeKcDatabase(KCDatabaseMock kcdb)
{
foreach (IShipDataMaster ship in kcdb.MasterShips.Values)
{
KCDatabase.Instance.MasterShips.Add(ship);
}

foreach (IEquipmentDataMaster equipment in kcdb.MasterEquipments.Values)
{
KCDatabase.Instance.MasterEquipments.Add(equipment);
}

foreach (UseItemId useItemId in Enum.GetValues<UseItemId>())
{
UseItemMasterMock itemMaster = new() { ItemID = useItemId };
UseItemMock item = new()
{
ItemID = (int)itemMaster.ItemID,
MasterUseItem = itemMaster,
};

KCDatabase.Instance.MasterUseItems.Add(itemMaster);
KCDatabase.Instance.UseItems.Add(item);
}
}
}
57 changes: 57 additions & 0 deletions ElectronicObserverCoreTests/UpgradeTreeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Linq;
using ElectronicObserver.Window.Tools.EquipmentUpgradePlanner;
using ElectronicObserver.Window.Tools.EquipmentUpgradePlanner.UpgradeTree;
using ElectronicObserverTypes;
using Xunit;

namespace ElectronicObserverCoreTests;

public class UpgradeTreeTests
{
private static int GetCount(UpgradeTreeUpgradePlanViewModel plan) => plan.Plan switch
{
EquipmentUpgradePlanItemViewModel => plan.RequiredCount,
EquipmentConversionPlanItemViewModel conversion => conversion.EquipmentRequiredForUpgradePlan.Count,
EquipmentCraftPlanItemViewModel => plan.RequiredCount,

_ => throw new NotImplementedException(),
};

[Fact(DisplayName = "S-51J kai example")]
public void UpgradeTreeTest1()
{
EquipmentUpgradePlanItemModel upgradePlan = new()
{
EquipmentId = EquipmentId.Autogyro_S51JKai,
DesiredUpgradeLevel = UpgradeLevel.Max,
};

EquipmentUpgradePlanItemViewModel upgradePlanViewModel = new(upgradePlan);
upgradePlanViewModel.UpdateCosts();

UpgradeTreeViewModel tree = new(upgradePlanViewModel);

UpgradeTreeUpgradePlanViewModel root = tree.Items[0];

Assert.NotNull(root.Plan);
Assert.Equal(EquipmentId.Autogyro_S51JKai, root.Plan.EquipmentMasterDataId);

UpgradeTreeUpgradePlanViewModel? s51jKaiPlan = root.Children
.FirstOrDefault(p => p.Plan?.EquipmentMasterDataId is EquipmentId.Autogyro_S51JKai);

UpgradeTreeUpgradePlanViewModel? zuiunPlan = root.Children
.FirstOrDefault(p => p.Plan?.EquipmentMasterDataId is EquipmentId.SeaplaneBomber_Zuiun);

UpgradeTreeUpgradePlanViewModel? t3dcpPlan = root.Children
.FirstOrDefault(p => p.Plan?.EquipmentMasterDataId is EquipmentId.DepthCharge_Type3DepthChargeProjector);

Assert.NotNull(s51jKaiPlan);
Assert.NotNull(zuiunPlan);
Assert.NotNull(t3dcpPlan);

Assert.Equal(1, s51jKaiPlan.RequiredCount);
Assert.Equal(12, GetCount(zuiunPlan));
Assert.Equal(8, GetCount(t3dcpPlan));
}
}

0 comments on commit b116b56

Please sign in to comment.