33using System . Linq ;
44using System . Text ;
55using System . Threading ;
6- using NUnit . Framework ;
6+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
77
88namespace ZstdNet . Tests
99{
10- [ TestFixture ]
10+ [ TestClass ]
1111 public class Binding_Tests
1212 {
1313 public enum CompressionLevel
@@ -17,8 +17,14 @@ public enum CompressionLevel
1717 Max
1818 }
1919
20- [ Test ]
21- public void CompressAndDecompress_workCorrectly ( [ Values ( false , true ) ] bool useDictionary , [ Values ( CompressionLevel . Min , CompressionLevel . Default , CompressionLevel . Max ) ] CompressionLevel level )
20+ [ TestMethod ]
21+ [ DataRow ( true , CompressionLevel . Min ) ]
22+ [ DataRow ( true , CompressionLevel . Default ) ]
23+ [ DataRow ( true , CompressionLevel . Max ) ]
24+ [ DataRow ( false , CompressionLevel . Min ) ]
25+ [ DataRow ( false , CompressionLevel . Default ) ]
26+ [ DataRow ( false , CompressionLevel . Max ) ]
27+ public void CompressAndDecompress_workCorrectly ( bool useDictionary , CompressionLevel level )
2228 {
2329 var data = GenerateSample ( ) ;
2430
@@ -33,8 +39,10 @@ public void CompressAndDecompress_workCorrectly([Values(false, true)] bool useDi
3339 CollectionAssert . AreEqual ( data , CompressAndDecompress ( data , dict , compressionLevel ) ) ;
3440 }
3541
36- [ Test ]
37- public void CompressAndDecompress_worksCorrectly_advanced ( [ Values ( false , true ) ] bool useDictionary )
42+ [ TestMethod ]
43+ [ DataRow ( true ) ]
44+ [ DataRow ( false ) ]
45+ public void CompressAndDecompress_worksCorrectly_advanced ( bool useDictionary )
3846 {
3947 var data = GenerateSample ( ) ;
4048 var dict = useDictionary ? BuildDictionary ( ) : null ;
@@ -59,7 +67,7 @@ public void CompressAndDecompress_worksCorrectly_advanced([Values(false, true)]
5967 }
6068 }
6169
62- [ Test ]
70+ [ TestMethod ]
6371 public void DecompressWithDictionary_worksCorrectly_onDataCompressedWithoutIt ( )
6472 {
6573 var data = GenerateSample ( ) ;
@@ -77,7 +85,7 @@ public void DecompressWithDictionary_worksCorrectly_onDataCompressedWithoutIt()
7785 CollectionAssert . AreEqual ( data , decompressed ) ;
7886 }
7987
80- [ Test ]
88+ [ TestMethod ]
8189 public void DecompressWithoutDictionary_throwsZstdException_onDataCompressedWithIt ( )
8290 {
8391 var data = GenerateSample ( ) ;
@@ -92,7 +100,7 @@ public void DecompressWithoutDictionary_throwsZstdException_onDataCompressedWith
92100 Assert . Throws < ZstdException > ( ( ) => decompressor . Unwrap ( compressed ) ) ;
93101 }
94102
95- [ Test ]
103+ [ TestMethod ]
96104 public void DecompressWithAnotherDictionary_throwsZstdException ( )
97105 {
98106 var data = GenerateSample ( ) ;
@@ -110,7 +118,7 @@ public void DecompressWithAnotherDictionary_throwsZstdException()
110118 Assert . Throws < ZstdException > ( ( ) => decompressor . Unwrap ( compressed ) ) ;
111119 }
112120
113- [ Test ]
121+ [ TestMethod ]
114122 public void Compress_reducesDataSize ( )
115123 {
116124 var data = GenerateSample ( ) ;
@@ -119,10 +127,10 @@ public void Compress_reducesDataSize()
119127 using ( var compressor = new Compressor ( ) )
120128 compressed = compressor . Wrap ( data ) ;
121129
122- Assert . Greater ( data . Length , compressed . Length ) ;
130+ Assert . IsGreaterThan ( compressed . Length , data . Length ) ;
123131 }
124132
125- [ Test ]
133+ [ TestMethod ]
126134 public void Compress_worksBetter_withDictionary ( )
127135 {
128136 var data = GenerateSample ( ) ;
@@ -135,11 +143,13 @@ public void Compress_worksBetter_withDictionary()
135143 using ( var compressor = new Compressor ( options ) )
136144 compressedWithDict = compressor . Wrap ( data ) ;
137145
138- Assert . Greater ( compressedWithoutDict . Length , compressedWithDict . Length ) ;
146+ Assert . IsGreaterThan ( compressedWithDict . Length , compressedWithoutDict . Length ) ;
139147 }
140148
141- [ Test ]
142- public void Decompress_throwsZstdException_onInvalidData ( [ Values ( false , true ) ] bool useDictionary )
149+ [ TestMethod ]
150+ [ DataRow ( true ) ]
151+ [ DataRow ( false ) ]
152+ public void Decompress_throwsZstdException_onInvalidData ( bool useDictionary )
143153 {
144154 var data = GenerateSample ( ) ; // This isn't data in compressed format
145155 var dict = useDictionary ? BuildDictionary ( ) : null ;
@@ -149,8 +159,10 @@ public void Decompress_throwsZstdException_onInvalidData([Values(false, true)] b
149159 Assert . Throws < ZstdException > ( ( ) => decompressor . Unwrap ( data ) ) ;
150160 }
151161
152- [ Test ]
153- public void Decompress_throwsZstdException_onMalformedDecompressedSize ( [ Values ( false , true ) ] bool useDictionary )
162+ [ TestMethod ]
163+ [ DataRow ( true ) ]
164+ [ DataRow ( false ) ]
165+ public void Decompress_throwsZstdException_onMalformedDecompressedSize ( bool useDictionary )
154166 {
155167 var data = GenerateSample ( ) ;
156168 var dict = useDictionary ? BuildDictionary ( ) : null ;
@@ -163,12 +175,12 @@ public void Decompress_throwsZstdException_onMalformedDecompressedSize([Values(f
163175 var frameHeader = compressed [ 4 ] ; // Ensure that we malform decompressed size in the right place
164176 if ( useDictionary )
165177 {
166- Assert . AreEqual ( frameHeader , 0x63 ) ;
178+ Assert . AreEqual ( 0x63 , frameHeader ) ;
167179 compressed [ 9 ] -- ;
168180 }
169181 else
170182 {
171- Assert . AreEqual ( frameHeader , 0x60 ) ;
183+ Assert . AreEqual ( 0x60 , frameHeader ) ;
172184 compressed [ 5 ] -- ;
173185 }
174186
@@ -178,8 +190,10 @@ public void Decompress_throwsZstdException_onMalformedDecompressedSize([Values(f
178190 Assert . Throws < ZstdException > ( ( ) => decompressor . Unwrap ( compressed ) ) ;
179191 }
180192
181- [ Test ]
182- public void Decompress_throwsArgumentOutOfRangeException_onTooBigData ( [ Values ( false , true ) ] bool useDictionary )
193+ [ TestMethod ]
194+ [ DataRow ( true ) ]
195+ [ DataRow ( false ) ]
196+ public void Decompress_throwsArgumentOutOfRangeException_onTooBigData ( bool useDictionary )
183197 {
184198 var data = GenerateSample ( ) ;
185199 var dict = useDictionary ? BuildDictionary ( ) : null ;
@@ -197,8 +211,10 @@ public void Decompress_throwsArgumentOutOfRangeException_onTooBigData([Values(fa
197211 }
198212 }
199213
200- [ Test ]
201- public void Compress_canRead_fromArraySegment ( [ Values ( false , true ) ] bool useDictionary )
214+ [ TestMethod ]
215+ [ DataRow ( true ) ]
216+ [ DataRow ( false ) ]
217+ public void Compress_canRead_fromArraySegment ( bool useDictionary )
202218 {
203219 var data = GenerateSample ( ) ;
204220 var segment = new ArraySegment < byte > ( data , 2 , data . Length - 5 ) ;
@@ -214,11 +230,13 @@ public void Compress_canRead_fromArraySegment([Values(false, true)] bool useDict
214230 using ( var decompressor = new Decompressor ( options ) )
215231 decompressed = decompressor . Unwrap ( compressed ) ;
216232
217- CollectionAssert . AreEqual ( segment , decompressed ) ;
233+ CollectionAssert . AreEqual ( segment . ToArray ( ) , decompressed ) ;
218234 }
219235
220- [ Test ]
221- public void CompressAndDecompress_workCorrectly_spans ( [ Values ( false , true ) ] bool useDictionary )
236+ [ TestMethod ]
237+ [ DataRow ( true ) ]
238+ [ DataRow ( false ) ]
239+ public void CompressAndDecompress_workCorrectly_spans ( bool useDictionary )
222240 {
223241 var buffer = GenerateSample ( ) ;
224242
@@ -245,8 +263,10 @@ public void CompressAndDecompress_workCorrectly_spans([Values(false, true)] bool
245263 CollectionAssert . AreEqual ( data . ToArray ( ) , decompressed . ToArray ( ) ) ;
246264 }
247265
248- [ Test ]
249- public void Decompress_canRead_fromArraySegment ( [ Values ( false , true ) ] bool useDictionary )
266+ [ TestMethod ]
267+ [ DataRow ( true ) ]
268+ [ DataRow ( false ) ]
269+ public void Decompress_canRead_fromArraySegment ( bool useDictionary )
250270 {
251271 var data = GenerateSample ( ) ;
252272 var dict = useDictionary ? BuildDictionary ( ) : null ;
@@ -267,8 +287,10 @@ public void Decompress_canRead_fromArraySegment([Values(false, true)] bool useDi
267287 CollectionAssert . AreEqual ( data , decompressed ) ;
268288 }
269289
270- [ Test ]
271- public void Compress_canWrite_toGivenBuffer ( [ Values ( false , true ) ] bool useDictionary )
290+ [ TestMethod ]
291+ [ DataRow ( true ) ]
292+ [ DataRow ( false ) ]
293+ public void Compress_canWrite_toGivenBuffer ( bool useDictionary )
272294 {
273295 var data = GenerateSample ( ) ;
274296 var dict = useDictionary ? BuildDictionary ( ) : null ;
@@ -288,8 +310,10 @@ public void Compress_canWrite_toGivenBuffer([Values(false, true)] bool useDictio
288310 CollectionAssert . AreEqual ( data , decompressed ) ;
289311 }
290312
291- [ Test ]
292- public void Decompress_canWrite_toGivenBuffer ( [ Values ( false , true ) ] bool useDictionary )
313+ [ TestMethod ]
314+ [ DataRow ( true ) ]
315+ [ DataRow ( false ) ]
316+ public void Decompress_canWrite_toGivenBuffer ( bool useDictionary )
293317 {
294318 var data = GenerateSample ( ) ;
295319 var dict = useDictionary ? BuildDictionary ( ) : null ;
@@ -307,11 +331,13 @@ public void Decompress_canWrite_toGivenBuffer([Values(false, true)] bool useDict
307331 using ( var decompressor = new Decompressor ( options ) )
308332 decompressedSize = decompressor . Unwrap ( compressed , decompressed , offset ) ;
309333
310- CollectionAssert . AreEqual ( data , decompressed . Skip ( offset ) . Take ( decompressedSize ) ) ;
334+ CollectionAssert . AreEqual ( data , decompressed . Skip ( offset ) . Take ( decompressedSize ) . ToArray ( ) ) ;
311335 }
312336
313- [ Test ]
314- public void Compress_throwsDstSizeTooSmall_whenDestinationBufferIsTooSmall ( [ Values ( false , true ) ] bool useDictionary )
337+ [ TestMethod ]
338+ [ DataRow ( true ) ]
339+ [ DataRow ( false ) ]
340+ public void Compress_throwsDstSizeTooSmall_whenDestinationBufferIsTooSmall ( bool useDictionary )
315341 {
316342 var data = GenerateSample ( ) ;
317343 var dict = useDictionary ? BuildDictionary ( ) : null ;
@@ -326,8 +352,10 @@ public void Compress_throwsDstSizeTooSmall_whenDestinationBufferIsTooSmall([Valu
326352 }
327353 }
328354
329- [ Test ]
330- public void Decompress_throwsDstSizeTooSmall_whenDestinationBufferIsTooSmall ( [ Values ( false , true ) ] bool useDictionary )
355+ [ TestMethod ]
356+ [ DataRow ( true ) ]
357+ [ DataRow ( false ) ]
358+ public void Decompress_throwsDstSizeTooSmall_whenDestinationBufferIsTooSmall ( bool useDictionary )
331359 {
332360 var data = GenerateSample ( ) ;
333361 var dict = useDictionary ? BuildDictionary ( ) : null ;
@@ -348,26 +376,32 @@ public void Decompress_throwsDstSizeTooSmall_whenDestinationBufferIsTooSmall([Va
348376 }
349377 }
350378
351- [ Test ]
352- public void CompressAndDecompress_workCorrectly_onEmptyBuffer ( [ Values ( false , true ) ] bool useDictionary )
379+ [ TestMethod ]
380+ [ DataRow ( true ) ]
381+ [ DataRow ( false ) ]
382+ public void CompressAndDecompress_workCorrectly_onEmptyBuffer ( bool useDictionary )
353383 {
354384 var data = new byte [ 0 ] ;
355385 var dict = useDictionary ? BuildDictionary ( ) : null ;
356386
357387 CollectionAssert . AreEqual ( data , CompressAndDecompress ( data , dict ) ) ;
358388 }
359389
360- [ Test ]
361- public void CompressAndDecompress_workCorrectly_onOneByteBuffer ( [ Values ( false , true ) ] bool useDictionary )
390+ [ TestMethod ]
391+ [ DataRow ( true ) ]
392+ [ DataRow ( false ) ]
393+ public void CompressAndDecompress_workCorrectly_onOneByteBuffer ( bool useDictionary )
362394 {
363395 var data = new byte [ ] { 42 } ;
364396 var dict = useDictionary ? BuildDictionary ( ) : null ;
365397
366398 CollectionAssert . AreEqual ( data , CompressAndDecompress ( data , dict ) ) ;
367399 }
368400
369- [ Test ]
370- public void CompressAndDecompress_workCorrectly_onArraysOfDifferentSizes ( [ Values ( false , true ) ] bool useDictionary )
401+ [ TestMethod ]
402+ [ DataRow ( true ) ]
403+ [ DataRow ( false ) ]
404+ public void CompressAndDecompress_workCorrectly_onArraysOfDifferentSizes ( bool useDictionary )
371405 {
372406 var dict = useDictionary ? BuildDictionary ( ) : null ;
373407 using ( var compressionOptions = new CompressionOptions ( dict ) )
@@ -386,8 +420,10 @@ public void CompressAndDecompress_workCorrectly_onArraysOfDifferentSizes([Values
386420 }
387421 }
388422
389- [ Test ]
390- public void CompressAndDecompress_workCorrectly_ifDifferentInstancesRunInDifferentThreads ( [ Values ( false , true ) ] bool useDictionary )
423+ [ TestMethod ]
424+ [ DataRow ( true ) ]
425+ [ DataRow ( false ) ]
426+ public void CompressAndDecompress_workCorrectly_ifDifferentInstancesRunInDifferentThreads ( bool useDictionary )
391427 {
392428 var dict = useDictionary ? BuildDictionary ( ) : null ;
393429 using ( var compressionOptions = new CompressionOptions ( dict ) )
@@ -411,8 +447,10 @@ public void CompressAndDecompress_workCorrectly_ifDifferentInstancesRunInDiffere
411447 } ) ;
412448 }
413449
414- [ Test , Explicit ( "stress" ) ]
415- public void CompressAndDecompress_workCorrectly_stress ( [ Values ( false , true ) ] bool useDictionary )
450+ [ TestMethod , CICondition ( ConditionMode . Exclude , IgnoreMessage = "stress" ) , TestCategory ( "Explicit" ) ]
451+ [ DataRow ( true ) ]
452+ [ DataRow ( false ) ]
453+ public void CompressAndDecompress_workCorrectly_stress ( bool useDictionary )
416454 {
417455 long i = 0L ;
418456 var data = GenerateBuffer ( 65536 ) ;
@@ -434,8 +472,10 @@ public void CompressAndDecompress_workCorrectly_stress([Values(false, true)] boo
434472 } ) ;
435473 }
436474
437- [ Test , Explicit ( "memory consuming" ) ]
438- public void CompressAndDecomress_workCorrectly_2GB ( [ Values ( false , true ) ] bool useDictionary )
475+ [ TestMethod , CICondition ( ConditionMode . Exclude , IgnoreMessage = "memory consuming" ) , TestCategory ( "Explicit" ) ]
476+ [ DataRow ( true ) ]
477+ [ DataRow ( false ) ]
478+ public void CompressAndDecomress_workCorrectly_2GB ( bool useDictionary )
439479 {
440480 var data = new byte [ MaxByteArrayLength ] ;
441481 Array . Fill < byte > ( data , 0xff , 100 , 10000000 ) ;
@@ -454,8 +494,10 @@ public void CompressAndDecomress_workCorrectly_2GB([Values(false, true)] bool us
454494 Assert . IsTrue ( data . SequenceEqual ( CompressAndDecompress ( data , dict ) ) ) ;
455495 }
456496
457- [ Test , Explicit ( "memory consuming" ) ]
458- public void CompressAndDecomress_throwsDstSizeTooSmall_Over2GB ( [ Values ( false , true ) ] bool useDictionary )
497+ [ TestMethod , CICondition ( ConditionMode . Exclude , IgnoreMessage = "memory consuming" ) , TestCategory ( "Explicit" ) ]
498+ [ DataRow ( true ) ]
499+ [ DataRow ( false ) ]
500+ public void CompressAndDecomress_throwsDstSizeTooSmall_Over2GB ( bool useDictionary )
459501 {
460502 var data = new byte [ MaxByteArrayLength ] ;
461503 new Random ( 1337 ) . NextBytes ( data ) ; //NOTE: Uncompressible data
@@ -470,7 +512,7 @@ public void CompressAndDecomress_throwsDstSizeTooSmall_Over2GB([Values(false, tr
470512 }
471513 }
472514
473- [ Test , Explicit ( "stress" ) ]
515+ [ TestMethod , CICondition ( ConditionMode . Exclude , IgnoreMessage = "stress" ) , TestCategory ( "Explicit ") ]
474516 public void TrainDictionaryParallel ( )
475517 {
476518 var buffer = Enumerable . Range ( 0 , 100000 ) . Select ( i => unchecked ( ( byte ) ( i * i ) ) ) . ToArray ( ) ;
@@ -479,8 +521,8 @@ public void TrainDictionaryParallel()
479521 . ToArray ( ) ;
480522
481523 var dict = DictBuilder . TrainFromBuffer ( samples ) ;
482- Assert . Greater ( dict . Length , 0 ) ;
483- Assert . LessOrEqual ( dict . Length , DictBuilder . DefaultDictCapacity ) ;
524+ Assert . IsGreaterThan ( 0 , dict . Length ) ;
525+ Assert . IsLessThanOrEqualTo ( DictBuilder . DefaultDictCapacity , dict . Length ) ;
484526
485527 Enumerable . Range ( 0 , 100000 )
486528 . AsParallel ( ) . WithDegreeOfParallelism ( Environment . ProcessorCount * 4 )
0 commit comments