From c27ae80b5e668abc87c8fb35c22b85884780c8f7 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Mon, 17 Mar 2025 09:16:00 +0100 Subject: [PATCH] Vomit up more test cases --- test/mod_list_troubleshooter_test.dart | 437 ++++++++++++++++++++----- 1 file changed, 357 insertions(+), 80 deletions(-) diff --git a/test/mod_list_troubleshooter_test.dart b/test/mod_list_troubleshooter_test.dart index fd5860d..b70339e 100644 --- a/test/mod_list_troubleshooter_test.dart +++ b/test/mod_list_troubleshooter_test.dart @@ -130,34 +130,31 @@ void main() { expect(result.activeMods.keys.last, equals('test.mod0')); }, ); - test( - 'Should end up with half the mods every iteration until 1', - () { - final troubleshooter = ModListTroubleshooter(modList); + test('Should end up with half the mods every iteration until 1', () { + final troubleshooter = ModListTroubleshooter(modList); - var result = troubleshooter.binaryBackward(); - // Half of our initial 30 - expect(result.activeMods.length, equals(15)); - expect(result.activeMods.keys.last, equals('test.mod14')); + var result = troubleshooter.binaryBackward(); + // Half of our initial 30 + expect(result.activeMods.length, equals(15)); + expect(result.activeMods.keys.last, equals('test.mod14')); - result = troubleshooter.binaryForward(); - // Half of our previous result - expect(result.activeMods.length, equals(8)); - expect(result.activeMods.keys.first, equals('test.mod7')); + result = troubleshooter.binaryForward(); + // Half of our previous result + expect(result.activeMods.length, equals(8)); + expect(result.activeMods.keys.first, equals('test.mod7')); - result = troubleshooter.binaryBackward(); - expect(result.activeMods.length, equals(4)); - expect(result.activeMods.keys.last, equals('test.mod10')); + result = troubleshooter.binaryBackward(); + expect(result.activeMods.length, equals(4)); + expect(result.activeMods.keys.last, equals('test.mod10')); - result = troubleshooter.binaryForward(); - expect(result.activeMods.length, equals(2)); - expect(result.activeMods.keys.first, equals('test.mod9')); + result = troubleshooter.binaryForward(); + expect(result.activeMods.length, equals(2)); + expect(result.activeMods.keys.first, equals('test.mod9')); - result = troubleshooter.binaryBackward(); - expect(result.activeMods.length, equals(1)); - expect(result.activeMods.keys.last, equals('test.mod9')); - }, - ); + result = troubleshooter.binaryBackward(); + expect(result.activeMods.length, equals(1)); + expect(result.activeMods.keys.last, equals('test.mod9')); + }); test('Should handle abuse gracefully', () { final troubleshooter = ModListTroubleshooter(modList); @@ -224,48 +221,42 @@ void main() { modList.enableAll(); }); - test( - 'Should end up with 10 mods every forward iteration', - () { - final troubleshooter = ModListTroubleshooter(modList); + test('Should end up with 10 mods every forward iteration', () { + 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')); + 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.linearForward(stepSize: 10); - expect(result.activeMods.length, equals(10)); - expect(result.activeMods.keys.first, equals('test.mod10')); - expect(result.activeMods.keys.last, equals('test.mod19')); + result = troubleshooter.linearForward(stepSize: 10); + expect(result.activeMods.length, equals(10)); + expect(result.activeMods.keys.first, equals('test.mod10')); + expect(result.activeMods.keys.last, equals('test.mod19')); - result = troubleshooter.linearForward(stepSize: 10); - expect(result.activeMods.length, equals(10)); - expect(result.activeMods.keys.first, equals('test.mod20')); - expect(result.activeMods.keys.last, equals('test.mod29')); - }, - ); - test( - 'Should end up with 10 mods every backward iteration', - () { - final troubleshooter = ModListTroubleshooter(modList); + result = troubleshooter.linearForward(stepSize: 10); + expect(result.activeMods.length, equals(10)); + expect(result.activeMods.keys.first, equals('test.mod20')); + expect(result.activeMods.keys.last, equals('test.mod29')); + }); + test('Should end up with 10 mods every backward iteration', () { + final troubleshooter = ModListTroubleshooter(modList); - var 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')); + var 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')); - result = troubleshooter.linearBackward(stepSize: 10); - expect(result.activeMods.length, equals(10)); - expect(result.activeMods.keys.first, equals('test.mod10')); - expect(result.activeMods.keys.last, equals('test.mod19')); + result = troubleshooter.linearBackward(stepSize: 10); + expect(result.activeMods.length, equals(10)); + expect(result.activeMods.keys.first, equals('test.mod10')); + expect(result.activeMods.keys.last, equals('test.mod19')); - 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.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')); + }); test('Should end up with 10 mods every iteration', () { final troubleshooter = ModListTroubleshooter(modList); @@ -355,38 +346,324 @@ void main() { 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')); + }); + + test('Complex navigation sequence should work correctly', () { + final troubleshooter = ModListTroubleshooter(modList); + + var result = troubleshooter.binaryForward(); + expect(result.activeMods.length, equals(15)); + expect(result.activeMods.keys.first, equals('test.mod15')); + + result = troubleshooter.linearBackward(stepSize: 5); + expect(result.activeMods.length, equals(5)); + expect(result.activeMods.keys.first, equals('test.mod25')); + expect(result.activeMods.keys.last, equals('test.mod29')); + + result = troubleshooter.binaryForward(); + expect(result.activeMods.length, equals(3)); + expect(result.activeMods.keys.first, equals('test.mod27')); + + result = troubleshooter.linearForward(stepSize: 2); + expect(result.activeMods.length, equals(2)); + expect(result.activeMods.keys.first, equals('test.mod27')); + expect(result.activeMods.keys.last, equals('test.mod28')); + + result = troubleshooter.binaryBackward(); + expect(result.activeMods.length, equals(1)); + expect(result.activeMods.keys.first, equals('test.mod27')); + }); + + test('Varying step sizes in linear navigation', () { + final troubleshooter = ModListTroubleshooter(modList); + + var result = troubleshooter.linearForward(stepSize: 15); + expect(result.activeMods.length, equals(15)); + expect(result.activeMods.keys.first, equals('test.mod0')); + expect(result.activeMods.keys.last, equals('test.mod14')); + + result = troubleshooter.linearForward(stepSize: 5); + expect(result.activeMods.length, equals(5)); + expect(result.activeMods.keys.first, equals('test.mod0')); + expect(result.activeMods.keys.last, equals('test.mod4')); + + result = troubleshooter.linearForward(stepSize: 2); + expect(result.activeMods.length, equals(2)); + expect(result.activeMods.keys.first, equals('test.mod0')); + expect(result.activeMods.keys.last, equals('test.mod1')); + + result = troubleshooter.linearBackward(stepSize: 3); + expect(result.activeMods.length, equals(3)); + expect(result.activeMods.keys.first, equals('test.mod0')); + expect(result.activeMods.keys.last, equals('test.mod2')); + + result = troubleshooter.linearBackward(stepSize: 7); + expect(result.activeMods.length, equals(7)); + expect(result.activeMods.keys.first, equals('test.mod0')); + expect(result.activeMods.keys.last, equals('test.mod6')); + }); + + test('Edge case - switching approaches at the boundary', () { + final troubleshooter = ModListTroubleshooter(modList); + + var 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')); + + result = troubleshooter.linearBackward(stepSize: 10); + expect(result.activeMods.length, equals(10)); + expect(result.activeMods.keys.first, equals('test.mod10')); + expect(result.activeMods.keys.last, equals('test.mod19')); + + 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.linearBackward(stepSize: 2); + expect(result.activeMods.length, equals(2)); + expect(result.activeMods.keys.first, equals('test.mod8')); + expect(result.activeMods.keys.last, equals('test.mod9')); + }); + + test('Testing reset/restart behavior', () { + final troubleshooter = ModListTroubleshooter(modList); + + // Do some navigation first + var result = troubleshooter.linearForward(stepSize: 5); + expect(result.activeMods.length, equals(5)); + + result = troubleshooter.binaryForward(); + expect(result.activeMods.length, equals(3)); + + // Create a new troubleshooter with the same mod list (simulating reset) + final newTroubleshooter = ModListTroubleshooter(modList); + + // First operation should work as if we're starting fresh + result = newTroubleshooter.binaryForward(); + expect(result.activeMods.length, equals(15)); + expect(result.activeMods.keys.first, equals('test.mod15')); + + // Original troubleshooter should still be in its own state + result = troubleshooter.linearForward(stepSize: 1); + expect(result.activeMods.length, equals(1)); + }); + + test('Alternate between multiple approaches repeatedly', () { + final troubleshooter = ModListTroubleshooter(modList); + + // Alternate between binary and linear several times + var result = troubleshooter.binaryForward(); + expect(result.activeMods.length, equals(15)); + + result = troubleshooter.linearBackward(stepSize: 5); + expect(result.activeMods.length, equals(5)); + + result = troubleshooter.binaryForward(); + expect(result.activeMods.length, equals(3)); + + result = troubleshooter.linearBackward(stepSize: 1); + expect(result.activeMods.length, equals(1)); + + result = troubleshooter.linearForward(stepSize: 10); + expect(result.activeMods.length, equals(10)); + + result = troubleshooter.binaryBackward(); + expect(result.activeMods.length, equals(5)); + + // Final set of mods should be consistent with the operations performed + expect(result.activeMods.length, equals(5)); + }); + + // These tests specifically examine the nuances of linear navigation + test('Linear navigation window adjustment - forward', () { + final troubleshooter = ModListTroubleshooter(modList); + + // First linearForward with a specific step size + var result = troubleshooter.linearForward(stepSize: 8); + expect(result.activeMods.length, equals(8)); + expect(result.activeMods.keys.first, equals('test.mod0')); + expect(result.activeMods.keys.last, equals('test.mod7')); + + // Second call should move forward since current selection size matches step size + result = troubleshooter.linearForward(stepSize: 8); + expect(result.activeMods.length, equals(8)); + expect(result.activeMods.keys.first, equals('test.mod8')); + expect(result.activeMods.keys.last, equals('test.mod15')); + + // Change step size - should adapt the window size without moving position + result = troubleshooter.linearForward(stepSize: 5); + expect(result.activeMods.length, equals(5)); + expect(result.activeMods.keys.first, equals('test.mod8')); + expect(result.activeMods.keys.last, equals('test.mod12')); + + // Move forward with new step size + result = troubleshooter.linearForward(stepSize: 5); + expect(result.activeMods.length, equals(5)); + expect(result.activeMods.keys.first, equals('test.mod13')); + expect(result.activeMods.keys.last, equals('test.mod17')); + }); + + test('Linear navigation window adjustment - backward', () { + final troubleshooter = ModListTroubleshooter(modList); + + // Move to the end first + troubleshooter.linearBackward(stepSize: 30); + + // First linearBackward with a specific step size + var result = troubleshooter.linearBackward(stepSize: 8); + expect(result.activeMods.length, equals(8)); + expect(result.activeMods.keys.first, equals('test.mod22')); + expect(result.activeMods.keys.last, equals('test.mod29')); + + // Second call should move backward since current selection size matches step size + result = troubleshooter.linearBackward(stepSize: 8); + expect(result.activeMods.length, equals(8)); + expect(result.activeMods.keys.first, equals('test.mod14')); + expect(result.activeMods.keys.last, equals('test.mod21')); + + // Change step size - should adapt the window size without moving position + result = troubleshooter.linearBackward(stepSize: 5); + expect(result.activeMods.length, equals(5)); + expect(result.activeMods.keys.first, equals('test.mod17')); + expect(result.activeMods.keys.last, equals('test.mod21')); + + // Move backward with new step size + result = troubleshooter.linearBackward(stepSize: 5); + expect(result.activeMods.length, equals(5)); + expect(result.activeMods.keys.first, equals('test.mod12')); + expect(result.activeMods.keys.last, equals('test.mod16')); + }); + + test('Linear navigation boundary handling - forward', () { + final troubleshooter = ModListTroubleshooter(modList); + + var result = troubleshooter.linearForward(stepSize: 25); + expect(result.activeMods.length, equals(25)); + expect(result.activeMods.keys.first, equals('test.mod0')); + + 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.linearForward(stepSize: 10); + expect(result.activeMods.length, equals(10)); + expect(result.activeMods.keys.first, equals('test.mod10')); + expect(result.activeMods.keys.last, equals('test.mod19')); + + result = troubleshooter.linearForward(stepSize: 3); + expect(result.activeMods.length, equals(3)); + expect(result.activeMods.keys.first, equals('test.mod10')); + expect(result.activeMods.keys.last, equals('test.mod12')); + }); + + test('Linear navigation boundary handling - backward', () { + final troubleshooter = ModListTroubleshooter(modList); + + troubleshooter.linearForward(stepSize: 30); + + var result = troubleshooter.linearBackward(stepSize: 25); + expect(result.activeMods.length, equals(25)); + expect(result.activeMods.keys.first, equals('test.mod5')); + expect(result.activeMods.keys.last, equals('test.mod29')); + + 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')); + + result = troubleshooter.linearBackward(stepSize: 10); + expect(result.activeMods.length, equals(10)); + expect(result.activeMods.keys.first, equals('test.mod10')); + expect(result.activeMods.keys.last, equals('test.mod19')); + + result = troubleshooter.linearBackward(stepSize: 3); + expect(result.activeMods.length, equals(3)); + expect(result.activeMods.keys.first, equals('test.mod17')); + expect(result.activeMods.keys.last, equals('test.mod19')); + }); + + // Test to verify we always get the requested number of mods at boundaries test( - 'Mixed navigation should work', + 'Linear navigation always returns exactly stepSize mods when possible', () { 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')); + troubleshooter.linearForward(stepSize: 23); + var result = troubleshooter.linearForward(stepSize: 7); + expect(result.activeMods.length, equals(7)); - 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: 7); + expect(result.activeMods.length, equals(7)); - 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.linearBackward(stepSize: 23); + expect(result.activeMods.length, equals(23)); - 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: 8); + expect(result.activeMods.length, equals(8)); - 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')); + result = troubleshooter.linearBackward(stepSize: 8); + expect(result.activeMods.length, equals(8)); }, ); + + test('Linear navigation with oversized steps', () { + final troubleshooter = ModListTroubleshooter(modList); + + // Step size larger than total mods + var result = troubleshooter.linearForward(stepSize: 50); + expect(result.activeMods.length, equals(30)); // All 30 mods + expect(result.activeMods.keys.first, equals('test.mod0')); + expect(result.activeMods.keys.last, equals('test.mod29')); + + // Forward with oversized step should still return all mods + result = troubleshooter.linearForward(stepSize: 50); + expect(result.activeMods.length, equals(30)); // Still all 30 mods + + // Now with backward + result = troubleshooter.linearBackward(stepSize: 50); + expect(result.activeMods.length, equals(30)); // All 30 mods + + // Another backward with oversized step + result = troubleshooter.linearBackward(stepSize: 50); + expect(result.activeMods.length, equals(30)); // Still all 30 mods + }); }); + group('Loading dependencies', () { late ModList modList = ModList(); setUp(() {