mercredi 16 décembre 2015

Nunit framework

What value is added to a programming project by the following code: using NUnit.Framework; [TestFixture()] class

 When_Generating_Unique_Twelve_Digit_Numbers { [Test] public void Should_Generate_10000000_Unique_Numbers() { 
var randomValues = new ConcurrentBag<string>();
    Parallel.For(0, 500, i => { int seed = unchecked(DateTime.Now.Ticks.GetHashCode() + Environment.MachineName.GetHashCode()); Console.WriteLine(seed); Random r = new Random(seed);
    var randomValue = r.Next(0, 999999999).ToString().PadLeft(10,'0');
    var secondRandomValue = r.Next(0, 9);
    var randomStr = string.Format("{0}{1}", randomValue, secondRandomValue); if (randomValues.Contains(randomStr)) { Assert.Fail("Failed at {0} for value {1}", i, randomStr); } });
    } 
}

Aucun commentaire:

Enregistrer un commentaire