|
| 1 | +using System.Runtime.InteropServices; |
| 2 | +using GalaxyCheck.Gens.Parameters; |
| 3 | +using GalaxyCheck.Gens.Parameters.Internal; |
| 4 | +using GalaxyCheck.Runners.Replaying; |
| 5 | + |
| 6 | +namespace GalaxyCheck_Tests_V3.Features.Replaying; |
| 7 | + |
| 8 | +public class AboutReplayEncoding |
| 9 | +{ |
| 10 | + public static TheoryData<int, int, int?, IEnumerable<int>, string> Data => |
| 11 | + new() |
| 12 | + { |
| 13 | + { |
| 14 | + 0, 0, null, new[] { 0 }, |
| 15 | + "H4sIAAAAAAAACjPQM9AzAACGS1suBQAAAA==" |
| 16 | + }, |
| 17 | + { |
| 18 | + 0, 0, null, new[] { 0, 0, 0, 0, 0, 0 }, |
| 19 | + "H4sIAAAAAAAACjPQM9AzsIJDALKWW5IPAAAA" |
| 20 | + }, |
| 21 | + { |
| 22 | + 0, 0, null, Enumerable.Range(0, 10).Select(_ => 0), |
| 23 | + "H4sIAAAAAAAACjPQM9AzsMKAANukRbAXAAAA" |
| 24 | + }, |
| 25 | + { |
| 26 | + 0, 0, null, Enumerable.Range(0, 100).Select(_ => 0), |
| 27 | + "H4sIAAAAAAAACjPQM9AzsBoWEAC35Wk5ywAAAA==" |
| 28 | + }, |
| 29 | + { |
| 30 | + int.MaxValue, 100, int.MaxValue, Enumerable.Range(0, 100), |
| 31 | + "H4sIAAAAAAAACj2Qxw0EQQzDOlo4yIn9F3bzuq8ABSpco83WfG72GU6QiKIZlsOf6HjgiQsvvPHBFz/CiOcJIgkRRTQxxBJHGunki0xSZJFNDrnkIUOOAr1GoUKNBi06yiingkrqDSqqqaGWOtpop4NOWvTb2/TQSx9jjDPBJCOmmIczzDLHGutssMmKLbbZR7vsccY5F1xy4oprbrh3xn3xP+wHz39ZWzsBAAA=" |
| 32 | + }, |
| 33 | + }; |
| 34 | + |
| 35 | + [Theory] |
| 36 | + [MemberData(nameof(Data))] |
| 37 | + public void Examples(int seed, int size, int? seedWaypoint, IEnumerable<int> exampleSpacePath, string expectedEncoding) |
| 38 | + { |
| 39 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) is false) |
| 40 | + { |
| 41 | + // TODO: Cross-platform support for this behaviour - I think this might be fixed in .NET 7 |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + var replay = CreateReplay(seed, size, seedWaypoint, exampleSpacePath); |
| 46 | + |
| 47 | + var encoded = ReplayEncoding.Encode(replay); |
| 48 | + |
| 49 | + encoded.Should().Be(expectedEncoding); |
| 50 | + } |
| 51 | + |
| 52 | + [NebulaCheck.Property] |
| 53 | + public NebulaCheck.Property EncodeDecodeRoundtrip() |
| 54 | + { |
| 55 | + return NebulaCheck.Property.ForAll(DomainGen.Seed(), DomainGen.Size(), DomainGen.SeedWaypoint(), FeatureGen.ShrinkPath(), Test); |
| 56 | + |
| 57 | + static void Test(int seed, int size, int? seedWaypoint, IEnumerable<int> exampleSpacePath) |
| 58 | + { |
| 59 | + var replay0 = CreateReplay(seed, size, seedWaypoint, exampleSpacePath); |
| 60 | + var replay1 = ReplayEncoding.Decode(ReplayEncoding.Encode(replay0)); |
| 61 | + |
| 62 | + replay1.Should().BeEquivalentTo(replay0); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + private static Replay CreateReplay(int seed, int size, int? seedWaypoint, IEnumerable<int> exampleSpacePath) => |
| 67 | + new(new GenParameters(Rng.Create(seed), new Size(size), seedWaypoint == null ? null : Rng.Create(seedWaypoint.Value)), exampleSpacePath); |
| 68 | +} |
0 commit comments