public void RandomExtended_Choose() { using (var verify = new Verify()) { var rand = new RandomExtended(0); var source = new List<int>(); for (int i = 100; i < 200; i++) source.Add(i); for (int i = 0; i < 100; i++) { var item = rand.Choose(source); verify.IsBetween(100, item, 199, "Item couldn't be in the sourse list"); verify.IsTrue(source.Contains(item), "Item should have been left in the list"); } } }
public void RandomExtended_Choose3() { using (var verify = new Verify()) { var rand = new RandomExtended(0); var source = new List<int>(); for (int i = 100; i < 200; i++) source.Add(i); for (int i = 0; i < 100; i += 10) { var items = rand.Choose(source, 10, false); foreach (var item in items) { verify.IsBetween(100, item, 199, "Item couldn't be in the source list"); verify.IsTrue(source.Contains(item), "Item should have been left in the list"); } var distinct = items.Distinct().Count(); verify.AreEqual(items.Count, distinct, "There shouldn't have been any duplicates"); } } }
public void RandomExtended_Choose3() { using (var verify = new Verify()) { var rand = new RandomExtended(0); var source = new List <int>(); for (int i = 100; i < 200; i++) { source.Add(i); } for (int i = 0; i < 100; i += 10) { var items = rand.Choose(source, 10, false); foreach (var item in items) { verify.IsBetween(100, item, 199, "Item couldn't be in the source list"); verify.IsTrue(source.Contains(item), "Item should have been left in the list"); } var distinct = items.Distinct().Count(); verify.AreEqual(items.Count, distinct, "There shouldn't have been any duplicates"); } } }
public void TaskUtilitiesTests_AutoCancelingTaskTest2() { using (var verify = new Verify()) { var timer = Stopwatch.StartNew(); var t = TaskUtilities.AutoCancelingTask(1000); Memory.CycleGC(); var result = t.WaitForCompleteOrCancel(); timer.Stop(); verify.IsFalse(result, "WaitForCompleteOrCancel should have returned false"); verify.IsTrue(t.IsCanceled, "Task should have been canceled."); verify.AreEqual(1.0, timer.Elapsed.TotalSeconds, 0.05, "Elapsed time was incorrect."); } }
public void TaskUtilitiesTests_WaitForCancelTest1() { using (var verify = new Verify()) { var task = Sleeper(verify); task.RunConcurrently(); var result = task.WaitForCompleteOrCancel(); verify.AreEqual(TaskStatus.RanToCompletion, task.Status, "The task should have been completed"); verify.IsTrue(result, "Assertion should be true because the task was completed"); } }