Skip to content

Commit

Permalink
Add two more tests that currently fail
Browse files Browse the repository at this point in the history
  • Loading branch information
IntelOrca committed Sep 22, 2024
1 parent 532e723 commit f72568b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
64 changes: 64 additions & 0 deletions IntelOrca.Biohazard.BioRand.Tests/TestRouting.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using IntelOrca.Biohazard.BioRand.Routing;
using Ps2IsoTools.ISO.Builders;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -212,6 +213,69 @@ public void EnsureKeyNotPlacedAgain()
}
}

/// <summary>
/// Tests a map with a mini segment which can go back to main segment.
/// </summary>
[Fact]
public void MiniSegment()
{
for (var i = 0; i < Retries; i++)
{
var builder = new GraphBuilder();

var key0 = builder.ReusuableKey(1, "KEY 0");
var key1 = builder.ReusuableKey(1, "KEY 1");

var room1 = builder.AndGate("ROOM 1");
var room2 = builder.AndGate("ROOM 2", room1);
var room3 = builder.OneWay("ROOM 3", room1);
var room4 = builder.AndGate("ROOM 4", room3, key1);
var room5 = builder.OrGate("ROOM 5", room2, room4);
var room6 = builder.AndGate("ROOM 6", room3, key0);

var item2 = builder.Item(1, "Item 2", room2);
var item3 = builder.Item(1, "Item 3", room3);

var route = builder.GenerateRoute(i);

Assert.True(route.AllNodesVisited);
AssertKeyOnce(route, key0, item2);
AssertKeyOnce(route, key1, item3);
}
}

/// <summary>
/// Tests a map with a two segments which you can go between.
/// </summary>
[Fact]
public void CircularSegments()
{
for (var i = 0; i < Retries; i++)
{
var builder = new GraphBuilder();

var key0 = builder.ReusuableKey(1, "KEY 0");
var key1 = builder.ReusuableKey(2, "KEY 1");

var room0 = builder.AndGate("ROOM 0");
var room1 = builder.OneWay("ROOM 1", room0);
var room2 = builder.AndGate("ROOM 2", room1);
var room3 = builder.AndGate("ROOM 3", room0);
var room4 = builder.AndGate("ROOM 4", room2);
var room5 = builder.OrGate("ROOM 5", room3, builder.OneWay(null, room4));
var room6 = builder.AndGate("ROOM 6", room2, key1);
var room7 = builder.AndGate("ROOM 7", room3, key0);
var item2 = builder.Item(1, "Item 2", room2);
var item3 = builder.Item(2, "Item 3", room3);

var route = builder.GenerateRoute(i);

Assert.True(route.AllNodesVisited);
AssertKeyOnce(route, key0, item2);
AssertKeyOnce(route, key1, item3);
}
}

[Fact]
public void SingleUseKey_DoorAfterDoor()
{
Expand Down
13 changes: 12 additions & 1 deletion IntelOrca.Biohazard.BioRand/Routing/RouteFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private static State DoSubgraph(State state, IEnumerable<Node> start, bool first
toVisit.Add(n);
}

state = state.AddLog($"Begin subgraph {start.First()}");
state = state.Clear(visited, keys, next);
foreach (var v in toVisit)
state = state.VisitNode(v);
Expand Down Expand Up @@ -180,16 +181,18 @@ private static List<Node> GetMissingKeys(State state, ImmutableMultiSet<Node> ke
var result = new Node[keys.Count];
for (var i = 0; i < keys.Count; i++)
{
var found = false;
for (var j = 0; j < available.Count; j++)
{
if (available[j].Group == keys[i].Group)
{
result[i] = available[j];
available.RemoveAt(j);
found = true;
break;
}
}
if (result[i] == null)
if (!found)
return null;
}
return result;
Expand Down Expand Up @@ -431,6 +434,7 @@ public State Clear(IEnumerable<Node> visited, IEnumerable<Node> keys, IEnumerabl
result.Keys = ImmutableMultiSet<Node>.Empty.AddRange(keys);
result.Next = ImmutableHashSet<Node>.Empty.Union(next);
result.OneWay = ImmutableHashSet<Node>.Empty;
result.SpareItems = ImmutableHashSet<Node>.Empty;
return result;
}

Expand Down Expand Up @@ -481,6 +485,13 @@ public State UseKey(Node unlock, params Node[] keys)
result.Keys = Keys.RemoveMany(keys);
return result;
}

public State AddLog(string message)
{
var state = new State(this);
state.Log = Log.Add(message);
return state;
}
}
}
}

0 comments on commit f72568b

Please sign in to comment.