Introduce 'pairwise' function, KEEP-11

This commit is contained in:
Ilya Gorbunov
2017-04-26 23:49:11 +03:00
parent b73be50e5b
commit c815ccfd6a
15 changed files with 298 additions and 1 deletions
+13 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -837,6 +837,18 @@ class StringTest {
assertContentEquals("abc", pair.second, "pair.second")
}
@Test fun pairwise() = withOneCharSequenceArg { arg1 ->
assertEquals(listOf("ab", "bc"), arg1("abc").pairwise { a, b -> a.toString() + b })
assertTrue(arg1("").pairwise { a, b -> a.toString() + b }.isEmpty())
assertTrue(arg1("a").pairwise { a, b -> a.toString() + b }.isEmpty())
}
@Test fun pairwisePairs() = withOneCharSequenceArg { arg1 ->
assertEquals(listOf('a' to 'b', 'b' to 'c'), arg1("abc").pairwise())
assertTrue(arg1("").pairwise().isEmpty())
assertTrue(arg1("a").pairwise().isEmpty())
}
@Test fun map() = withOneCharSequenceArg { arg1 ->
assertEquals(listOf('a', 'b', 'c'), arg1("abc").map { it })