Closed MHQB closed 9 months ago
i'm on the master branch btw, since i encountered the endless loop issue in 4.0.0.
thanks! you can try out the potential fix in #22
That solved the issue, thanks. btw the following snippet suggests a property-based testing method that can generate a large number of random list of ints to make sure that the end result of the diff algorithm is correct. It could be useful for you to add some test units like this:
import 'package:collection/collection.dart';
import 'package:diffutil_dart/diffutil.dart';
import 'package:fpdart/fpdart.dart';
main() {
List<int> randomIntList(int maxLength) => List.generate(
randomInt(0, maxLength).run(), (_) => randomInt(0, 10000).run());
({List<int> init, List<int> expected}) randomIntListPair() =>
(init: randomIntList(100), expected: randomIntList(200));
final tenThousandTestCases = List.generate(10000, (_) => randomIntListPair());
// ensuring property: b.equals(applyDiffs(a, diff(a, b)))
final result = tenThousandTestCases
.map((t) => t.expected.equals(applyDiffs(
t.init,
calculateListDiff(t.init, t.expected, detectMoves: true)
.getUpdatesWithData(),
)))
.fold(
(success: 0, failure: 0),
(state, testUnit) => switch (testUnit) {
true => (success: state.success + 1, failure: state.failure),
false => (success: state.success, failure: state.failure + 1),
});
print(result); // prints (failure: 0, success: 10000), it's all good now :)
}
applyDiffs(...)...
Thanks! I'll add something like that when I have time!
I published 4.0.1 with the fix from #22
The first test case in the following snippet works correctly but not the second one. Am I doing something wrong?