5 // Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
7 // Copyright (c) 2009 Jérémie "Garuma" Laval
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:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
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
30 using System.Collections.Generic;
31 using System.Collections.Concurrent;
33 using NUnit.Framework;
35 using NUnit.Framework.SyntaxHelpers;
38 namespace MonoTests.System.Collections.Concurrent
41 public class PartitionerTests
44 public void PartitionerCreateIntegerWithExplicitRange ()
46 OrderablePartitioner<Tuple<int, int>> partitioner = Partitioner.Create (1, 20, 5);
47 var partitions = partitioner.GetOrderablePartitions (3);
48 Assert.AreEqual (3, partitions.Count);
49 Assert.That (partitions, Is.All.Not.Null);
50 var iterator = partitions[0];
51 Assert.IsTrue (iterator.MoveNext ());
52 Assert.IsTrue (iterator.Current.Equals (Create (0, 1, 6)));
53 Assert.IsTrue (iterator.MoveNext ());
54 Assert.IsTrue (iterator.Current.Equals (Create (1, 6, 11)));
55 Assert.IsTrue (iterator.MoveNext ());
56 Assert.IsTrue (iterator.Current.Equals (Create (2, 11, 16)));
57 Assert.IsTrue (iterator.MoveNext ());
58 Assert.IsTrue (iterator.Current.Equals (Create (3, 16, 20)));
60 Assert.IsFalse (partitions[1].MoveNext ());
61 Assert.IsFalse (partitions[2].MoveNext ());
65 public void PartitionerCreateLongWithExplicitRange ()
67 OrderablePartitioner<Tuple<long, long>> partitioner = Partitioner.Create ((long)1, (long)20, (long)5);
68 var partitions = partitioner.GetOrderablePartitions (3);
69 Assert.AreEqual (3, partitions.Count);
70 Assert.That (partitions, Is.All.Not.Null);
71 var iterator = partitions[0];
72 Assert.IsTrue (iterator.MoveNext ());
73 Assert.IsTrue (iterator.Current.Equals (CreateL (0, 1, 6)));
74 Assert.IsTrue (iterator.MoveNext ());
75 Assert.IsTrue (iterator.Current.Equals (CreateL (1, 6, 11)));
76 Assert.IsTrue (iterator.MoveNext ());
77 Assert.IsTrue (iterator.Current.Equals (CreateL (2, 11, 16)));
78 Assert.IsTrue (iterator.MoveNext ());
79 Assert.IsTrue (iterator.Current.Equals (CreateL (3, 16, 20)));
81 Assert.IsFalse (partitions[1].MoveNext ());
82 Assert.IsFalse (partitions[2].MoveNext ());
85 static KeyValuePair<long, Tuple<int, int>> Create (long ind, int i1, int i2)
87 return new KeyValuePair<long, Tuple<int, int>> (ind, Tuple.Create (i1, i2));
90 static KeyValuePair<long, Tuple<long, long>> CreateL (long ind, long i1, long i2)
92 return new KeyValuePair<long, Tuple<long, long>> (ind, Tuple.Create (i1, i2));