|
| 1 | +using Definitions.ObjectModels.Objects.Track; |
| 2 | +using Definitions.ObjectModels.Objects.Bridge; |
| 3 | +using Gui; |
| 4 | +using Gui.ViewModels; |
| 5 | +using NUnit.Framework; |
| 6 | + |
| 7 | +namespace Gui.Tests; |
| 8 | + |
| 9 | +[TestFixture] |
| 10 | +public class EffectiveCostTests |
| 11 | +{ |
| 12 | + [SetUp] |
| 13 | + public void Setup() |
| 14 | + { |
| 15 | + // Set up global settings |
| 16 | + GlobalSettings.CurrentSettings = new EditorSettings |
| 17 | + { |
| 18 | + InflationYear = 1950 |
| 19 | + }; |
| 20 | + } |
| 21 | + |
| 22 | + [Test] |
| 23 | + public void TrackViewModel_CalculatesEffectiveCosts() |
| 24 | + { |
| 25 | + var trackObject = new TrackObject |
| 26 | + { |
| 27 | + BuildCostFactor = 100, |
| 28 | + SellCostFactor = -50, |
| 29 | + TunnelCostFactor = 200, |
| 30 | + CostIndex = 0 |
| 31 | + }; |
| 32 | + |
| 33 | + var viewModel = new TrackViewModel(trackObject); |
| 34 | + |
| 35 | + // For year 1950, with factor 1024 and divisor 10, we should get: (100 * X) / 1024 |
| 36 | + // where X is the inflation-adjusted currency multiplication factor |
| 37 | + Assert.That(viewModel.EffectiveBuildCost, Is.GreaterThan(0)); |
| 38 | + Assert.That(viewModel.EffectiveSellCost, Is.LessThan(0)); |
| 39 | + Assert.That(viewModel.EffectiveTunnelCost, Is.GreaterThan(0)); |
| 40 | + |
| 41 | + // Build cost should be proportional to the factors |
| 42 | + Assert.That(viewModel.EffectiveTunnelCost, Is.GreaterThan(viewModel.EffectiveBuildCost)); |
| 43 | + } |
| 44 | + |
| 45 | + [Test] |
| 46 | + public void BridgeViewModel_CalculatesEffectiveCosts() |
| 47 | + { |
| 48 | + var bridgeObject = new BridgeObject |
| 49 | + { |
| 50 | + BaseCostFactor = 150, |
| 51 | + HeightCostFactor = 50, |
| 52 | + SellCostFactor = -75, |
| 53 | + CostIndex = 1 |
| 54 | + }; |
| 55 | + |
| 56 | + var viewModel = new BridgeViewModel(bridgeObject); |
| 57 | + |
| 58 | + Assert.That(viewModel.EffectiveBaseCost, Is.GreaterThan(0)); |
| 59 | + Assert.That(viewModel.EffectiveHeightCost, Is.GreaterThan(0)); |
| 60 | + Assert.That(viewModel.EffectiveSellCost, Is.LessThan(0)); |
| 61 | + |
| 62 | + // Base cost should be greater than height cost |
| 63 | + Assert.That(viewModel.EffectiveBaseCost, Is.GreaterThan(viewModel.EffectiveHeightCost)); |
| 64 | + } |
| 65 | + |
| 66 | + [Test] |
| 67 | + public void InflationYear_AffectsCosts() |
| 68 | + { |
| 69 | + var trackObject = new TrackObject |
| 70 | + { |
| 71 | + BuildCostFactor = 100, |
| 72 | + CostIndex = 0 |
| 73 | + }; |
| 74 | + |
| 75 | + // Test with year 1900 (no inflation) |
| 76 | + GlobalSettings.CurrentSettings!.InflationYear = 1900; |
| 77 | + var viewModel1900 = new TrackViewModel(trackObject); |
| 78 | + var cost1900 = viewModel1900.EffectiveBuildCost; |
| 79 | + |
| 80 | + // Test with year 2000 (with inflation) |
| 81 | + GlobalSettings.CurrentSettings!.InflationYear = 2000; |
| 82 | + var viewModel2000 = new TrackViewModel(trackObject); |
| 83 | + var cost2000 = viewModel2000.EffectiveBuildCost; |
| 84 | + |
| 85 | + // Cost in 2000 should be higher due to inflation |
| 86 | + Assert.That(cost2000, Is.GreaterThan(cost1900)); |
| 87 | + } |
| 88 | + |
| 89 | + [Test] |
| 90 | + public void GlobalSettings_DefaultYear_WorksCorrectly() |
| 91 | + { |
| 92 | + // Test that if GlobalSettings is null, default year is used |
| 93 | + GlobalSettings.CurrentSettings = null; |
| 94 | + |
| 95 | + var trackObject = new TrackObject |
| 96 | + { |
| 97 | + BuildCostFactor = 100, |
| 98 | + CostIndex = 0 |
| 99 | + }; |
| 100 | + |
| 101 | + var viewModel = new TrackViewModel(trackObject); |
| 102 | + |
| 103 | + // Should not throw and should return a valid cost |
| 104 | + Assert.That(viewModel.EffectiveBuildCost, Is.GreaterThan(0)); |
| 105 | + } |
| 106 | +} |
0 commit comments