-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathRandomAccessTest.cs
44 lines (43 loc) · 1.49 KB
/
RandomAccessTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Tynamix.ObjectFiller.Test
{
[TestClass]
public class RandomAccessTest
{
[TestMethod]
public void GetRandomIntOnDifferentThreadsGetsDifferentResults()
{
var numberToGenerate = 1000;
var intRange = new IntRange(1, 10);
var task1 = Task.Factory.StartNew(() =>
{
var taskResults = new List<int>();
for (int i = 0; i < numberToGenerate; ++i)
{
taskResults.Add(Randomizer<int>.Create(intRange));
}
return taskResults;
},
TaskCreationOptions.LongRunning
);
var task2 = Task.Factory.StartNew(() =>
{
var taskResults = new List<int>();
for (int i = 0; i < numberToGenerate; ++i)
{
taskResults.Add(Randomizer<int>.Create(intRange));
}
return taskResults;
},
TaskCreationOptions.LongRunning
);
var results = Task.WhenAll(task1, task2).Result;
var firstResults = results[0].Sum();
var secondResults = results[1].Sum();
Assert.AreNotEqual(firstResults, secondResults);
}
}
}