public void ThreadedTest() { const int MAX = 1000000; const int THREADS = 10; var serv = new ExTest(); System.Threading.ThreadStart t_d = delegate() { for (int i = 0; i < 2 * MAX; i++) { if (i % 2 == 0) { serv.Add(-1); } else { serv.Add(1); } } }; var threads = new System.Collections.Generic.List <System.Threading.Thread>(); for (int i = 0; i < THREADS; i++) { threads.Add(new System.Threading.Thread(t_d)); } foreach (var t in threads) { t.Start(); } foreach (var t in threads) { t.Join(); } Assert.AreEqual(0, serv.total, "Threaded exclusive test"); }
public void BasicTest() { var serv = new ExTest(); var total = 0; for (int i = 0; i < 100; i++) { serv.Add(i); total += i; } Assert.AreEqual(serv.total, total, "single threaded correct"); }