Fix linear forwards backwards

This commit is contained in:
2025-03-17 08:47:39 +01:00
parent 2df23dde06
commit 872a59b27c
2 changed files with 113 additions and 38 deletions

View File

@@ -75,7 +75,7 @@ void main() {
});
test(
'Bisect search should end up with half the mods every forward iteration until 1',
'Should end up with half the mods every forward iteration until 1',
() {
final troubleshooter = ModListTroubleshooter(modList);
@@ -103,7 +103,7 @@ void main() {
},
);
test(
'Bisect search should end up with half the mods every backward iteration until 1',
'Should end up with half the mods every backward iteration until 1',
() {
final troubleshooter = ModListTroubleshooter(modList);
@@ -131,7 +131,7 @@ void main() {
},
);
test(
'Bisect search should end up with half the mods every iteration until 1',
'Should end up with half the mods every iteration until 1',
() {
final troubleshooter = ModListTroubleshooter(modList);
@@ -158,7 +158,7 @@ void main() {
expect(result.activeMods.keys.last, equals('test.mod9'));
},
);
test('Bisect should handle abuse gracefully', () {
test('Should handle abuse gracefully', () {
final troubleshooter = ModListTroubleshooter(modList);
var result = troubleshooter.binaryBackward();
@@ -225,7 +225,7 @@ void main() {
});
test(
'Linear search should end up with 10 mods every forward iteration',
'Should end up with 10 mods every forward iteration',
() {
final troubleshooter = ModListTroubleshooter(modList);
@@ -246,7 +246,7 @@ void main() {
},
);
test(
'Linear search should end up with 10 mods every backward iteration',
'Should end up with 10 mods every backward iteration',
() {
final troubleshooter = ModListTroubleshooter(modList);
@@ -266,7 +266,7 @@ void main() {
expect(result.activeMods.keys.last, equals('test.mod9'));
},
);
test('Linear search should end up with 10 mods every iteration', () {
test('Should end up with 10 mods every iteration', () {
final troubleshooter = ModListTroubleshooter(modList);
var result = troubleshooter.linearBackward(stepSize: 10);
@@ -281,10 +281,10 @@ void main() {
result = troubleshooter.linearBackward(stepSize: 10);
expect(result.activeMods.length, equals(10));
expect(result.activeMods.keys.first, equals('test.mod20'));
expect(result.activeMods.keys.last, equals('test.mod29'));
expect(result.activeMods.keys.first, equals('test.mod10'));
expect(result.activeMods.keys.last, equals('test.mod19'));
});
test('Linear search should handle abuse gracefully', () {
test('Should handle abuse gracefully', () {
final troubleshooter = ModListTroubleshooter(modList);
var result = troubleshooter.linearBackward(stepSize: 10);
@@ -302,7 +302,25 @@ void main() {
result = troubleshooter.linearForward(stepSize: 10);
expect(result.activeMods.length, equals(10));
});
test('Linear search cannot return more items than there are', () {
test('Should handle different step sizes', () {
final troubleshooter = ModListTroubleshooter(modList);
var result = troubleshooter.linearBackward(stepSize: 10);
expect(result.activeMods.length, equals(10));
result = troubleshooter.linearForward(stepSize: 10);
expect(result.activeMods.length, equals(10));
result = troubleshooter.linearBackward(stepSize: 10);
expect(result.activeMods.length, equals(10));
result = troubleshooter.linearForward(stepSize: 10);
expect(result.activeMods.length, equals(10));
result = troubleshooter.linearForward(stepSize: 10);
expect(result.activeMods.length, equals(10));
});
test('Cannot return more items than there are', () {
final troubleshooter = ModListTroubleshooter(modList);
var result = troubleshooter.linearBackward(stepSize: 10000);
@@ -312,6 +330,63 @@ void main() {
expect(result.activeMods.length, equals(30));
});
});
group('Navigation tests', () {
late ModList modList = ModList();
setUp(() {
modList = ModList();
// Add some base mods
for (int i = 0; i < 20; i++) {
final modId = 'test.mod$i';
final mod = makeDummy().copyWith(name: 'Test Mod $i', id: modId);
modList.mods[modId] = mod;
}
// Add some mods with dependencies
for (int i = 20; i < 30; i++) {
final modId = 'test.mod$i';
final mod = makeDummy().copyWith(
name: 'Test Mod $i',
id: modId,
dependencies: ['test.mod${i - 20}'], // Depend on earlier mods
);
modList.mods[modId] = mod;
}
modList.enableAll();
});
test(
'Mixed navigation should work',
() {
final troubleshooter = ModListTroubleshooter(modList);
var result = troubleshooter.linearForward(stepSize: 10);
expect(result.activeMods.length, equals(10));
expect(result.activeMods.keys.first, equals('test.mod0'));
expect(result.activeMods.keys.last, equals('test.mod9'));
result = troubleshooter.binaryForward();
expect(result.activeMods.length, equals(5));
expect(result.activeMods.keys.first, equals('test.mod5'));
expect(result.activeMods.keys.last, equals('test.mod9'));
result = troubleshooter.linearBackward(stepSize: 10);
expect(result.activeMods.length, equals(10));
expect(result.activeMods.keys.first, equals('test.mod0'));
expect(result.activeMods.keys.last, equals('test.mod9'));
result = troubleshooter.binaryForward();
expect(result.activeMods.length, equals(5));
expect(result.activeMods.keys.first, equals('test.mod5'));
expect(result.activeMods.keys.last, equals('test.mod9'));
result = troubleshooter.linearForward(stepSize: 10);
expect(result.activeMods.length, equals(10));
expect(result.activeMods.keys.first, equals('test.mod5'));
expect(result.activeMods.keys.last, equals('test.mod14'));
},
);
});
group('Loading dependencies', () {
late ModList modList = ModList();
setUp(() {
@@ -336,7 +411,7 @@ void main() {
modList.enableAll();
});
// Not that it has any reason to since they're completely detached...
test('Loading dependencies should not fuck up troubleshooter', () {
test('Should not fuck up troubleshooter', () {
final troubleshooter = ModListTroubleshooter(modList);
final expectedFirst = [
'test.mod1',