mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-19 06:55:59 +01:00
- HaslerTapeWindow: with nothing recorded it offers to record and turns on the black box and the trains' tapes; a tape of the last launch is summed up with its scenario and train, and is no longer followed once the window closes. - HaslerTapes.Load: a log begun anew over the end that was read is read whole once its time goes back; an unreadable tape is none and told in the log; a file read only forward is read whole each time. Empty log lines are passed over. - MessageBox.Choose: the answer clicked, or none on the way back or on closing. - CabPanel: wheels turning apart from the train are said beside its speed. - EventList: going to the other cab tells nothing of the doors, still the switches. - WarehouseEditTests and ConsistOrientationTests put in app-wide services of their own: they now wait their turn with the controls that read them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
137 lines
4.4 KiB
C#
137 lines
4.4 KiB
C#
using StarterNG.Application;
|
|
using StarterNG.Classes;
|
|
using StarterNG.Domain;
|
|
using StarterNG.Domain.Vehicles;
|
|
using StarterNG.Tests.Fakes;
|
|
|
|
namespace StarterNG.Tests;
|
|
|
|
// Puts in services of its own: not while the controls read theirs.
|
|
[Collection(AvaloniaControls.Name)]
|
|
public class ConsistOrientationTests
|
|
{
|
|
private readonly VehicleCatalog _catalog;
|
|
private readonly TestInstallation _installation;
|
|
|
|
public ConsistOrientationTests()
|
|
{
|
|
var installation = new TestInstallation(new InMemoryFileSystem()
|
|
.WithFile(TestInstallation.At("dynamic", "pkp", "et40", "textures.txt"),
|
|
"!=e\n^2\net40-10-a.mat=et40a,ET40-A\net40-10-b.mat=et40b,ET40-B\n" +
|
|
"et40-16-a.mat=et40a,ET40-A\net40-16-b.mat=et40b,ET40-B"));
|
|
installation.Vehicles.Load(installation.Library.Vehicles);
|
|
_catalog = installation.Library.Vehicles;
|
|
_installation = installation;
|
|
}
|
|
|
|
[Fact]
|
|
public void Randomly_turned_unit_comes_out_like_a_flipped_one()
|
|
{
|
|
var flipped = NewConsist(out var unit);
|
|
flipped.Flip(unit);
|
|
|
|
var randomized = NewConsist(out _);
|
|
randomized.RandomizeOrientation(new AlwaysTurn());
|
|
|
|
Assert.Equal(Describe(flipped), Describe(randomized));
|
|
}
|
|
|
|
[Fact]
|
|
public void A_turned_unit_has_its_cars_reversed_and_each_one_turned()
|
|
{
|
|
var consist = NewConsist(out _);
|
|
|
|
consist.RandomizeOrientation(new AlwaysTurn());
|
|
|
|
// B leads, A trails, and both face backwards - not A-B reordered but facing forward.
|
|
Assert.Equal(new[] { "et40-10-b -1", "et40-10-a -1" }, Describe(consist));
|
|
}
|
|
|
|
[Fact]
|
|
public void A_unit_put_in_place_of_a_turned_one_faces_the_same_way()
|
|
{
|
|
var consist = NewConsist(out var unit);
|
|
consist.Flip(unit);
|
|
|
|
consist.Replace(0, Unit(consist, "et40-16-a"));
|
|
|
|
Assert.Equal(new[] { "et40-16-b -1", "et40-16-a -1" }, Describe(consist));
|
|
}
|
|
|
|
[Fact]
|
|
public void Joining_units_that_face_different_ways_leaves_every_car_as_it_was()
|
|
{
|
|
var consist = NewConsist(out var first);
|
|
var second = Unit(consist, "et40-16-a");
|
|
consist.Insert(1, second);
|
|
consist.Flip(second);
|
|
var before = Describe(consist);
|
|
|
|
consist.Join(first);
|
|
|
|
Assert.Single(consist);
|
|
Assert.Equal(before, Describe(consist));
|
|
Assert.Equal(new[] { "et40-10-a 1", "et40-10-b 1", "et40-16-b -1", "et40-16-a -1" }, before);
|
|
}
|
|
|
|
[Fact]
|
|
public void Splitting_such_a_unit_gives_each_car_its_own_way_back()
|
|
{
|
|
var consist = NewConsist(out var first);
|
|
var second = Unit(consist, "et40-16-a");
|
|
consist.Insert(1, second);
|
|
consist.Flip(second);
|
|
var before = Describe(consist);
|
|
consist.Join(first);
|
|
|
|
consist.Split(consist[0]);
|
|
|
|
Assert.Equal(before, Describe(consist));
|
|
Assert.All(consist, card => Assert.Equal(Consist.IsTurned(card.Cars[0]), card.Flipped));
|
|
}
|
|
|
|
[Fact]
|
|
public void A_turned_unit_comes_back_as_it_was_from_every_load()
|
|
{
|
|
AppServices.Initialize(_installation.Paths, _installation.Files, _installation.Clock, _installation.Environment);
|
|
var consist = NewConsist(out var unit);
|
|
consist.Flip(unit);
|
|
string[] turned = Describe(consist);
|
|
var trainset = new Trainset("trainset a tor 0 0\nendtrainset");
|
|
|
|
for (int load = 0; load < 3; load++)
|
|
{
|
|
trainset.Vehicles = consist.Flatten();
|
|
consist.LoadFrom(trainset);
|
|
|
|
Assert.True(Assert.Single(consist).Flipped);
|
|
Assert.Equal(turned, Describe(consist));
|
|
}
|
|
}
|
|
|
|
private Consist NewConsist(out ConsistItem unit)
|
|
{
|
|
var consist = new Consist(_catalog, new VehicleInfo(_catalog, _installation.Physics));
|
|
unit = Unit(consist, "et40-10-a");
|
|
consist.Insert(0, unit);
|
|
return consist;
|
|
}
|
|
|
|
private ConsistItem Unit(Consist consist, string lead) => new()
|
|
{
|
|
Cars = _catalog.ResolveSet(_catalog.TextureForSkin(lead)!)!
|
|
.Select(texture => consist.MakeDynamic(texture, null))
|
|
.ToList(),
|
|
Grouped = true
|
|
};
|
|
|
|
// The export order, each car with the way it faces.
|
|
private static string[] Describe(Consist consist) =>
|
|
consist.Flatten().Select(car => $"{car.SkinFile} {(car.Offset < 0 ? -1 : 1)}").ToArray();
|
|
|
|
private sealed class AlwaysTurn : Random
|
|
{
|
|
public override int Next(int maxValue) => 0;
|
|
}
|
|
}
|