Fix up bisect every which way
This commit is contained in:
@@ -26,7 +26,10 @@ class ModListTroubleshooter {
|
||||
|
||||
ModList binaryForward() {
|
||||
final midIndex = (_startIndex + _endIndex) ~/ 2;
|
||||
final subset = originalModList.activeMods.keys.toList().sublist(midIndex);
|
||||
final subset = originalModList.activeMods.keys.toList().sublist(
|
||||
midIndex,
|
||||
_endIndex,
|
||||
);
|
||||
currentModList.disableAll();
|
||||
currentModList.enableMods(subset);
|
||||
_startIndex = midIndex;
|
||||
@@ -36,7 +39,7 @@ class ModListTroubleshooter {
|
||||
ModList binaryBackward() {
|
||||
final midIndex = ((_startIndex + _endIndex) / 2).ceil();
|
||||
final subset = originalModList.activeMods.keys.toList().sublist(
|
||||
0,
|
||||
_startIndex,
|
||||
midIndex,
|
||||
);
|
||||
currentModList.disableAll();
|
||||
|
@@ -116,6 +116,29 @@ void main() {
|
||||
result = troubleshooter.binaryBackward();
|
||||
expect(result.activeMods.length, equals(2));
|
||||
|
||||
result = troubleshooter.binaryBackward();
|
||||
expect(result.activeMods.length, equals(1));
|
||||
},
|
||||
);
|
||||
test(
|
||||
'Bisect search 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));
|
||||
|
||||
result = troubleshooter.binaryForward();
|
||||
// Half of our previous result
|
||||
expect(result.activeMods.length, equals(8));
|
||||
|
||||
result = troubleshooter.binaryBackward();
|
||||
expect(result.activeMods.length, equals(4));
|
||||
|
||||
result = troubleshooter.binaryForward();
|
||||
expect(result.activeMods.length, equals(2));
|
||||
|
||||
result = troubleshooter.binaryBackward();
|
||||
expect(result.activeMods.length, equals(1));
|
||||
},
|
||||
|
Reference in New Issue
Block a user