public bool NegTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest1: InvalidOperationException should be thrown when the collection was modified after the enumerator was created."); try { Queue <string> TestQueue = new Queue <string>(); TestQueue.Enqueue("one"); TestQueue.Enqueue("two"); TestQueue.Enqueue("three"); Queue <string> .Enumerator TestEnumerator; TestEnumerator = TestQueue.GetEnumerator(); TestQueue.Enqueue("four"); TestEnumerator.MoveNext(); TestLibrary.TestFramework.LogError("N01.1", "InvalidOperationException is not thrown when the collection was modified after the enumerator was created!"); retVal = false; } catch (InvalidOperationException) { } catch (Exception e) { TestLibrary.TestFramework.LogError("N01.2", "Unexpected exception: " + e); TestLibrary.TestFramework.LogVerbose(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: The enumerator should be positioned at the first element in the collection after MoveNext()."); try { Queue <string> TestQueue = new Queue <string>(); TestQueue.Enqueue("one"); TestQueue.Enqueue("two"); TestQueue.Enqueue("three"); Queue <string> .Enumerator TestEnumerator; TestEnumerator = TestQueue.GetEnumerator(); TestEnumerator.MoveNext(); string TestString = TestEnumerator.Current; if (TestString != "one") { TestLibrary.TestFramework.LogError("P01.1", "The enumerator is not positioned at the first element in the collection after MoveNext()!"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e); TestLibrary.TestFramework.LogVerbose(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Resource of the Enumerator should be released after Dispose()."); try { Queue <string> TestQueue = new Queue <string>(); TestQueue.Enqueue("one"); TestQueue.Enqueue("two"); TestQueue.Enqueue("three"); Queue <string> .Enumerator TestEnumerator; TestEnumerator = TestQueue.GetEnumerator(); TestEnumerator.MoveNext(); TestEnumerator.Dispose(); string TestString = TestEnumerator.Current; TestLibrary.TestFramework.LogError("P01.1", "Resource of the Enumerator have not been released after Dispose()!"); retVal = false; } catch (InvalidOperationException) { } catch (Exception e) { TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e); TestLibrary.TestFramework.LogVerbose(e.StackTrace); retVal = false; } return(retVal); }
}//TODO it must be implemented //private Opc.Da.ItemValueResult CreateDiagnosticInfo() //{ // return CreateItemValueResult( Convert.ToString( "CAS_DiagnosticInfo_" + m_RandomValue ) ); //} private Opc.Da.ItemValueResult CreateEnumeration() { Enum.Parse(typeof(TestEnumerator), TestEnumerator.testElement1.ToString()); TestEnumerator en = (TestEnumerator)(3 * m_RandomValue + 1); return(CreateItemValueResult(en)); }//TODO it must be implemented
public bool NegTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest2: InvalidOperationException should be thrown when the enumerator is positioned after the last element of the collection."); try { Queue <string> TestQueue = new Queue <string>(); TestQueue.Enqueue("one"); TestQueue.Enqueue("two"); TestQueue.Enqueue("three"); Queue <string> .Enumerator TestEnumerator; TestEnumerator = TestQueue.GetEnumerator(); TestEnumerator.MoveNext(); TestEnumerator.MoveNext(); TestEnumerator.MoveNext(); TestEnumerator.MoveNext(); string TestString = TestEnumerator.Current; TestLibrary.TestFramework.LogError("N02.1", "InvalidOperationException is not thrown when the enumerator is positioned after the last element of the collection!"); retVal = false; } catch (InvalidOperationException) { } catch (Exception e) { TestLibrary.TestFramework.LogError("N02.2", "Unexpected exception: " + e); TestLibrary.TestFramework.LogVerbose(e.StackTrace); retVal = false; } return(retVal); }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Test whether GetEnumerator() is successful when the queue is not empty."); try { Queue <string> TestQueue = new Queue <string>(); TestQueue.Enqueue("one"); TestQueue.Enqueue("two"); TestQueue.Enqueue("three"); Queue <string> .Enumerator TestEnumerator; TestEnumerator = TestQueue.GetEnumerator(); TestEnumerator.MoveNext(); for (int i = 0; i < TestQueue.Count; i++) { if (TestQueue.ToArray()[i] != TestEnumerator.Current) { TestLibrary.TestFramework.LogError("P01.1", "GetEnumerator() failed when the queue is not empty!"); retVal = false; } TestEnumerator.MoveNext(); } } catch (Exception e) { TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e); TestLibrary.TestFramework.LogVerbose(e.StackTrace); retVal = false; } return(retVal); }
public EditModeLauncher(Filter[] filters, TestPlatform platform, bool runSynchronously) { TestEnumerator.Reset(); m_EditModeRunner = ScriptableObject.CreateInstance <EditModeRunner>(); m_EditModeRunner.UnityTestAssemblyRunnerFactory = new UnityTestAssemblyRunnerFactory(); m_EditModeRunner.Init(filters, platform, runSynchronously); }
private TestEnumerator testEnumerator; // TestEnumerator型testEnumerator. // コンストラクタ public TestCollection(int len) { // 配列の生成. collection = new int[len]; // 要素数lenのint型配列collection. // イナミュレータの生成. testEnumerator = new TestEnumerator(collection, len); // testEnumeratorの生成. }
public void CloseDisposes() { var e = new TestEnumerator <object>(); Assert.IsFalse(e.Disposed); new Reader <object>(e).Close(); Assert.IsTrue(e.Disposed); }
public void DisposeDisposes() { var e = new TestEnumerator <object>(); Assert.IsFalse(e.Disposed); ((IDisposable) new Reader <object>(e)).Dispose(); Assert.IsTrue(e.Disposed); }
public void EnumeratorDisposal() { var e = new TestEnumerator(); var iter = TaskEnumerator <object> .FromEnumerator(e, 1); Scheduler.WaitFor(iter.Fetch()); iter.Dispose(); Assert.IsTrue(e.Disposed); }
public void TestToArrayOnEmptySequence() { var e = new TestEnumerator(); var iter = TaskEnumerator <object> .FromEnumerator(e, 1); object[] items = (object[])Scheduler.WaitFor(iter.GetArray()); object[] expected = new object[0]; Assert.AreEqual(expected, items); }
public void DisposeDisposesOnce() { var e = new TestEnumerator <object>(); Assert.IsFalse(e.Disposed); var disposable = ((IDisposable) new Reader <object>(e)); disposable.Dispose(); Assert.AreEqual(1, e.DisposeCallCount); disposable.Dispose(); Assert.AreEqual(1, e.DisposeCallCount); }
public void WillStopIfAllEnumeratorsCurrentIsNullAndReturningFalse() { var stream1 = new TestEnumerator { MoveNextReturnValue = false }; var synchronizer = new SynchronizingSliceEnumerator(stream1); while (synchronizer.MoveNext()) { Assert.Fail(); } Assert.IsTrue(stream1.MoveNextWasCalled); synchronizer.Dispose(); }
IEnumerator WaitForEntityViewsAdded() { //Engines are usually designed to be able to cope with dynamic adding and removing of entities, //but in this case I needed to know when the entities are ready to be processed. This wouldn't be //strictly necessary if I coded the engine in a different way, but I decided to keep it simpler and more readable. //That's why the engine starts immediately a task that waits for the EntityViews to be added(it assumes that all the //entities are created on the same frame).This demo aims to be allocation free during the main execution, that's //why all the tasks are prepared before hand. In this step, we prepare just one task that runs the main operations //that must be executed on the entities. int count = 0; #if FIRST_TIER_EXAMPLE || SECOND_TIER_EXAMPLE ReadOnlyCollectionStruct <BoidEntityView> _entityViews; #endif #if FOURTH_TIER_EXAMPLE || THIRD_TIER_EXAMPLE BoidEntityView[] _entityViews; #endif do { #if FIRST_TIER_EXAMPLE || SECOND_TIER_EXAMPLE _entityViews = entitiesDB.QueryEntityViews <BoidEntityView>(); count = _entityViews.Count; #endif #if FOURTH_TIER_EXAMPLE || THIRD_TIER_EXAMPLE _entityViews = entitiesDB.QueryEntities <BoidEntityView>(ExclusiveGroups.BoidGroup, out count); #endif yield return(null); } while (count == 0); #if TURBO_EXAMPLE int numberOfThreads = (int)Mathf.Min(NUM_OF_THREADS, count); var countn = count / numberOfThreads; _multiParallelTask = new MultiThreadedParallelTaskCollection((uint)numberOfThreads); for (int i = 0; i < numberOfThreads; i++) { _multiParallelTask.Add(new BoidEnumerator(_entityViews, countn * i, countn)); } #elif FIRST_TIER_EXAMPLE || SECOND_TIER_EXAMPLE || THIRD_TIER_EXAMPLE || FOURTH_TIER_EXAMPLE _boidEnumerator = new BoidEnumerator(_entityViews, 0, count); #endif _testEnumerator = new TestEnumerator(_printEntityView); Update().RunOnScheduler(StandardSchedulers.updateScheduler); }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Test whether GetEnumerator() is successful when the queue is empty."); try { Queue <string> TestQueue = new Queue <string>(); Queue <string> .Enumerator TestEnumerator; TestEnumerator = TestQueue.GetEnumerator(); try { string CurrentElement = TestEnumerator.Current; TestLibrary.TestFramework.LogError("P02.1", "GetEnumerator() failed when the queue is empty!"); retVal = false; } catch (InvalidOperationException) { } bool b = TestEnumerator.MoveNext(); if (b != false) { TestLibrary.TestFramework.LogError("P02.2", "GetEnumerator() failed when the queue is empty!"); retVal = false; } try { string CurrentElement = TestEnumerator.Current; TestLibrary.TestFramework.LogError("P02.3", "GetEnumerator() failed when the queue is empty!"); retVal = false; } catch (InvalidOperationException) { } } catch (Exception e) { TestLibrary.TestFramework.LogError("P02.4", "Unexpected exception: " + e); TestLibrary.TestFramework.LogVerbose(e.StackTrace); retVal = false; } return(retVal); }
static void Main(string[] args) { ITestEnumerator<TestClass> enumerator = new TestEnumerator<TestClass>(); enumerator.HasMoreItems(); enumerator.Next(); Console.WriteLine("-----------------------------------"); ITestIterator<TestClass> iterator = new TestIterator<TestClass>(); iterator.HasNext(); iterator.Next(); Console.WriteLine("-----------------------------------"); ITestEnumerator<TestClass> adapter = new IteratorEnumeratorAdapter<TestClass>(iterator); adapter.HasMoreItems(); adapter.Next(); }
public void WillRemoveEnumeratorsReturningFalse() { var time = new DateTime(2016, 03, 03, 12, 05, 00); var stream1 = new TestEnumerator { MoveNextReturnValue = false }; var stream2 = Enumerable.Range(0, 10).Select(x => new Slice(time.AddSeconds(x * 0.5), new List <BaseData>(), utcTime: time.AddSeconds(x * 0.5))).GetEnumerator(); var synchronizer = new SynchronizingSliceEnumerator(stream1, stream2); var emitted = false; while (synchronizer.MoveNext()) { emitted = true; } Assert.IsTrue(emitted); Assert.IsTrue(stream1.MoveNextWasCalled); Assert.AreEqual(1, stream1.MoveNextCallCount); synchronizer.Dispose(); }
public bool PosTest4() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest4: With a Queue that contains three items, MoveNext returns true the first three times and returns false every time it is called after that."); try { bool b; Queue <string> TestQueue = new Queue <string>(); TestQueue.Enqueue("one"); TestQueue.Enqueue("two"); TestQueue.Enqueue("three"); Queue <string> .Enumerator TestEnumerator; TestEnumerator = TestQueue.GetEnumerator(); for (int i = 0; i < 3; i++) { b = TestEnumerator.MoveNext(); if (!b) { TestLibrary.TestFramework.LogError("P04.1", "MoveNext() failed!"); retVal = false; } } b = TestEnumerator.MoveNext(); if (b) { TestLibrary.TestFramework.LogError("P04.1", "MoveNext() failed!"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("P04.2", "Unexpected exception: " + e); TestLibrary.TestFramework.LogVerbose(e.StackTrace); retVal = false; } return(retVal); }
public void Setup() { _vo = new ValueObject(); _serialTasks1 = new SerialTaskCollection <TestEnumerator>(); _parallelTasks1 = new ParallelTaskCollection <IEnumerator>(); _serialTasks2 = new SerialTaskCollection(); _parallelTasks2 = new ParallelTaskCollection(); _task1 = new Task(); _task2 = new Task(); _asyncTaskChain1 = new AsyncTask(); _asyncTaskChain2 = new AsyncTask(); _iterable1 = new TestEnumerator(10000); _iterable2 = new TestEnumerator(10000); _iterableWithException = new TestEnumerator(-5); _taskRunner = TaskRunner.Instance; //the taskroutine will stall the thread because it runs on the SyncScheduler _reusableTaskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine(new SyncRunner()); }
public void DropsEnumeratorsReturningNullAndTrue(bool skipsBasedOnEndTime) { var enumerator1 = new TestEnumerator(); var enumerator2 = new TestEnumerator(); var concat = new ConcatEnumerator(skipsBasedOnEndTime, enumerator1, null, enumerator2); Assert.IsTrue(concat.MoveNext()); Assert.IsNull(concat.Current); Assert.IsTrue(enumerator1.Disposed); Assert.IsFalse(enumerator2.Disposed); Assert.AreEqual(1, enumerator2.MoveNextCount); Assert.IsTrue(concat.MoveNext()); // we assert it just keeps the last enumerator and drops the rest Assert.IsTrue(enumerator1.Disposed); Assert.IsFalse(enumerator2.Disposed); Assert.IsNull(concat.Current); Assert.AreEqual(2, enumerator2.MoveNextCount); concat.Dispose(); }
public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: The enumerator should be positioned after the last element in the collection after MoveNext() passed the end of collection."); try { Queue <string> TestQueue = new Queue <string>(); TestQueue.Enqueue("one"); TestQueue.Enqueue("two"); TestQueue.Enqueue("three"); Queue <string> .Enumerator TestEnumerator; TestEnumerator = TestQueue.GetEnumerator(); bool bSuc; bSuc = TestEnumerator.MoveNext(); bSuc = TestEnumerator.MoveNext(); bSuc = TestEnumerator.MoveNext(); bSuc = TestEnumerator.MoveNext(); bSuc = TestEnumerator.MoveNext(); bSuc = TestEnumerator.MoveNext(); if (bSuc) { TestLibrary.TestFramework.LogError("P03.1", "The enumerator is not positioned after the last element in the collection after MoveNext() passed the end of collection!"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("P03.2", "Unexpected exception: " + e); TestLibrary.TestFramework.LogVerbose(e.StackTrace); retVal = false; } return(retVal); }
public void TestToArrayOnEmptySequence () { var e = new TestEnumerator(); var iter = TaskEnumerator<object>.FromEnumerator(e, 1); object[] items = (object[])Scheduler.WaitFor(iter.GetArray()); object[] expected = new object[0]; Assert.AreEqual(expected, items); }
public void EnumeratorDisposal () { var e = new TestEnumerator(); var iter = TaskEnumerator<object>.FromEnumerator(e, 1); Scheduler.WaitFor(iter.Fetch()); iter.Dispose(); Assert.IsTrue(e.Disposed); }
public TestList() { _Enumerator = new TestEnumerator <T>(); }