@@ -50,11 +50,11 @@ public void Test_ReadOnlyRefEnumerable_DangerousCreate_BelowZero(int length, int
50
50
51
51
[ TestCategory ( "ReadOnlyRefEnumerable" ) ]
52
52
[ TestMethod ]
53
- [ DataRow ( 1 , 1 , new [ ] { 1 } ) ]
54
- [ DataRow ( 4 , 1 , new [ ] { 1 , 2 , 3 , 4 } ) ]
55
- [ DataRow ( 4 , 4 , new [ ] { 1 , 5 , 9 , 13 } ) ]
56
- [ DataRow ( 4 , 5 , new [ ] { 1 , 6 , 11 , 16 } ) ]
57
- public void Test_ReadOnlyRefEnumerable_Indexer ( int length , int step , int [ ] values )
53
+ [ DataRow ( 1 , new [ ] { 1 } ) ]
54
+ [ DataRow ( 1 , new [ ] { 1 , 2 , 3 , 4 } ) ]
55
+ [ DataRow ( 4 , new [ ] { 1 , 5 , 9 , 13 } ) ]
56
+ [ DataRow ( 5 , new [ ] { 1 , 6 , 11 , 16 } ) ]
57
+ public void Test_ReadOnlyRefEnumerable_Indexer ( int step , int [ ] values )
58
58
{
59
59
Span < int > data = new [ ]
60
60
{
@@ -64,22 +64,35 @@ public void Test_ReadOnlyRefEnumerable_Indexer(int length, int step, int[] value
64
64
13 , 14 , 15 , 16
65
65
} ;
66
66
67
- ReadOnlyRefEnumerable < int > enumerable = ReadOnlyRefEnumerable < int > . DangerousCreate ( in data [ 0 ] , length , step ) ;
67
+ ReadOnlyRefEnumerable < int > enumerable = ReadOnlyRefEnumerable < int > . DangerousCreate ( in data [ 0 ] , values . Length , step ) ;
68
68
69
69
for ( int i = 0 ; i < enumerable . Length ; i ++ )
70
70
{
71
71
Assert . AreEqual ( enumerable [ i ] , values [ i ] ) ;
72
72
}
73
73
}
74
74
75
+ [ TestCategory ( "ReadOnlyRefEnumerable" ) ]
76
+ [ TestMethod ]
77
+ public void Test_ReadOnlyRefEnumerable_Indexer_ThrowsIndexOutOfRange ( )
78
+ {
79
+ int [ ] array = new [ ]
80
+ {
81
+ 0 , 0 , 0 , 0
82
+ } ;
83
+
84
+ Assert . ThrowsException < IndexOutOfRangeException > ( ( ) => ReadOnlyRefEnumerable < int > . DangerousCreate ( in array [ 0 ] , array . Length , 1 ) [ - 1 ] ) ;
85
+ Assert . ThrowsException < IndexOutOfRangeException > ( ( ) => ReadOnlyRefEnumerable < int > . DangerousCreate ( in array [ 0 ] , array . Length , 1 ) [ array . Length ] ) ;
86
+ }
87
+
75
88
#if NETCOREAPP3_1_OR_GREATER
76
89
[ TestCategory ( "ReadOnlyRefEnumerable" ) ]
77
90
[ TestMethod ]
78
- [ DataRow ( 1 , 1 , new [ ] { 1 } ) ]
79
- [ DataRow ( 4 , 1 , new [ ] { 1 , 2 , 3 , 4 } ) ]
80
- [ DataRow ( 4 , 4 , new [ ] { 1 , 5 , 9 , 13 } ) ]
81
- [ DataRow ( 4 , 5 , new [ ] { 1 , 6 , 11 , 16 } ) ]
82
- public void Test_ReadOnlyRefEnumerable_Index_Indexer ( int length , int step , int [ ] values )
91
+ [ DataRow ( 1 , new [ ] { 1 } ) ]
92
+ [ DataRow ( 1 , new [ ] { 1 , 2 , 3 , 4 } ) ]
93
+ [ DataRow ( 4 , new [ ] { 1 , 5 , 9 , 13 } ) ]
94
+ [ DataRow ( 5 , new [ ] { 1 , 6 , 11 , 16 } ) ]
95
+ public void Test_ReadOnlyRefEnumerable_Index_Indexer ( int step , int [ ] values )
83
96
{
84
97
Span < int > data = new [ ]
85
98
{
@@ -89,9 +102,25 @@ public void Test_ReadOnlyRefEnumerable_Index_Indexer(int length, int step, int[]
89
102
13 , 14 , 15 , 16
90
103
} ;
91
104
92
- ReadOnlyRefEnumerable < int > enumerable = ReadOnlyRefEnumerable < int > . DangerousCreate ( in data [ 0 ] , length , step ) ;
105
+ ReadOnlyRefEnumerable < int > enumerable = ReadOnlyRefEnumerable < int > . DangerousCreate ( in data [ 0 ] , values . Length , step ) ;
106
+
107
+ for ( int i = 1 ; i <= enumerable . Length ; i ++ )
108
+ {
109
+ Assert . AreEqual ( values [ ^ i ] , enumerable [ ^ i ] ) ;
110
+ }
111
+ }
112
+
113
+ [ TestCategory ( "ReadOnlyRefEnumerable" ) ]
114
+ [ TestMethod ]
115
+ public void Test_ReadOnlyRefEnumerable_Index_Indexer_ThrowsIndexOutOfRange ( )
116
+ {
117
+ int [ ] array = new [ ]
118
+ {
119
+ 0 , 0 , 0 , 0
120
+ } ;
93
121
94
- Assert . AreEqual ( values [ ^ 1 ] , enumerable [ ^ 1 ] ) ;
122
+ Assert . ThrowsException < IndexOutOfRangeException > ( ( ) => ReadOnlyRefEnumerable < int > . DangerousCreate ( in array [ 0 ] , array . Length , 1 ) [ new Index ( array . Length ) ] ) ;
123
+ Assert . ThrowsException < IndexOutOfRangeException > ( ( ) => ReadOnlyRefEnumerable < int > . DangerousCreate ( in array [ 0 ] , array . Length , 1 ) [ ^ 0 ] ) ;
95
124
}
96
125
#endif
97
126
}
0 commit comments