Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
6d2f9cc6
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6d2f9cc6
编写于
10月 13, 2015
作者:
I
Ilya Gorbunov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove obsolete iterator tests
上级
c58d21a1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
10 addition
and
176 deletion
+10
-176
libraries/stdlib/test/collections/SequenceTest.kt
libraries/stdlib/test/collections/SequenceTest.kt
+10
-0
libraries/stdlib/test/iterators/FunctionIteratorTest.kt
libraries/stdlib/test/iterators/FunctionIteratorTest.kt
+0
-28
libraries/stdlib/test/iterators/IteratorsJVMTest.kt
libraries/stdlib/test/iterators/IteratorsJVMTest.kt
+0
-32
libraries/stdlib/test/iterators/IteratorsTest.kt
libraries/stdlib/test/iterators/IteratorsTest.kt
+0
-116
未找到文件。
libraries/stdlib/test/collections/SequenceTest.kt
浏览文件 @
6d2f9cc6
...
...
@@ -73,6 +73,11 @@ public class SequenceTest {
}
}
@
test
fun
mapIndexed
()
{
assertEquals
(
listOf
(
0
,
1
,
2
,
6
,
12
),
fibonacci
().
mapIndexed
{
index
,
value
->
index
*
value
}.
takeWhile
{
i
:
Int
->
i
<
20
}.
toList
())
}
@
test
fun
mapAndJoinToString
()
{
assertEquals
(
"3, 5, 8"
,
fibonacci
().
withIndex
().
filter
{
it
.
index
>
3
}.
take
(
3
).
joinToString
{
it
.
value
.
toString
()
})
}
...
...
@@ -126,6 +131,11 @@ public class SequenceTest {
}
}
@
test
fun
zipPairs
()
{
val
pairStr
=
(
fibonacci
()
zip
fibonacci
().
map
{
i
->
i
*
2
}).
joinToString
(
limit
=
10
)
assertEquals
(
"(0, 0), (1, 2), (1, 2), (2, 4), (3, 6), (5, 10), (8, 16), (13, 26), (21, 42), (34, 68), ..."
,
pairStr
)
}
@
test
fun
toStringJoinsNoMoreThanTheFirstTenElements
()
{
assertEquals
(
"0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ..."
,
fibonacci
().
joinToString
(
limit
=
10
))
assertEquals
(
"13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ..."
,
fibonacci
().
filter
{
it
>
10
}.
joinToString
(
limit
=
10
))
...
...
libraries/stdlib/test/iterators/FunctionIteratorTest.kt
已删除
100644 → 0
浏览文件 @
c58d21a1
package
iterators
import
kotlin.*
import
kotlin.test.*
import
org.junit.Test
class
FunctionIteratorTest
{
@Test
fun
iterateOverFunction
()
{
var
count
=
3
val
iter
=
sequence
<
Int
>
{
count--
if
(
count
>=
0
)
count
else
null
}
val
list
=
iter
.
toList
()
assertEquals
(
arrayListOf
(
2
,
1
,
0
),
list
)
}
@Test
fun
iterateOverFunction2
()
{
val
values
=
sequence
<
Int
>(
3
)
{
n
->
if
(
n
>
0
)
n
-
1
else
null
}
assertEquals
(
arrayListOf
(
3
,
2
,
1
,
0
),
values
.
toList
())
}
}
\ No newline at end of file
libraries/stdlib/test/iterators/IteratorsJVMTest.kt
已删除
100644 → 0
浏览文件 @
c58d21a1
package
iterators
import
kotlin.test.assertEquals
import
org.junit.Test
as
test
class
IteratorsJVMTest
{
@
test
fun
flatMapAndTakeExtractTheTransformedElements
()
{
fun
intToBinaryDigits
()
=
{
i
:
Int
->
val
binary
=
Integer
.
toBinaryString
(
i
)
!!
var
index
=
0
sequence
<
Char
>
{
if
(
index
<
binary
.
length
())
binary
.
get
(
index
++)
else
null
}
}
val
expected
=
arrayListOf
(
'0'
,
// fibonacci(0) = 0
'1'
,
// fibonacci(1) = 1
'1'
,
// fibonacci(2) = 1
'1'
,
'0'
,
// fibonacci(3) = 2
'1'
,
'1'
,
// fibonacci(4) = 3
'1'
,
'0'
,
'1'
// fibonacci(5) = 5
)
assertEquals
(
expected
,
fibonacci
().
flatMap
<
Int
,
Char
>(
intToBinaryDigits
()).
take
(
10
).
toList
())
}
@
test
fun
flatMapOnIterator
()
{
val
result
=
sequenceOf
(
1
,
2
).
flatMap
{
i
->
(
0
..
i
).
asSequence
()}
assertEquals
(
listOf
(
0
,
1
,
0
,
1
,
2
),
result
.
toList
())
}
}
libraries/stdlib/test/iterators/IteratorsTest.kt
已删除
100644 → 0
浏览文件 @
c58d21a1
package
iterators
import
kotlin.test.assertEquals
import
org.junit.Test
as
test
import
java.util.ArrayList
import
kotlin.test.assertFails
fun
fibonacci
():
Sequence
<
Int
>
{
// fibonacci terms
var
index
=
0
;
var
a
=
0
;
var
b
=
1
return
sequence
<
Int
>
{
when
(
index
++)
{
0
->
a
;
1
->
b
;
else
->
{
val
result
=
a
+
b
;
a
=
b
;
b
=
result
;
result
}
}
}
}
class
IteratorsTest
{
@
test
fun
filterAndTakeWhileExtractTheElementsWithinRange
()
{
assertEquals
(
arrayListOf
(
144
,
233
,
377
,
610
,
987
),
fibonacci
().
filter
{
it
>
100
}.
takeWhile
{
it
<
1000
}.
toList
())
}
@
test
fun
foldReducesTheFirstNElements
()
{
val
sum
=
{
a
:
Int
,
b
:
Int
->
a
+
b
}
assertEquals
(
arrayListOf
(
13
,
21
,
34
,
55
,
89
).
fold
(
0
,
sum
),
fibonacci
().
filter
{
it
>
10
}.
take
(
5
).
fold
(
0
,
sum
))
}
@
test
fun
takeExtractsTheFirstNElements
()
{
assertEquals
(
arrayListOf
(
0
,
1
,
1
,
2
,
3
,
5
,
8
,
13
,
21
,
34
),
fibonacci
().
take
(
10
).
toList
())
}
@
test
fun
mapAndTakeWhileExtractTheTransformedElements
()
{
assertEquals
(
arrayListOf
(
0
,
3
,
3
,
6
,
9
,
15
),
fibonacci
().
map
{
it
*
3
}.
takeWhile
{
i
:
Int
->
i
<
20
}.
toList
())
}
@
test
fun
mapIndexed
()
{
assertEquals
(
arrayListOf
(
0
,
1
,
2
,
6
,
12
),
fibonacci
().
mapIndexed
{
index
,
value
->
index
*
value
}.
takeWhile
{
i
:
Int
->
i
<
20
}.
toList
())
}
@
test
fun
joinConcatenatesTheFirstNElementsAboveAThreshold
()
{
assertEquals
(
"13, 21, 34, 55, 89, ..."
,
fibonacci
().
filter
{
it
>
10
}.
joinToString
(
separator
=
", "
,
limit
=
5
))
}
@
test
fun
plus
()
{
val
iter
=
arrayListOf
(
"foo"
,
"bar"
).
asSequence
()
val
iter2
=
iter
+
"cheese"
assertEquals
(
arrayListOf
(
"foo"
,
"bar"
,
"cheese"
),
iter2
.
toList
())
// lets use a mutable variable
var
mi
=
sequenceOf
(
"a"
,
"b"
)
mi
+=
"c"
assertEquals
(
arrayListOf
(
"a"
,
"b"
,
"c"
),
mi
.
toList
())
}
@
test
fun
plusCollection
()
{
val
a
=
arrayListOf
(
"foo"
,
"bar"
)
val
b
=
arrayListOf
(
"cheese"
,
"wine"
)
val
iter
=
a
.
asSequence
()
+
b
.
asSequence
()
assertEquals
(
arrayListOf
(
"foo"
,
"bar"
,
"cheese"
,
"wine"
),
iter
.
toList
())
// lets use a mutable variable
var
ml
=
arrayListOf
(
"a"
).
asSequence
()
ml
+=
a
.
asSequence
()
ml
+=
"beer"
ml
+=
b
ml
+=
"z"
assertEquals
(
arrayListOf
(
"a"
,
"foo"
,
"bar"
,
"beer"
,
"cheese"
,
"wine"
,
"z"
),
ml
.
toList
())
}
@
test
fun
requireNoNulls
()
{
val
iter
=
arrayListOf
<
String
?>(
"foo"
,
"bar"
).
asSequence
()
val
notNull
=
iter
.
requireNoNulls
()
assertEquals
(
arrayListOf
(
"foo"
,
"bar"
),
notNull
.
toList
())
val
iterWithNulls
=
arrayListOf
(
"foo"
,
null
,
"bar"
).
asSequence
()
val
notNull2
=
iterWithNulls
.
requireNoNulls
()
assertFails
{
// should throw an exception as we have a null
notNull2
.
toList
()
}
}
@
test
fun
toStringJoinsNoMoreThanTheFirstTenElements
()
{
assertEquals
(
"0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ..."
,
fibonacci
().
joinToString
(
limit
=
10
))
assertEquals
(
"13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ..."
,
fibonacci
().
filter
{
it
>
10
}.
joinToString
(
limit
=
10
))
assertEquals
(
"144, 233, 377, 610, 987"
,
fibonacci
().
filter
{
it
>
100
}.
takeWhile
{
it
<
1000
}.
joinToString
())
}
@
test
fun
pairIterator
()
{
val
pairStr
=
(
fibonacci
()
zip
fibonacci
().
map
{
i
->
i
*
2
}).
joinToString
(
limit
=
10
)
assertEquals
(
"(0, 0), (1, 2), (1, 2), (2, 4), (3, 6), (5, 10), (8, 16), (13, 26), (21, 42), (34, 68), ..."
,
pairStr
)
}
@
test
fun
skippingIterator
()
{
assertEquals
(
"13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ..."
,
fibonacci
().
drop
(
7
).
joinToString
(
limit
=
10
))
assertEquals
(
"13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ..."
,
fibonacci
().
drop
(
3
).
drop
(
4
).
joinToString
(
limit
=
10
))
}
@
test
fun
iterationOverIterator
()
{
val
c
=
arrayListOf
(
0
,
1
,
2
,
3
,
4
,
5
)
var
s
=
""
for
(
i
in
c
.
iterator
())
{
s
=
s
+
i
.
toString
()
}
assertEquals
(
"012345"
,
s
)
}
private
fun
<
T
,
C
:
MutableCollection
<
in
T
>>
Iterator
<
T
>.
takeWhileTo
(
result
:
C
,
predicate
:
(
T
)
->
Boolean
):
C
{
for
(
element
in
this
)
if
(
predicate
(
element
))
result
.
add
(
element
)
else
break
return
result
}
@
test
fun
iterableExtension
()
{
val
c
=
arrayListOf
(
0
,
1
,
2
,
3
,
4
,
5
)
val
d
=
ArrayList
<
Int
>()
c
.
iterator
().
takeWhileTo
(
d
,
{
i
->
i
<
4
})
assertEquals
(
4
,
d
.
size
())
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录