示例#1
0
        private void Amb([PexAssumeNotNull] IEnumerable <int> firstSource, [PexAssumeNotNull] IEnumerable <int> secondSource, int firstDelay, int secondDelay)
        {
            PexAssume.InRange(firstDelay, 0, 10);
            PexAssume.InRange(secondDelay, 0, 10);
            PexAssume.IsTrue(firstDelay != secondDelay);

            var first      = AmbHelper(firstSource, firstDelay);
            var second     = AmbHelper(secondSource, secondDelay);
            var enumerable = first.Amb(second);
            var enumerator = enumerable.GetEnumerator();

            var selectedSource = firstDelay < secondDelay ? firstSource : secondSource;

            var sourceEnumerator = selectedSource.GetEnumerator();
            var firstSourceMove  = sourceEnumerator.MoveNext();
            var firstAmbMove     = enumerator.MoveNext();

            PexAssert.AreEqual(firstSourceMove, firstAmbMove);
            if (firstAmbMove)
            {
                var firstThread = enumerator.Current.Second;
                PexAssert.AreEqual(sourceEnumerator.Current, enumerator.Current.First);
                while (sourceEnumerator.MoveNext())
                {
                    PexAssert.IsTrue(enumerator.MoveNext());
                    PexAssert.AreEqual(sourceEnumerator.Current, enumerator.Current.First);
                    PexAssert.AreEqual(firstThread, enumerator.Current.Second);
                }
                PexAssert.IsFalse(enumerator.MoveNext());
            }
        }