Added unit test to cover issue #8
This commit is contained in:
		
							parent
							
								
									9024752b53
								
							
						
					
					
						commit
						faf6c99c19
					
				@ -1,6 +1,7 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Diagnostics.CodeAnalysis;
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using System.Threading;
 | 
					using System.Threading;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using FastRng;
 | 
					using FastRng;
 | 
				
			||||||
using FastRng.Distributions;
 | 
					using FastRng.Distributions;
 | 
				
			||||||
using NUnit.Framework;
 | 
					using NUnit.Framework;
 | 
				
			||||||
@ -223,6 +224,32 @@ public class MultiThreadedRngTests
 | 
				
			|||||||
        Assert.That(lorentzContains1, Is.True, "Lorentz distribution does not contained 1");
 | 
					        Assert.That(lorentzContains1, Is.True, "Lorentz distribution does not contained 1");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    [Test]
 | 
				
			||||||
 | 
					    [Category(TestCategories.LONG_RUNNING)]
 | 
				
			||||||
 | 
					    public void TestMultiThreadedConsumer()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        var job1 = Task.Factory.StartNew(Run, TaskCreationOptions.LongRunning);
 | 
				
			||||||
 | 
					        var job2 = Task.Factory.StartNew(Run, TaskCreationOptions.LongRunning);
 | 
				
			||||||
 | 
					        var job3 = Task.Factory.StartNew(Run, TaskCreationOptions.LongRunning);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Assert.DoesNotThrowAsync(async () => await job1);
 | 
				
			||||||
 | 
					        Assert.DoesNotThrowAsync(async () => await job2);
 | 
				
			||||||
 | 
					        Assert.DoesNotThrowAsync(async () => await job3);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        float Run()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var sum = 0f;
 | 
				
			||||||
 | 
					            var distLorentz = new CauchyLorentzX1<float>(this.rng);
 | 
				
			||||||
 | 
					            for (int i = 0; i < 100_000_000; i++)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                sum += distLorentz.NextNumber();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return sum;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Test]
 | 
					    [Test]
 | 
				
			||||||
    [Category(TestCategories.COVER)]
 | 
					    [Category(TestCategories.COVER)]
 | 
				
			||||||
    [Category(TestCategories.NORMAL)]
 | 
					    [Category(TestCategories.NORMAL)]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user