44 lines
1.1 KiB
Dart
44 lines
1.1 KiB
Dart
import "package:test/test.dart";
|
|
import "package:clawd_code/src/utils/array_utils.dart";
|
|
|
|
|
|
void main() {
|
|
group("intersperse", () {
|
|
test("adds separator between elements", () {
|
|
final result = intersperse([1, 2, 3], (_) => 0);
|
|
expect(result, equals([1, 0, 2, 0, 3]));
|
|
});
|
|
|
|
test("empty list stays empty", () {
|
|
expect(intersperse([], (_) => 0), isEmpty);
|
|
});
|
|
|
|
test("single element no separator", () {
|
|
expect(intersperse([42], (_) => 0), equals([42]));
|
|
});
|
|
});
|
|
|
|
group("countWhere", () {
|
|
test("counts matching elements", () {
|
|
expect(countWhere([1, 2, 3, 4, 5], (x) => x % 2 == 0), equals(2));
|
|
});
|
|
|
|
test("zero when none match", () {
|
|
expect(countWhere([1, 3, 5], (x) => x % 2 == 0), equals(0));
|
|
});
|
|
});
|
|
|
|
group("uniq", () {
|
|
test("removes duplicates preserving order", () {
|
|
expect(uniq([1, 2, 1, 3, 2, 4]), equals([1, 2, 3, 4]));
|
|
});
|
|
|
|
test("empty stays empty", () {
|
|
expect(uniq([]), isEmpty);
|
|
});
|
|
|
|
test("strings work too", () {
|
|
expect(uniq(["a", "b", "a", "c"]), equals(["a", "b", "c"]));
|
|
});
|
|
});
|
|
}
|