@@ -6,20 +6,25 @@ import kotlin.test.Test
6
6
import kotlin.test.assertFailsWith
7
7
import kotlin.test.assertTrue
8
8
9
- class CollectionsTest {
9
+ internal class CollectionsTest {
10
10
11
11
private val numbers: List <Int > = listOf (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 )
12
- private val chars: Iterable <Char > = listOf (' A' , ' B' , ' C' , ' D' , ' E' , ' F' ).asIterable()
13
- private val empty: List <String > = emptyList()
14
- private val emptyIterable: Iterable <String > = emptyList<String >().asIterable()
12
+ private val numbersIterable: Iterable <Int > = IntRange (1 , 10 )
13
+ private val chars: List <Char > = listOf (' A' , ' B' , ' C' , ' D' , ' E' , ' F' )
14
+ private val charsIterable: Iterable <Char > = CharRange (' A' , ' F' )
15
+ private val empty: List <Char > = emptyList()
16
+ private val emptyIterable: Iterable <Char > = CharRange .EMPTY
15
17
16
18
@Test
17
19
fun collection_second () {
18
20
assertTrue { numbers.second() == 2 }
21
+ assertTrue { numbersIterable.second() == 2 }
19
22
assertTrue { numbers.secondOrNull() == 2 }
23
+ assertTrue { numbersIterable.secondOrNull() == 2 }
20
24
21
25
assertTrue { chars.second() == ' B' }
22
- assertTrue { chars.secondOrNull() == ' B' }
26
+ assertTrue { charsIterable.second() == ' B' }
27
+ assertTrue { charsIterable.secondOrNull() == ' B' }
23
28
24
29
assertFailsWith<NoSuchElementException > { empty.second() }
25
30
assertFailsWith<NoSuchElementException > { emptyIterable.second() }
@@ -31,10 +36,14 @@ class CollectionsTest {
31
36
@Test
32
37
fun collection_third () {
33
38
assertTrue { numbers.third() == 3 }
39
+ assertTrue { numbersIterable.third() == 3 }
34
40
assertTrue { numbers.thirdOrNull() == 3 }
41
+ assertTrue { numbersIterable.thirdOrNull() == 3 }
35
42
36
43
assertTrue { chars.third() == ' C' }
44
+ assertTrue { charsIterable.third() == ' C' }
37
45
assertTrue { chars.thirdOrNull() == ' C' }
46
+ assertTrue { charsIterable.thirdOrNull() == ' C' }
38
47
39
48
assertFailsWith<NoSuchElementException > { empty.third() }
40
49
assertFailsWith<NoSuchElementException > { emptyIterable.third() }
@@ -46,10 +55,13 @@ class CollectionsTest {
46
55
@Test
47
56
fun collection_forth () {
48
57
assertTrue { numbers.forth() == 4 }
58
+ assertTrue { numbersIterable.forth() == 4 }
49
59
assertTrue { numbers.forthOrNull() == 4 }
60
+ assertTrue { numbersIterable.forthOrNull() == 4 }
50
61
51
62
assertTrue { chars.forth() == ' D' }
52
- assertTrue { chars.forthOrNull() == ' D' }
63
+ assertTrue { charsIterable.forth() == ' D' }
64
+ assertTrue { charsIterable.forthOrNull() == ' D' }
53
65
54
66
assertFailsWith<NoSuchElementException > { empty.forth() }
55
67
assertFailsWith<NoSuchElementException > { emptyIterable.forth() }
@@ -61,10 +73,14 @@ class CollectionsTest {
61
73
@Test
62
74
fun collection_fifth () {
63
75
assertTrue { numbers.fifth() == 5 }
76
+ assertTrue { numbersIterable.fifth() == 5 }
64
77
assertTrue { numbers.fifthOrNull() == 5 }
78
+ assertTrue { numbersIterable.fifthOrNull() == 5 }
65
79
66
80
assertTrue { chars.fifth() == ' E' }
81
+ assertTrue { charsIterable.fifth() == ' E' }
67
82
assertTrue { chars.fifthOrNull() == ' E' }
83
+ assertTrue { charsIterable.fifthOrNull() == ' E' }
68
84
69
85
assertFailsWith<NoSuchElementException > { empty.fifth() }
70
86
assertFailsWith<NoSuchElementException > { emptyIterable.fifth() }
@@ -76,10 +92,14 @@ class CollectionsTest {
76
92
@Test
77
93
fun collection_penultimate () {
78
94
assertTrue { numbers.penultimate() == 9 }
95
+ assertTrue { numbersIterable.penultimate() == 9 }
79
96
assertTrue { numbers.penultimateOrNull() == 9 }
97
+ assertTrue { numbersIterable.penultimateOrNull() == 9 }
80
98
81
99
assertTrue { chars.penultimate() == ' E' }
100
+ assertTrue { charsIterable.penultimate() == ' E' }
82
101
assertTrue { chars.penultimateOrNull() == ' E' }
102
+ assertTrue { charsIterable.penultimateOrNull() == ' E' }
83
103
84
104
assertFailsWith<NoSuchElementException > { empty.penultimate() }
85
105
assertFailsWith<NoSuchElementException > { emptyIterable.penultimate() }
0 commit comments