Implement backward bisect
This commit is contained in:
@@ -34,6 +34,14 @@ class ModListTroubleshooter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ModList binaryBackward() {
|
ModList binaryBackward() {
|
||||||
|
final midIndex = ((_startIndex + _endIndex) / 2).ceil();
|
||||||
|
final subset = originalModList.activeMods.keys.toList().sublist(
|
||||||
|
0,
|
||||||
|
midIndex,
|
||||||
|
);
|
||||||
|
currentModList.disableAll();
|
||||||
|
currentModList.enableMods(subset);
|
||||||
|
_endIndex = midIndex;
|
||||||
return currentModList;
|
return currentModList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -97,5 +97,28 @@ void main() {
|
|||||||
expect(result.activeMods.length, equals(1));
|
expect(result.activeMods.length, equals(1));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
test(
|
||||||
|
'Bisect search should end up with half the mods every backward iteration until 1',
|
||||||
|
() {
|
||||||
|
final troubleshooter = ModListTroubleshooter(modList);
|
||||||
|
|
||||||
|
var result = troubleshooter.binaryBackward();
|
||||||
|
// Half of our initial 30
|
||||||
|
expect(result.activeMods.length, equals(15));
|
||||||
|
|
||||||
|
result = troubleshooter.binaryBackward();
|
||||||
|
// Half of our previous result
|
||||||
|
expect(result.activeMods.length, equals(8));
|
||||||
|
|
||||||
|
result = troubleshooter.binaryBackward();
|
||||||
|
expect(result.activeMods.length, equals(4));
|
||||||
|
|
||||||
|
result = troubleshooter.binaryBackward();
|
||||||
|
expect(result.activeMods.length, equals(2));
|
||||||
|
|
||||||
|
result = troubleshooter.binaryBackward();
|
||||||
|
expect(result.activeMods.length, equals(1));
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user