/// <summary> ///Clear 的测试 ///</summary> public void ClearTestHelper <ValueT>() { SafeStack <ValueT> target = new SafeStack <ValueT>(); // TODO: 初始化为适当的值 target.Clear(); Assert.Inconclusive("无法验证不返回值的方法。"); }
// //编写测试时,还可使用以下属性: // //使用 ClassInitialize 在运行类中的第一个测试前先运行代码 //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //使用 ClassCleanup 在运行完类中的所有测试后再运行代码 //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //使用 TestInitialize 在运行每个测试前先运行代码 //[TestInitialize()] //public void MyTestInitialize() //{ //} // //使用 TestCleanup 在运行完每个测试后运行代码 //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// <summary> ///Count 的测试 ///</summary> public void CountTestHelper <ValueT>() { SafeStack <ValueT> target = new SafeStack <ValueT>(); // TODO: 初始化为适当的值 int actual; actual = target.Count; Assert.Inconclusive("验证此测试方法的正确性。"); }
/// <summary> ///Push 的测试 ///</summary> public void PushTestHelper <ValueT>() { SafeStack <ValueT> target = new SafeStack <ValueT>(); // TODO: 初始化为适当的值 ValueT value = default(ValueT); // TODO: 初始化为适当的值 target.Push(value); Assert.Inconclusive("无法验证不返回值的方法。"); }
/// <summary> ///Peek 的测试 ///</summary> public void PeekTestHelper <ValueT>() { SafeStack <ValueT> target = new SafeStack <ValueT>(); // TODO: 初始化为适当的值 ValueT expected = default(ValueT); // TODO: 初始化为适当的值 ValueT actual; actual = target.Peek(); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
/// <summary> ///ToArray 的测试 ///</summary> public void ToArrayTestHelper <ValueT>() { SafeStack <ValueT> target = new SafeStack <ValueT>(); // TODO: 初始化为适当的值 ValueT[] expected = null; // TODO: 初始化为适当的值 ValueT[] actual; actual = target.ToArray(); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
/// <summary> ///CopyTo 的测试 ///</summary> public void CopyToTestHelper <ValueT>() { SafeStack <ValueT> target = new SafeStack <ValueT>(); // TODO: 初始化为适当的值 ValueT[] arrayT = null; // TODO: 初始化为适当的值 int iArrayIndex = 0; // TODO: 初始化为适当的值 target.CopyTo(arrayT, iArrayIndex); Assert.Inconclusive("无法验证不返回值的方法。"); }
/// <summary> ///GetEnumerator 的测试 ///</summary> public void GetEnumeratorTestHelper <ValueT>() { SafeStack <ValueT> target = new SafeStack <ValueT>(); // TODO: 初始化为适当的值 IEnumerator <ValueT> expected = null; // TODO: 初始化为适当的值 IEnumerator <ValueT> actual; actual = target.GetEnumerator(); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
/// <summary> /// Constructor. /// </summary> /// <param name="log">IEventLog</param> /// <param name="threadIndex">Thread index</param> /// <param name="callMonitor">IThreadMonitor</param> /// <param name="raceDetectionEngine">IRaceDetectionEngine</param> /// <param name="configuration">Configuration</param> public ThreadExecutionMonitorDispatcher(IEventLog log, int threadIndex, IThreadMonitor callMonitor, IRegisterRuntimeOperation raceDetectionEngine, Configuration configuration) : base(threadIndex) { SafeDebug.AssertNotNull(callMonitor, "callMonitor"); this.ThreadIndex = threadIndex; this.Configuration = configuration; this.DebugTrace = new SafeList <string>(); this.CallStack = new SafeStack <Method>(); this.Reporter = raceDetectionEngine; }
/// <summary> ///Contains 的测试 ///</summary> public void ContainsTestHelper <ValueT>() { SafeStack <ValueT> target = new SafeStack <ValueT>(); // TODO: 初始化为适当的值 ValueT value = default(ValueT); // TODO: 初始化为适当的值 bool expected = false; // TODO: 初始化为适当的值 bool actual; actual = target.Contains(value); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
public NetworkConnection(TCPPacketConnection tcpConnection, ResponseRequest responseRequest, PackageAdapter adapter) { Adapter = adapter; TcpPackages = new SafeStack <PackageInterface>(); m_openResponses = new SafeList <ResponseRequest>(); if (responseRequest != null) { m_openResponses.Add(responseRequest); } ClientSession = null; TcpConnection = tcpConnection; RemoteEndPoint = tcpConnection.Remote; OnDisconnect = TcpConnection.OnDisconnect.CreateRelay(this); TcpConnection.DataReceivedEvent += ReceiveTCP; TcpConnection.OnDisconnect.Event += HandleDisconnect; TcpConnection.InitializeReceiving(); }
private string GetFullPathThroughStack(TreeNode n) { /* * Same as the previous method, but it uses Stack to perform "reverse-iterate". */ Stack <string> pathS = new Stack <string>(); TreeNode node = n; pathS.Push(n.Text); while ((node = node.Parent) != null) { if (node.Text == "/") { continue; } pathS.Push(node.Text); } StringBuilder pathBuilder = new StringBuilder(); pathBuilder.Append("/"); string currPathS; while ((currPathS = SafeStack <string> .SafePop(pathS)) != SafeStack <string> .NULL) { pathBuilder.Append(currPathS); pathBuilder.Append("/"); } if (pathBuilder.ToString() != "/") { pathBuilder.Remove(pathBuilder.Length - 1, 1); } return(pathBuilder.ToString()); }
public async NativeTasks.Task Run() { // runtime.RegisterMonitor(typeof(StateMonitor)); // Runtime = runtime; int numTasks = 5; var stack = new SafeStack(numTasks); Task[] tasks = new Task[numTasks]; for (int i = 0; i < numTasks; i++) { tasks[i] = Task.Run(async() => { int id = i; //Runtime.Logger.WriteLine($"Starting task {id}."); for (int j = 0; j != 2; j += 1) { int elem = await stack.PopAsync(id); if (elem <= 0) { nekara.ContextSwitch(); continue; } stack.Array[elem].Value = id; // Runtime.Logger.WriteLine($"Task {id} popped item '{elem}' and writes value '{id}'."); // Runtime.InvokeMonitor<StateMonitor>(new StateMonitor.UpdateStateEvent(stack.Array)); nekara.ContextSwitch(); nekara.Assert(stack.Array[elem].Value == id, $"Task {id} found bug: [{elem}].{stack.Array[elem].Value} is not '{id}'!"); await stack.PushAsync(id, elem); } }); } await Task.WhenAll(tasks); }
/// <summary> /// Constructor. /// </summary> /// <param name="log">IEventLog</param> /// <param name="threadIndex">Thread index</param> /// <param name="callMonitor">IThreadMonitor</param> /// <param name="testingEngine">ITestingEngine</param> /// <param name="configuration">Configuration</param> public ThreadExecutionMonitorDispatcher(IEventLog log, int threadIndex, IThreadMonitor callMonitor, ITestingEngine testingEngine, Configuration configuration) : base(threadIndex) { SafeDebug.AssertNotNull(callMonitor, "callMonitor"); this.ThreadIndex = threadIndex; this.Configuration = configuration; this.ThreadTrace = new List <ThreadTrace>(); this.DebugTrace = new SafeList <string>(); this.CallStack = new SafeStack <Method>(); this.IsDoHandlerCalled = false; this.IsEntryActionCalled = false; this.IsExitActionCalled = false; this.IsAction = false; this.RecordRW = false; this.IsCreateMachineMethod = false; // Registers a callback to emit the thread trace. The callback // is invoked at the end of each testing iteration. testingEngine.RegisterPerIterationCallBack(EmitThreadTrace); }
public TaskManager() { Stack = new SafeStack <Task>(); Tasks = (IProducerConsumerCollection <Task>)Stack; }
/* Function: GetJavadocLinkSymbol * Returns the symbol part of a @see or {@link} tag and moves the iterator past it. */ protected string GetJavadocLinkSymbol(ref TokenIterator iterator) { StringBuilder symbol = new StringBuilder(); // In Javadoc, spaces are only allowed in parentheses. We're going to go further and allow them in any braces to support // templates and other languages. However, for angle brackets they must be preceded by a comma. This allows // "Template<A, B>" to be supported while not getting tripped on "operator<". // Most symbols won't have braces so create this on demand. SafeStack <char> braceStack = null; while (iterator.IsInBounds) { if (iterator.Character == '(' || iterator.Character == '[' || iterator.Character == '{' || iterator.Character == '<') { if (braceStack == null) { braceStack = new SafeStack <char>(); } braceStack.Push(iterator.Character); symbol.Append(iterator.Character); } else if ((iterator.Character == ')' && braceStack != null && braceStack.Peek() == '(') || (iterator.Character == ']' && braceStack != null && braceStack.Peek() == '[') || (iterator.Character == '}' && braceStack != null && braceStack.Peek() == '{') || (iterator.Character == '>' && braceStack != null && braceStack.Peek() == '<')) { braceStack.Pop(); symbol.Append(iterator.Character); } else if (iterator.Character == '}' && (braceStack == null || braceStack.Contains('{') == false)) { // If we're at an unopened closing brace we're probably at the end of a {@link}. We check if the stack contains an // opening brace instead of checking whether it's empty to ignore any possible opening angle brackets that could // screw us up like "operator<". break; } else if (iterator.FundamentalType == FundamentalType.Text || iterator.FundamentalType == FundamentalType.Symbol) { iterator.AppendTokenTo(symbol); } else if (iterator.FundamentalType == FundamentalType.Whitespace) { if (braceStack == null || braceStack.Count == 0) { break; } else if (braceStack.Peek() == '<') { TokenIterator lookbehind = iterator; lookbehind.Previous(); if (lookbehind.Character == ',') { iterator.AppendTokenTo(symbol); } else { break; } } else { iterator.AppendTokenTo(symbol); } } else // line break { break; } iterator.Next(); } // Javadoc uses Class.Class#Member. First remove leading hashes to handle just #Member while (symbol.Length > 0 && symbol[0] == '#') { symbol.Remove(0, 1); } // Convert any remaining hashes to dots. Ideally we would use the language's native member operator but it's not // easy to get it here. return(symbol.ToString().Replace('#', '.')); }
/// <summary> ///SafeStack`1 构造函数 的测试 ///</summary> public void SafeStackConstructorTestHelper <ValueT>() { SafeStack <ValueT> target = new SafeStack <ValueT>(); Assert.Inconclusive("TODO: 实现用来验证目标的代码"); }
public ConcurrentStack(IEnumerable <T> collection) { _wrapped = new SafeStack <T>(collection); }
/// <summary> /// Constructor. /// </summary> /// <param name="log">IEventLog</param> /// <param name="threadIndex">Thread index</param> /// <param name="callMonitor">IThreadMonitor</param> /// <param name="testingEngine">ITestingEngine</param> /// <param name="configuration">Configuration</param> public ThreadExecutionMonitorDispatcher(IEventLog log, int threadIndex, IThreadMonitor callMonitor, ITestingEngine testingEngine, Configuration configuration) : base(threadIndex) { SafeDebug.AssertNotNull(callMonitor, "callMonitor"); this.ThreadIndex = threadIndex; this.Configuration = configuration; this.ThreadTrace = new List<ThreadTrace>(); this.DebugTrace = new SafeList<string>(); this.CallStack = new SafeStack<Method>(); this.IsDoHandlerCalled = false; this.IsEntryActionCalled = false; this.IsExitActionCalled = false; this.IsAction = false; this.RecordRW = false; this.IsCreateMachineMethod = false; // Registers a callback to emit the thread trace. The callback // is invoked at the end of each testing iteration. testingEngine.RegisterPerIterationCallBack(EmitThreadTrace); }
// Test our implementation of IProducerConsumerCollection(T) // Demonstrates: // IPCC(T).TryAdd() // IPCC(T).TryTake() // IPCC(T).CopyTo() static void TestSafeStack() { SafeStack <int> stack = new SafeStack <int>(); IProducerConsumerCollection <int> ipcc = (IProducerConsumerCollection <int>)stack; // Test Push()/TryAdd() stack.Push(10); Console.WriteLine("Pushed 10"); ipcc.TryAdd(20); Console.WriteLine("IPCC.TryAdded 20"); stack.Push(15); Console.WriteLine("Pushed 15"); int[] testArray = new int[3]; // Try CopyTo() within boundaries try { ipcc.CopyTo(testArray, 0); Console.WriteLine("CopyTo() within boundaries worked, as expected"); } catch (Exception e) { Console.WriteLine("CopyTo() within boundaries unexpectedly threw an exception: {0}", e.Message); } // Try CopyTo() that overflows try { ipcc.CopyTo(testArray, 1); Console.WriteLine("CopyTo() with index overflow worked, and it SHOULD NOT HAVE"); } catch (Exception e) { Console.WriteLine("CopyTo() with index overflow threw an exception, as expected: {0}", e.Message); } // Test enumeration Console.Write("Enumeration (should be three items): "); foreach (int item in stack) { Console.Write("{0} ", item); } Console.WriteLine(""); // Test TryPop() int popped = 0; if (stack.TryPop(out popped)) { Console.WriteLine("Successfully popped {0}", popped); } else { Console.WriteLine("FAILED to pop!!"); } // Test Count Console.WriteLine("stack count is {0}, should be 2", stack.Count); // Test TryTake() if (ipcc.TryTake(out popped)) { Console.WriteLine("Successfully IPCC-TryTaked {0}", popped); } else { Console.WriteLine("FAILED to IPCC.TryTake!!"); } }
public ConcurrentStack() { _wrapped = new SafeStack <T>(); }