diff --git a/test/collection/iterable_extensions_test.dart b/test/collection/iterable_extensions_test.dart index 064b1ced..ed90889d 100644 --- a/test/collection/iterable_extensions_test.dart +++ b/test/collection/iterable_extensions_test.dart @@ -587,6 +587,53 @@ void testIterable(KIterable Function() emptyIterable, }); }); + group("fold", () { + if (ordered) { + test("fold division", () { + final iterable = iterableOf([ + [1, 2], + [3, 4], + [5, 6] + ]); + final result = iterable.fold( + listOf(), (KList acc, it) => acc + listOf(it)); + expect(result, listOf([1, 2, 3, 4, 5, 6])); + }); + } + + test("operation must be non null", () { + final e = catchException( + () => emptyIterable().fold("foo", null)); + expect(e.message, allOf(contains("null"), contains("operation"))); + }); + }); + + group("foldIndexed", () { + if (ordered) { + test("foldIndexed division", () { + final iterable = iterableOf([ + [1, 2], + [3, 4], + [5, 6] + ]); + var i = 0; + final result = + iterable.foldIndexed(listOf(), (index, KList acc, it) { + expect(index, i); + i++; + return acc + listOf(it); + }); + expect(result, listOf([1, 2, 3, 4, 5, 6])); + }); + } + + test("operation must be non null", () { + final e = catchException( + () => emptyIterable().foldIndexed("foo", null)); + expect(e.message, allOf(contains("null"), contains("operation"))); + }); + }); + group("groupBy", () { if (ordered) { test("basic", () { @@ -1052,6 +1099,32 @@ void testIterable(KIterable Function() emptyIterable, }); }); + group("reduceIndexed", () { + test("reduceIndexed", () { + var i = 1; + final result = + iterableOf([1, 2, 3, 4]).reduceIndexed((index, int acc, it) { + expect(index, i); + i++; + return it + acc; + }); + expect(result, 10); + }); + + test("empty throws", () { + expect( + () => emptyIterable() + .reduceIndexed((index, int acc, it) => it + acc), + throwsUnsupportedError); + }); + + test("reduceIndexed doesn't allow null as operation", () { + final iterable = emptyIterable(); + var e = catchException(() => iterable.reduceIndexed(null)); + expect(e.message, allOf(contains("null"), contains("operation"))); + }); + }); + group("reversed", () { test("mutliple", () { final result = iterableOf([1, 2, 3, 4]).reversed(); diff --git a/test/collection/list_extensions_test.dart b/test/collection/list_extensions_test.dart index a63485e2..a72118e2 100644 --- a/test/collection/list_extensions_test.dart +++ b/test/collection/list_extensions_test.dart @@ -52,6 +52,49 @@ void main() { }); }); + group("foldRight", () { + test("foldRight division", () { + final iterable = listOf([ + [1, 2], + [3, 4], + [5, 6] + ]); + final result = iterable.foldRight( + listOf(), (it, KList acc) => acc + listOf(it)); + expect(result, listOf([5, 6, 3, 4, 1, 2])); + }); + + test("operation must be non null", () { + final e = catchException( + () => emptyList().foldRight("foo", null)); + expect(e.message, allOf(contains("null"), contains("operation"))); + }); + }); + + group("foldRightIndexed", () { + test("foldRightIndexed division", () { + final iterable = listOf([ + [1, 2], + [3, 4], + [5, 6] + ]); + var i = 2; + final result = + iterable.foldRightIndexed(listOf(), (index, it, KList acc) { + expect(index, i); + i--; + return acc + listOf(it); + }); + expect(result, listOf([5, 6, 3, 4, 1, 2])); + }); + + test("operation must be non null", () { + final e = catchException( + () => emptyList().foldRightIndexed("foo", null)); + expect(e.message, allOf(contains("null"), contains("operation"))); + }); + }); + group("first", () { test("get first element", () { expect(listOf(["a", "b"]).first(), "a"); @@ -99,6 +142,7 @@ void main() { expect(e.message, allOf(contains("null"), contains("defaultValue"))); }); }); + group("getOrNull", () { test("get item", () { final list = listOf(["a", "b", "c"]); diff --git a/test/collection/list_test.dart b/test/collection/list_test.dart index ecf90d32..ac8010c0 100644 --- a/test/collection/list_test.dart +++ b/test/collection/list_test.dart @@ -115,6 +115,33 @@ void main() { }); }); + group("reduceRightIndexed", () { + test("reduceRightIndexed", () { + var i = 2; + final result = + listOf([1, 2, 3, 4]).reduceRightIndexed((index, it, int acc) { + expect(index, i); + i--; + return it + acc; + }); + expect(result, 10); + }); + + test("empty throws", () { + expect( + () => emptyList() + .reduceRightIndexed((index, it, int acc) => it + acc), + throwsUnsupportedError); + }); + + test("reduceRightIndexed doesn't allow null as operation", () { + final list = emptyList(); + var e = + catchException(() => list.reduceRightIndexed(null)); + expect(e.message, allOf(contains("null"), contains("operation"))); + }); + }); + test("sublist works ", () { final list = listOf(["a", "b", "c"]); final subList = list.subList(1, 3);