// // Author: Carson Jones // Adapted from "Art of Multiprocessor Programming" by Herlihy and Shavit // CS6966 // using System; using System.Text; using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using PriorityQueueHeap; namespace ChessTestFineGrainedHeap { /// /// Summary description for UnitTest1 /// [TestClass] public class UnitTest1 { public UnitTest1() { // // TODO: Add constructor logic here // } private TestContext testContextInstance; /// ///Gets or sets the test context which provides ///information about and functionality for the current test run. /// public TestContext TestContext { get { return testContextInstance; } set { testContextInstance = value; } } #region Additional test attributes // // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion [TestMethod] //[HostType("Chess")] //[TestProperty("ChessDebug", "true")] public void TestMethod1() { FineGrainedHeap heap = new FineGrainedHeap(5); List addList = new List(); for (int i = 0; i < 5; i++) { heap.Add(i, i); addList.Add(i); } List removeList = new List(); int removeItem; for (int i = 0; i < 5; i++) { removeItem = heap.RemoveMin(); Assert.IsTrue(removeItem == i); Assert.IsTrue(addList.Contains(removeItem)); Assert.IsTrue(!removeList.Contains(removeItem)); removeList.Add(removeItem); } } [TestMethod] //[HostType("Chess")] //[TestProperty("ChessDebug", "true")] public void TestMethod2() { ParallelTasks tasks = new ParallelTasks(); FineGrainedHeap heap = new FineGrainedHeap(6); List addList = new List(); tasks.Add("Producer", () => { for (int i = 0; i < 6; i++) { heap.Add(i, i); addList.Add(i); } }); tasks.Execute(); tasks.Clear(); List removeList = new List(); tasks.Add("Consumer", () => { int removeItem; for (int i = 0; i < 3; i++) { removeItem = heap.RemoveMin(); Assert.IsTrue(addList.Contains(removeItem)); Assert.IsTrue(!removeList.Contains(removeItem)); removeList.Add(removeItem); } }); tasks.Add("Consumer", () => { int removeItem; for (int i = 0; i < 3; i++) { removeItem = heap.RemoveMin(); Assert.IsTrue(addList.Contains(removeItem)); Assert.IsTrue(!removeList.Contains(removeItem)); removeList.Add(removeItem); } }); //Assert.IsTrue(addList.Count == removeList.Count); tasks.Execute(); Assert.IsTrue(true); } } }