[bcl] Add NUnitHelper.cs with API not in nunit-lite
[mono.git] / mcs / class / corlib / Test / System.Collections.Concurrent / PartitionerTests.cs
1 // 
2 // PartitionerTests.cs
3 //  
4 // Author:
5 //       Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
6 // 
7 // Copyright (c) 2009 Jérémie "Garuma" Laval
8 // 
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 // 
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 // 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
26
27
28 using System;
29 using System.Collections.Generic;
30 using System.Collections.Concurrent;
31
32 using NUnit.Framework;
33
34 namespace MonoTests.System.Collections.Concurrent
35 {
36         [TestFixture]
37         public class PartitionerTests
38         {
39                 [Test]
40                 public void PartitionerCreateIntegerWithExplicitRange ()
41                 {
42                         OrderablePartitioner<Tuple<int, int>> partitioner = Partitioner.Create (1, 20, 5);
43                         var partitions = partitioner.GetOrderablePartitions (3);
44                         Assert.AreEqual (3, partitions.Count);
45                         Assert.That (partitions, Is.All.Not.Null);
46                         var iterator = partitions[0];                   
47                         Assert.IsTrue (iterator.MoveNext ());
48                         Assert.IsTrue (iterator.Current.Equals (Create (0, 1, 6)));
49                         Assert.IsTrue (iterator.MoveNext ());
50                         Assert.IsTrue (iterator.Current.Equals (Create (1, 6, 11)));
51                         Assert.IsTrue (iterator.MoveNext ());
52                         Assert.IsTrue (iterator.Current.Equals (Create (2, 11, 16)));
53                         Assert.IsTrue (iterator.MoveNext ());
54                         Assert.IsTrue (iterator.Current.Equals (Create (3, 16, 20)));
55                         
56                         Assert.IsFalse (partitions[1].MoveNext ());
57                         Assert.IsFalse (partitions[2].MoveNext ());
58                 }
59
60                 [Test]
61                 public void PartitionerCreateLongWithExplicitRange ()
62                 {
63                         OrderablePartitioner<Tuple<long, long>> partitioner = Partitioner.Create ((long)1, (long)20, (long)5);
64                         var partitions = partitioner.GetOrderablePartitions (3);
65                         Assert.AreEqual (3, partitions.Count);
66                         Assert.That (partitions, Is.All.Not.Null);
67                         var iterator = partitions[0];                   
68                         Assert.IsTrue (iterator.MoveNext ());
69                         Assert.IsTrue (iterator.Current.Equals (CreateL (0, 1, 6)));
70                         Assert.IsTrue (iterator.MoveNext ());
71                         Assert.IsTrue (iterator.Current.Equals (CreateL (1, 6, 11)));
72                         Assert.IsTrue (iterator.MoveNext ());
73                         Assert.IsTrue (iterator.Current.Equals (CreateL (2, 11, 16)));
74                         Assert.IsTrue (iterator.MoveNext ());
75                         Assert.IsTrue (iterator.Current.Equals (CreateL (3, 16, 20)));
76                         
77                         Assert.IsFalse (partitions[1].MoveNext ());
78                         Assert.IsFalse (partitions[2].MoveNext ());
79                 }
80
81                 static KeyValuePair<long, Tuple<int, int>> Create (long ind, int i1, int i2)
82                 {
83                         return new KeyValuePair<long, Tuple<int, int>> (ind, Tuple.Create (i1, i2));
84                 }
85
86                 static KeyValuePair<long, Tuple<long, long>> CreateL (long ind, long i1, long i2)
87                 {
88                         return new KeyValuePair<long, Tuple<long, long>> (ind, Tuple.Create (i1, i2));
89                 }
90         }
91 }