Esempio n. 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameters"></param>
        public OculusRiftDisplay( Game game, GraphicsDevice device, GameParameters parameters )
            : base(game, device, parameters)
        {
            window = CreateForm(parameters, null);

            oculus = new Wrap();

            // Initialize the Oculus runtime.
            oculus.Initialize();

            // Use the head mounted display, if it's available, otherwise use the debug HMD.
            int numberOfHeadMountedDisplays = oculus.Hmd_Detect();
            if (numberOfHeadMountedDisplays > 0)
                hmd = oculus.Hmd_Create(0);
            else
                hmd = oculus.Hmd_CreateDebug(OculusWrap.OVR.HmdType.DK2);

            if (hmd == null) {
                MessageBox.Show("Oculus Rift not detected.", "Uh oh", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (hmd.ProductName == string.Empty)
                MessageBox.Show("The HMD is not enabled.", "There's a tear in the Rift", MessageBoxButtons.OK, MessageBoxIcon.Error);

            OVR.Recti destMirrorRect;
            OVR.Recti sourceRenderTargetRect;
            hmd.AttachToWindow(window.Handle, out destMirrorRect, out sourceRenderTargetRect);

            // Create a backbuffer that's the same size as the HMD's resolution.
            OVR.Sizei backBufferSize;
            backBufferSize.Width	= hmd.Resolution.Width;
            backBufferSize.Height	= hmd.Resolution.Height;

            var deviceFlags = DeviceCreationFlags.None;
            deviceFlags |= parameters.UseDebugDevice ? DeviceCreationFlags.Debug : DeviceCreationFlags.None;

            var driverType = DriverType.Hardware;

            var featureLevel = HardwareProfileChecker.GetFeatureLevel(parameters.GraphicsProfile);

            swapChainDesc = new SwapChainDescription {
                BufferCount			= 1,
                ModeDescription		= new ModeDescription(backBufferSize.Width, backBufferSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed			= true,
                OutputHandle		= window.Handle,
                SampleDescription	= new SampleDescription(parameters.MsaaLevel, 0),
                SwapEffect			= SwapEffect.Discard,
                Usage				= Usage.RenderTargetOutput| Usage.ShaderInput,
                Flags				= SwapChainFlags.None,
            };

            D3D.Device.CreateWithSwapChain(driverType, deviceFlags, new[] { featureLevel }, swapChainDesc, out d3dDevice, out swapChain);

            var factory = swapChain.GetParent<Factory>();
            factory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);

            clientWidth		= window.ClientSize.Width;
            clientHeight	= window.ClientSize.Height;
        }
Esempio n. 2
0
        public LazyFrameAnimation(IList<Surface> surfaces, Wrap<float> interval)
        {
            Contract.Requires(surfaces != null);

            _surfaces = surfaces;
            _interval = interval;
        }
Esempio n. 3
0
        public LazyFrameAnimation(
            IEnumerable<Surface> surfaces, Wrap<float> interval)
        {
            Contract.Requires(surfaces != null);

            _surfaces =
                    new LazyWrap<IList<Surface>>(() => surfaces.ToList()).
                            ToListWrap();
            _interval = interval;
        }
Esempio n. 4
0
    void OnDnaStringRequested(Wrap<string> dna)
    {
        if (dna.IsSet)
        {
            return;
        }

        dna.Value = Dna;
        dna.ValueSource = "DnaProcessor";
    }
Esempio n. 5
0
    void OnDnaGenRequested(Wrap<int> generation)
    {
        if (generation.IsSet)
        {
            return;
        }

        generation.Value = _generation;
        generation.ValueSource = "DnaProcessor";
    }
Esempio n. 6
0
	public static int Main ()
	{
		var a = new Wrap () {
			Numbers =  { 3, 9 }
		};
		
		if (a.Numbers [1] != 9)
			return 1;
		
		Console.WriteLine ("OK");
		return 0;
	}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="game"></param>
		/// <param name="device"></param>
		/// <param name="parameters"></param>
		public OculusRiftDisplay( Game game, GraphicsDevice device, GraphicsParameters parameters ) : base( game, device, parameters )
		{
			oculus = new Wrap();

			// Initialize the Oculus runtime.
			oculus.Initialize();

			OVR.GraphicsLuid graphicsLuid;
			hmd = oculus.Hmd_Create(out graphicsLuid);

			if (hmd == null) {
				MessageBox.Show("Oculus Rift not detected.", "Uh oh", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}

			if (hmd.ProductName == string.Empty)
				MessageBox.Show("The HMD is not enabled.", "There's a tear in the Rift", MessageBoxButtons.OK, MessageBoxIcon.Error);


			parameters.Width	= hmd.Resolution.Width;
			parameters.Height	= hmd.Resolution.Height;

			window = CreateForm(parameters, null);

			var deviceFlags = DeviceCreationFlags.None;
			deviceFlags |= parameters.UseDebugDevice ? DeviceCreationFlags.Debug : DeviceCreationFlags.None;

			var driverType = DriverType.Hardware;

			var featureLevel = HardwareProfileChecker.GetFeatureLevel(parameters.GraphicsProfile);


			var swapChainDesc = new SwapChainDescription {
				BufferCount			= 1,
				ModeDescription		= new ModeDescription(hmd.Resolution.Width, hmd.Resolution.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
				IsWindowed			= true,
				OutputHandle		= window.Handle,
				SampleDescription	= new SampleDescription(parameters.MsaaLevel, 0),
				SwapEffect			= SwapEffect.Discard,
				Usage				= Usage.RenderTargetOutput| Usage.ShaderInput,
				Flags				= SwapChainFlags.None,
			};


			D3D.Device.CreateWithSwapChain(driverType, deviceFlags, new[] { featureLevel }, swapChainDesc, out d3dDevice, out swapChain);


			var myFactory = swapChain.GetParent<Factory>();
			myFactory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);
		}
Esempio n. 8
0
        public void FixedSizeSmaller ()
        {
            var wrap = new Wrap {
                ItemWidth = 3,
                ItemHeight = 2,
                Children = {
                    CreateRectDiv(3, 1),
                    CreateRectDiv(2, 2),
                    CreateRectDiv(1, 1),
                    CreateRectDiv(2, 1),
                }
            };

            GetRenderedText(wrap, 6).Should().BeLines(
                "abcde ",
                "   fg ",
                "h  ij ",
                "      ");
        }
Esempio n. 9
0
        public void FixedSizeExact ()
        {
            var wrap = new Wrap {
                ItemWidth = 3,
                ItemHeight = 2,
                Children = {
                    CreateRectDiv(3, 2),
                    CreateRectDiv(3, 2),
                    CreateRectDiv(3, 2),
                    CreateRectDiv(3, 2),
                }
            };

            GetRenderedText(wrap, 6).Should().BeLines(
                "abcghi",
                "defjkl",
                "mnostu",
                "pqrvwx");
        }
Esempio n. 10
0
        /// <summary>
        /// Downloads the data.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="httpMethod">The HTTP method.</param>
        /// <param name="requestData">The request data.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="userState">State of the user.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static AsyncResult DownloadDataAsync(Uri url, HttpMethod httpMethod, byte[] requestData,
                                                    AsyncDataCallback callback, object userState)
        {
            var web = new WebClient();

            web.UploadDataCompleted   += WebUploadDataCompleted;
            web.DownloadDataCompleted += WebDownloadDataCompleted;
            var wrap = new Wrap(callback, userState);

            web.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; BOIE9;ZHCN)");
            if (httpMethod == HttpMethod.POST)
            {
                web.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                web.UploadDataAsync(url, "POST", requestData, wrap);
            }
            else
            {
                web.DownloadDataAsync(url, wrap);
            }

            return(new AsyncResult(web));
        }
Esempio n. 11
0
        public void Single_Predicate_With_Single_Must_Return_Some(int[] source, int skipCount, int takeCount, Predicate <int> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skipCount)
                           .Take(takeCount)
                           .Single(predicate.AsFunc());

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skipCount)
                         .Take(takeCount)
                         .Where(predicate)
                         .Single();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
        public void SkipTake_ForEachIndex_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount)
        {
            // Arrange
            var wrapped  = Wrap.AsValueReadOnlyList(source);
            var expected = 0;

            System.Linq.EnumerableEx.ForEach(
                System.Linq.Enumerable.Take(
                    System.Linq.Enumerable.Skip(wrapped, skipCount), takeCount), (item, index) => expected += item + index);

            // Act
            var result = 0;

            ReadOnlyList
            .Skip <Wrap.ValueReadOnlyList <int>, int>(wrapped, skipCount)
            .Take(takeCount)
            .ForEach((item, index) => result += item + index);

            // Assert
            _ = result.Must()
                .BeEqualTo(expected);
        }
        public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func <int, int, string> selector)
        {
            // Arrange
            var pool     = ArrayPool <string> .Shared;
            var wrapped  = Wrap.AsReadOnlyList(source);
            var expected = source
                           .Skip(skip)
                           .Take(take)
                           .Select(selector)
                           .ToArray();

            // Act
            using var result = wrapped.AsValueEnumerable()
                               .Skip(skip)
                               .Take(take)
                               .Select(selector)
                               .ToArray(pool);

            // Assert
            _ = result.Memory
                .SequenceEqual(expected);
        }
Esempio n. 14
0
        public async void ElementAtAsync_Predicate_With_OutOfRange_Must_Return_None(int[] source, Predicate <int> predicate)
        {
            // Arrange
            var wrapped = Wrap.AsAsyncValueEnumerable(source);

            // Act
            var optionNegative = await AsyncValueEnumerable
                                 .Where <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int>(wrapped, predicate.AsAsync())
                                 .ElementAtAsync(-1);

            var optionTooLarge = await AsyncValueEnumerable
                                 .Where <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int>(wrapped, predicate.AsAsync())
                                 .ElementAtAsync(source.Length);

            // Assert
            _ = optionNegative.Must()
                .BeOfType <Option <int> >()
                .EvaluateTrue(option => option.IsNone);
            _ = optionTooLarge.Must()
                .BeOfType <Option <int> >()
                .EvaluateTrue(option => option.IsNone);
        }
        public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source, int skip, int take)
        {
            // Arrange
            var pool     = MemoryPool <int> .Shared;
            var wrapped  = Wrap.AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skip)
                           .Take(take)
                           .Distinct()
                           .ToArray();

            // Act
            using var result = ReadOnlyListExtensions
                               .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skip)
                               .Take(take)
                               .Distinct()
                               .ToArray(pool);

            // Assert
            _ = result
                .SequenceEqual(expected);
        }
Esempio n. 16
0
        public void Count_PredicateAt_With_ValidData_Must_Succeed(int[] source, int skip, int take, Func <int, int, bool> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skip)
                           .Take(take)
                           .Where(predicate)
                           .Count();

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skip)
                         .Take(take)
                         .Where(predicate)
                         .Count();

            // Assert
            _ = result.Must()
                .BeEqualTo(expected);
        }
        public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, int skip, int take, Predicate <int> predicate)
        {
            // Arrange
            var pool     = MemoryPool <int> .Shared;
            var wrapped  = Wrap.AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skip)
                           .Take(take)
                           .Where(predicate.AsFunc())
                           .ToArray();

            // Act
            using var result = ReadOnlyListExtensions
                               .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skip)
                               .Take(take)
                               .Where(predicate)
                               .ToArray(pool);

            // Assert
            _ = result.Memory
                .SequenceEqual(expected);
        }
        public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, int skip, int take, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var pool     = MemoryPool <string> .Shared;
            var wrapped  = Wrap.AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skip)
                           .Take(take)
                           .Select(selector.AsFunc())
                           .ToArray();

            // Act
            using var result = ReadOnlyListExtensions
                               .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skip)
                               .Take(take)
                               .Select(selector)
                               .ToArray(pool);

            // Assert
            _ = result.Memory
                .SequenceEqual(expected);
        }
        public async ValueTask FirstAsync_Predicate_Selector_With_ValidData_Must_Return_Some(int[] source, Func <int, bool> predicate, Func <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsAsyncValueEnumerable(source);
            var expected = source
                           .Where(predicate)
                           .Select(selector)
                           .First();

            // Act
            var result = await wrapped.AsAsyncValueEnumerable()
                         .Where(predicate.AsAsync())
                         .Select(selector.AsAsync())
                         .FirstAsync()
                         .ConfigureAwait(false);

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
        public void WhereSelect_With_ValidData_Must_Succeed(int[] source, int skip, int take, Predicate <int> predicate, NullableSelector <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skip)
                           .Take(take)
                           .Where(predicate.AsFunc())
                           .Select(selector.AsFunc());

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skip)
                         .Take(take)
                         .Where(predicate)
                         .Select(selector);

            // Assert
            _ = result.Must()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
        public async ValueTask ForEachAsync_ActionAt_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsAsyncValueEnumerable(source);
            var result   = new List <(string, int)>();
            var expected = new List <(string, int)>();

            System.Linq.EnumerableEx.ForEach(
                System.Linq.Enumerable.Select(
                    System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()), (item, index) => expected.Add((item, index)));

            // Act
            await AsyncValueEnumerable
            .Where <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int>(wrapped, predicate.AsAsync())
            .Select(selector.AsAsync())
            .ForEachAsync((item, index, cancellationToken) => { result.Add((item, index)); return(new ValueTask()); });

            // Assert
            _ = result.Must()
                .BeEnumerableOf <(string, int)>()
                .BeEqualTo(expected);
        }
Esempio n. 22
0
        public async ValueTask ToListAsync_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate, NullableSelector <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsAsyncValueEnumerable(source);
            var expected = Enumerable
                           .Where(source, predicate.AsFunc())
                           .Select(selector.AsFunc())
                           .ToList();

            // Act
            var result = await AsyncValueEnumerableExtensions
                         .Where <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int>(wrapped, predicate.AsAsync())
                         .Select(selector.AsAsync())
                         .ToListAsync();

            // Assert
            _ = result.Must()
                .BeOfType <List <string> >()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
Esempio n. 23
0
        public async void ElementAtAsync_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, SelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap.AsAsyncValueEnumerable(source);

            // Act
            var optionNegative = await AsyncValueEnumerable
                                 .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync())
                                 .ElementAtAsync(-1);

            var optionTooLarge = await AsyncValueEnumerable
                                 .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync())
                                 .ElementAtAsync(source.Length);

            // Assert
            _ = optionNegative.Must()
                .BeOfType <Option <string> >()
                .EvaluateTrue(option => option.IsNone);
            _ = optionTooLarge.Must()
                .BeOfType <Option <string> >()
                .EvaluateTrue(option => option.IsNone);
        }
Esempio n. 24
0
        public async ValueTask ElementAtAsync_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func <int, int, bool> predicate)
        {
            // Arrange
            var wrapped  = Wrap.AsAsyncValueEnumerable(source);
            var expected = source
                           .Where(predicate)
                           .ToList();

            for (var index = 0; index < expected.Count; index++)
            {
                // Act
                var result = await wrapped.AsAsyncValueEnumerable()
                             .Where(predicate.AsAsync())
                             .ElementAtAsync(index)
                             .ConfigureAwait(false);

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected[index]),
                    () => throw new Exception());
            }
        }
Esempio n. 25
0
        public void Distinct_ToList_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount)
        {
            // Arrange
            var wrapped  = Wrap.AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skipCount)
                           .Take(takeCount)
                           .Distinct()
                           .ToList();

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skipCount)
                         .Take(takeCount)
                         .Distinct()
                         .ToList();

            // Assert
            _ = result.Must()
                .BeEnumerableOf <int>()
                .BeEqualTo(expected);
        }
        public void ToList_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Func <int, bool> predicate, Func <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Where(source, predicate)
                           .Select(selector)
                           .ToList();

            // Act
            var result = ValueEnumerableExtensions
                         .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                         .Select(selector)
                         .ToList();

            // Assert
            _ = result.Must()
                .BeOfType <List <string> >()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
Esempio n. 27
0
        public void First_Predicate_With_ValidData_Must_Return_Some(int[] source, int skip, int take, Func <int, bool> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsReadOnlyList <int>(source);
            var expected = Enumerable
                           .Skip(source, skip)
                           .Take(take)
                           .First(predicate);

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skip)
                         .Take(take)
                         .Where(predicate)
                         .First();

            // Assert
            _ = result.Match(
                value => value.Must().BeEqualTo(expected),
                () => throw new Exception());
        }
Esempio n. 28
0
        public void ForEach_ActionAt_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsValueEnumerable(source);
            var result   = new List <(string, int)>();
            var expected = new List <(string, int)>();

            System.Linq.EnumerableEx.ForEach(
                System.Linq.Enumerable.Select(
                    System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()), (item, index) => expected.Add((item, index)));

            // Act
            ValueEnumerable
            .Where <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
            .Select(selector)
            .ForEach((item, index) => result.Add((item, index)));

            // Assert
            _ = result.Must()
                .BeEnumerableOf <(string, int)>()
                .BeEqualTo(expected);
        }
Esempio n. 29
0
        internal virtual void MergeAttributes(TagBuilder tag, RenderContext context, MergeAttrMode mode = MergeAttrMode.All)
        {
            if (mode.HasFlag(MergeAttrMode.Visibility))
            {
                MergeVisibilityAttribures(tag, context);
            }

            if (mode.HasFlag(MergeAttrMode.Tip))
            {
                MergeBindingAttributeString(tag, context, "title", "Tip", Tip);
            }

            if (mode.HasFlag(MergeAttrMode.Wrap))
            {
                if (Wrap != WrapMode.Default)
                {
                    tag.AddCssClass(Wrap.ToString().ToKebabCase());
                }
            }

            if (mode.HasFlag(MergeAttrMode.Margin))
            {
                if (Margin != null)
                {
                    Margin.MergeStyles("margin", tag);
                }
                if (Padding != null)
                {
                    Padding.MergeStyles("padding", tag);
                }
            }

            if (Absolute != null)
            {
                Absolute.MergeAbsolute(tag);
            }

            tag.MergeAttribute("id", HtmlId);
        }
        public void FirstOrDefault_Skip_Take_PredicateAt_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount, PredicateAt <int> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueReadOnlyList(source);
            var expected =
                System.Linq.Enumerable.FirstOrDefault(
                    System.Linq.Enumerable.Where(
                        System.Linq.Enumerable.Take(
                            System.Linq.Enumerable.Skip(source, skipCount), takeCount), predicate.AsFunc()));

            // Act
            var result = ReadOnlyList
                         .Skip <Wrap.ValueReadOnlyList <int>, int>(wrapped, skipCount)
                         .Take(takeCount)
                         .Where(predicate)
                         .FirstOrDefault();

            // Assert
            _ = result.Must()
                .BeEqualTo(expected);
        }
Esempio n. 31
0
        public async ValueTask ElementAtAsync_SelectorAt_With_ValidData_Must_Return_Some(int[] source, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsAsyncValueEnumerable(source);
            var expected = Enumerable
                           .Select(source, selector.AsFunc())
                           .ToList();

            for (var index = 0; index < source.Length; index++)
            {
                // Act
                var result = await AsyncValueEnumerableExtensions
                             .Select <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync())
                             .ElementAtAsync(index);

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected[index]),
                    () => throw new Exception());
            }
        }
Esempio n. 32
0
        public async ValueTask ElementAtAsync_Predicate_With_ValidData_Must_Return_Some(int[] source, Predicate <int> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsAsyncValueEnumerable(source);
            var expected = Enumerable
                           .Where(source, predicate.AsFunc())
                           .ToList();

            for (var index = 0; index < expected.Count; index++)
            {
                // Act
                var result = await AsyncValueEnumerableExtensions
                             .Where <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int>(wrapped, predicate.AsAsync())
                             .ElementAtAsync(index);

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected[index]),
                    () => throw new Exception());
            }
        }
Esempio n. 33
0
        public async ValueTask ElementAtAsync_With_ValidData_Must_Return_Some(int[] source)
        {
            var wrapped = Wrap
                          .AsAsyncValueEnumerable(source);

            for (var index = 0; index < source.Length; index++)
            {
                // Arrange
                var expected = source
                               .ElementAt(index);

                // Act
                var result = await wrapped.AsAsyncValueEnumerable()
                             .ElementAtAsync(index)
                             .ConfigureAwait(false);

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected),
                    () => throw new Exception());
            }
        }
        public void ToArray_Skip_Take_SelectorAt_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount, NullableSelectorAt <int, string> selector)
        {
            // Arrange
            var wrapped  = Wrap.AsValueReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skipCount)
                           .Take(takeCount)
                           .Select(selector.AsFunc())
                           .ToArray();

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ValueReadOnlyListWrapper <int>, int>(wrapped, skipCount)
                         .Take(takeCount)
                         .Select(selector)
                         .ToArray();

            // Assert
            _ = result.Must()
                .BeArrayOf <string>()
                .BeEqualTo(expected);
        }
        public void Where_Predicate_With_ValidData_Must_Succeed(int[] source, int skipCount, int takeCount, Predicate <int> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsReadOnlyList(source);
            var expected = Enumerable
                           .Skip(source, skipCount)
                           .Take(takeCount)
                           .Where(predicate.AsFunc());

            // Act
            var result = ReadOnlyListExtensions
                         .Skip <Wrap.ReadOnlyListWrapper <int>, int>(wrapped, skipCount)
                         .Take(takeCount)
                         .Where(predicate);


            // Assert
            _ = result.Must()
                .BeEnumerableOf <int>()
                .BeEqualTo(expected);
        }
Esempio n. 36
0
        public void ElementAt_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, Func <int, int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);

            // Act
            var optionNegative = ValueEnumerableExtensions
                                 .Select <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector)
                                 .ElementAt(-1);
            var optionTooLarge = ValueEnumerableExtensions
                                 .Select <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int, string>(wrapped, selector)
                                 .ElementAt(source.Length);

            // Assert
            _ = optionNegative.Must()
                .BeOfType <Option <string> >()
                .EvaluateTrue(option => option.IsNone);
            _ = optionTooLarge.Must()
                .BeOfType <Option <string> >()
                .EvaluateTrue(option => option.IsNone);
        }
Esempio n. 37
0
        public void ElementAt_Predicate_With_OutOfRange_Must_Return_None(int[] source, Func <int, bool> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);

            // Act
            var optionNegative = ValueEnumerableExtensions
                                 .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                                 .ElementAt(-1);
            var optionTooLarge = ValueEnumerableExtensions
                                 .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                                 .ElementAt(source.Length);

            // Assert
            _ = optionNegative.Must()
                .BeOfType <Option <int> >()
                .EvaluateTrue(option => option.IsNone);
            _ = optionTooLarge.Must()
                .BeOfType <Option <int> >()
                .EvaluateTrue(option => option.IsNone);
        }
Esempio n. 38
0
        public void ElementAt_PredicateAt_With_ValidData_Must_Return_Some(int[] source, Func <int, int, bool> predicate)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected = Enumerable
                           .Where(source, predicate)
                           .ToList();

            for (var index = 0; index < expected.Count; index++)
            {
                // Act
                var result = ValueEnumerableExtensions
                             .Where <Wrap.ValueEnumerableWrapper <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                             .ElementAt(index);

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected[index]),
                    () => throw new Exception());
            }
        }
Esempio n. 39
0
        public void ToList_Predicate_Selector_With_ValidData_Must_Succeed(int[] source, Predicate <int> predicate, Selector <int, string> selector)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueEnumerable(source);
            var expected =
                System.Linq.Enumerable.ToList(
                    System.Linq.Enumerable.Select(
                        System.Linq.Enumerable.Where(source, predicate.AsFunc()), selector.AsFunc()));

            // Act
            var result = ValueEnumerable
                         .Where <Wrap.ValueEnumerable <int>, Wrap.Enumerator <int>, int>(wrapped, predicate)
                         .Select(selector)
                         .ToList();

            // Assert
            _ = result.Must()
                .BeOfType <List <string> >()
                .BeEnumerableOf <string>()
                .BeEqualTo(expected);
        }
Esempio n. 40
0
    void Start()
    {
        _age = 0.0f;

        var dna = new Wrap<string>();

        if (gameObject.transform.parent != null) {
            var gen = new Wrap<int>();

            gameObject.transform.parent.SendMessage("OnDnaGenRequested", gen);
            _generation = gen.IsSet ? gen.Value + 1 : 0;

            gameObject.transform.parent.SendMessage("OnDnaStringRequested", dna);
        }
        else {
            SendMessage("OnSeedDnaStringRequested", dna);
        }

        if (dna.IsSet)
        {
            DnaString = dna.Value;
        }
    }
Esempio n. 41
0
        /// <summary>
        /// Write out any error details received from the Oculus SDK, into the debug output window.
        /// 
        /// Please note that writing text to the debug output window is a slow operation and will affect performance,
        /// if too many messages are written in a short timespan.
        /// </summary>
        /// <param name="oculus">OculusWrap object for which the error occurred.</param>
        /// <param name="result">Error code to write in the debug text.</param>
        /// <param name="message">Error message to include in the debug text.</param>
        public static void WriteErrorDetails(Wrap oculus, OVRTypes.Result result, string message)
        {
            if (result >= OVRTypes.Result.Success)
                return;

            // Retrieve the error message from the last occurring error.
            OVRTypes.ErrorInfo errorInformation = oculus.GetLastError();

            string formattedMessage = string.Format("{0}. \nMessage: {1} (Error code={2})", message, errorInformation.ErrorString, errorInformation.Result);
            Trace.WriteLine(formattedMessage);
            MessageBox.Show(formattedMessage, message);

            throw new Exception(formattedMessage);
        }
Esempio n. 42
0
 private void FindRemovableTypesInAssertStmt(AssertStmt assert, Statement parent, Method method)
 {
     if (!(parent is BlockStmt)) return;
     var block = (BlockStmt) parent;
     var assertWrap = new Wrap<Statement>(assert, block.Body);
     _allRemovableTypes.AddAssert(assertWrap, method);
 }
Esempio n. 43
0
        public void AutoSizeMixedVertical ()
        {
            var wrap = new Wrap {
                Orientation = Orientation.Vertical,
                Height = 3,
                Children = {
                    CreateRectDiv(3, 1),
                    CreateRectDiv(2, 2),
                    CreateRectDiv(2, 1),
                    CreateRectDiv(1, 1),
                }
            };

            GetRenderedText(wrap, 6).Should().BeLines(
                "abchi ",
                "de j  ",
                "fg    ");
        }
Esempio n. 44
0
        public void AutoSizeFixedVertical ()
        {
            var wrap = new Wrap {
                Orientation = Orientation.Vertical,
                Height = 4,
                Children = {
                    CreateRectDiv(3, 2),
                    CreateRectDiv(3, 2),
                    CreateRectDiv(3, 2),
                    CreateRectDiv(3, 2),
                }
            };

            GetRenderedText(wrap, 6).Should().BeLines(
                "abcmno",
                "defpqr",
                "ghistu",
                "jklvwx");
        }
Esempio n. 45
0
    void OnApplicantTypeRequested(Wrap<string> type)
    {
        if (type.IsSet || string.IsNullOrEmpty(ApplicantType)) return;

        type.Value = ApplicantType.ToLower();
        type.ValueSource = "BonesApplicant";
    }
Esempio n. 46
0
 private void Start()
 {
     var genWrap = new Wrap<Int32>();
     gameObject.SendMessage("OnDnaGenRequested", genWrap, SendMessageOptions.DontRequireReceiver);
     Generation = genWrap.IsSet ? genWrap.Value : 0;
 }
Esempio n. 47
0
        public void AutoSizeFixed ()
        {
            var wrap = new Wrap {
                Children = {
                    CreateRectDiv(3, 2),
                    CreateRectDiv(3, 2),
                    CreateRectDiv(3, 2),
                    CreateRectDiv(3, 2),
                }
            };

            GetRenderedText(wrap, 6).Should().BeLines(
                "abcghi",
                "defjkl",
                "mnostu",
                "pqrvwx");
        }
Esempio n. 48
0
        public void AutoSizeTooLarge ()
        {
            var wrap = new Wrap {
                Children = {
                    CreateRectDiv(5, 1),
                    CreateRectDiv(6, 1),
                }
            };

            GetRenderedText(wrap, 4).Should().BeLines(
                "abcd",
                "fghi");
        }
Esempio n. 49
0
        public void AutoSizeMixed ()
        {
            var wrap = new Wrap {
                Children = {
                    CreateRectDiv(3, 1),
                    CreateRectDiv(2, 2),
                    CreateRectDiv(2, 1),
                    CreateRectDiv(1, 1),
                }
            };

            GetRenderedText(wrap, 6).Should().BeLines(
                "abcde ",
                "   fg ",
                "hij   ");
        }
Esempio n. 50
0
        public void EmptyChild ()
        {
            var wrap = new Wrap { Children = { new Div() } };

            new Action(() => RenderOn1x1(wrap)).ShouldNotThrow();
        }
Esempio n. 51
0
        public void NegativeItemHeight ()
        {
            var wrap = new Wrap();

            new Action(() => wrap.ItemHeight = -1).ShouldThrow<ArgumentOutOfRangeException>();
        }
 public A([TestContract("a")] Wrap s1, Wrap s2)
 {
     this.s1 = s1;
     this.s2 = s2;
 }
Esempio n. 53
0
        public void NoChildren ()
        {
            var wrap = new Wrap();

            new Action(() => RenderOn1x1(wrap)).ShouldNotThrow();
        }
Esempio n. 54
0
 public static void BitmapSize(Filter filter, Wrap wrapx, Wrap wrapy, ushort width, ushort height)
 {
     uint fxy = ((uint)filter << 2) | ((uint)wrapx << 1) | ((uint)wrapy);
     uint cmd = (0x08 << 24) | (uint)height | ((uint)width << 9) | (fxy << 18);
     GDTransport.cmd32(cmd);
 }
Esempio n. 55
0
        public LazyFrameAnimation(
            IEnumerable<Surface> surfaces, float time, bool isTotalTime)
        {
            Contract.Requires(surfaces != null);

            _surfaces =
                    new LazyWrap<IList<Surface>>(() => surfaces.ToList()).
                            ToListWrap();
            _interval = isTotalTime
                ? new LazyWrap<float>(
                    () => time / _surfaces.Count)
                : time;
        }
		public Wrap (int i)
		{
			Next = this;
		}
Esempio n. 57
0
        public void FixedSizeLarger ()
        {
            var wrap = new Wrap {
                ItemWidth = 2,
                ItemHeight = 1,
                Children = {
                    CreateRectDiv(3, 1),
                    CreateRectDiv(2, 2),
                    CreateRectDiv(1, 1),
                    CreateRectDiv(2, 1),
                }
            };

            GetRenderedText(wrap, 5).Should().BeLines(
                "abde ",
                "h ij ");
        }
Esempio n. 58
0
        private void FindRemovableTypesInCalcStmt(CalcStmt calc, Statement parent, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl)
        {
            Wrap<Statement> calcWrap = null;
            if (parent is BlockStmt)
                calcWrap = new Wrap<Statement>(calc, ((BlockStmt)parent).Body);
            else if (parent is MatchStmt) {
                var matchStmt = (MatchStmt) parent;
                foreach (var matchCase in matchStmt.Cases) {
                    if (!matchCase.Body.Contains(calc)) continue;
                    calcWrap = new Wrap<Statement>(calc, matchCase.Body);
                    break;
                }
                if (calcWrap == null) throw  new Exception("Calc not found!");
            }
            else {
                throw new Exception("Calc not found!");
            }

            _allRemovableTypes.AddCalc(calcWrap, method);
            foreach (var hint in calc.Hints) {
                FindRemovableTypesInStatement(hint, calc, method, wildCardParent, classDecl); // This will check the inside of the hint - it will ID anything that can be shortened inside it.
            }

        }
 public A([TestContract("x")] Wrap wrap, [TestContract("x")] C c1, C c2)
 {
     this.wrap = wrap;
     this.c1 = c1;
     this.c2 = c2;
 }
		public Wrap ()
		{
			Next = new Wrap (100);
		}