public void Should_Return_All_Array_Items()
        {
            var input = new[] {"a", "b", "c"};
            IEnumerable<string> result = 100.Times(x => input.Random());

            Assert.That(result.Distinct(), Is.EquivalentTo(input));
        }
        public void Should_Return_All_Array_Items()
        {
            var input = new[] {"a", "b", "c"};
            var result = 100.Times(x => input.Random());

            Assert.AreEqual(3, result.Distinct().Count());
        }
    public void random()
    {
      Assert.Throws<ArgumentNullException>(() => QueryableExtensions.Random<object>(null));

      Assert.Null(Enumerable.Empty<object>().AsQueryable().Random());

      var element = new object();
      Assert.True(ReferenceEquals(new[] { element }.AsQueryable().Random(), element));

      var elements = new[] { "first", "second" }.AsQueryable();
      Assert.True(elements.Contains(elements.Random()));
    }
        public void Random_PicksItems()
        {
            var action = new Action(() =>
            {
                var source = new[] {1, 2, 3, 4, 5, 6};
                var actualValue = source.Random();
                Assert.IsTrue(source.Contains(actualValue));
            });

            for (int i = 0; i < 1000; i++)
            {
                action();
            }
        }
示例#5
0
        private static void SendContinuousEvents(int delay, CancellationToken token, int maxEvents = Int32.MaxValue, int maxDaysOld = 90, Event ev = null) {
            Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 2);
            Console.WriteLine("Press 's' to stop sending.");
            int eventCount = 0;

            var levels = new[] { LogLevel.Trace, LogLevel.Debug, LogLevel.Info, LogLevel.Warn, LogLevel.Error, LogLevel.Fatal, LogLevel.Other };

            Task.Factory.StartNew(delegate {
                while (eventCount < maxEvents) {
                    if (token.IsCancellationRequested)
                        break;

                    if (ev != null && ev.IsLog())
                        ev.SetProperty(Event.KnownDataKeys.Level, levels.Random().Name);

                    SendEvent(ev, false);
                    eventCount++;
                    lock (_writeLock) {
                        Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 4);
                        Console.WriteLine("Submitted {0} events.", eventCount);
                    }

                    Thread.Sleep(delay);
                }

                ClearOutputLines();
            }, token);
        }
		/// <summary>
		///   Generates the name of a random domain.
		/// </summary>
		/// <returns>The random domain name.</returns>
		public static string DomainName()
		{
			var prefix = new[] { string.Empty, string.Empty, "www.", "www2." };

			return prefix.Random() + DomainNameWithoutPrefix();
		}
示例#7
0
		public static HorizontalSplit CreateView()
		{
			var h = new HorizontalSplit
			{

			};


			var sln = new SolutionBuilder
			{
				Name = "VisualBasicProject1",
				Language = new VisualBasicLanguage()
			};

			var v = new SolutionFileView();



			v.Container.style.height = "100%";

			// phase 1 has only one project at once.

			var _Solution = new TreeNode(VistaTreeNodePage.Create);
			var _Project = _Solution.Add();





			h.LeftContainer = v.Container;
			h.RightContainer = _Solution.Container;

			h.Value = 0.7;

			#region AtLink
			Action<Uri, Action<int>> AtLink =
				(Link, Handler) =>
				{
					var Counter = 0;

					v.LinkCommentClick +=
						uri =>
						{
							if (uri == Link)
							{
								Counter++;
								Handler(Counter);
							}
						};
				};
			#endregion

			Action Update =
				delegate
				{
					_Project.Clear();
					UpdateTree(sln, v, _Solution, _Project);
				};

			AtLink(sln.Interactive.ToVisualCSharpLanguage,
				delegate
				{
					sln.Language = new VisualCSharpLanguage();
					sln.Name = "VisualCSharpProject1";
					Update();
				}
			);

			AtLink(sln.Interactive.ToVisualBasicLanguage,
				delegate
				{
					sln.Language = new VisualBasicLanguage();
					sln.Name = "VisualBasicProject1";
					Update();
				}
			);


			AtLink(sln.Interactive.ToVisualFSharpLanguage,
				delegate
				{
					sln.Language = new VisualFSharpLanguage();
					sln.Name = "VisualFSharpProject1";
					Update();
				}
			);



			AtLink(sln.Interactive.ApplicationToDocumentTitle.Comment,
				ApplicationToDocumentTitleVariation =>
				{
					var Now = DateTime.Now;


					if (ApplicationToDocumentTitleVariation % 2 == 0)
						sln.Interactive.ApplicationToDocumentTitle.Title.Value =
							"Time: " + Now.ToString();
					else
						sln.Interactive.ApplicationToDocumentTitle.Title.Value =
							sln.Name;

					Update();
				}
			);

			var WebMethod2_From = new[]
			{
				"IL",
				"C#",
				"Visual Basic",
				"F#",
			};

			var WebMethod2_To = new[]
			{
				"JavaScript",
				"ActionScript",
				"Java",
				"PHP",
			};

			AtLink(sln.Interactive.WebMethod2,
				Variation =>
				{

					sln.Interactive.WebMethod2.Title.Value =
						"jsc can convert " + WebMethod2_From.Random() + " to " + WebMethod2_To.Random();

					Update();
				}
			);


			v.LinkCommentClick +=
				uri =>
				{
					Native.Document.location.hash = uri.Fragment;
				};


			UpdateTree(sln, v, _Solution, _Project);
			return h;
		}
        public OrcasAvalonApplicationCanvas()
        {
            Width = DefaultWidth;
            Height = DefaultHeight;

            this.ClipToBounds = true;

            var Images = new[]
            {
                //new SCImage ( 334, 558, 937 ),

                new SCImage ( 333, 840, 1410 ),

                new SCImage ( 332, 840, 1410 ),
                new SCImage ( 331, 840, 1410 ),
                new SCImage ( 330, 840, 1410 ),
                new SCImage ( 329, 860, 1410 ),
                new SCImage ( 328, 560, 940 ),
                new SCImage ( 327, 700, 900 ),
                new SCImage ( 325, 700, 900 ),
                new SCImage ( 324, 700, 900 ),
                new SCImage ( 323, 700, 900 ),
                new SCImage ( 322, 700, 900 ),
                new SCImage ( 321, 700, 900 ),
                new SCImage ( 309, 700, 900 ),
                new SCImage ( 308, 700, 900 ),
                new SCImage ( 306, 703, 903 ),
                new SCImage ( 305, 768, 1024 ),
                new SCImage ( 303, 768, 1024 ),
                new SCImage ( 302, 703, 937 ),
                new SCImage ( 300, 768, 1024 ),
                new SCImage ( 289, 790, 1024 ),
                new SCImage ( 287, 842, 1024 ),
                new SCImage ( 286, 722, 1024 ),
                new SCImage ( 284, 933, 1024 ),
                new SCImage ( 272, 781, 1000 ),
                new SCImage ( 271, 746, 1000 ),
                new SCImage ( 269, 838, 1000 ),
                new SCImage ( 267, 768, 983 ),
                new SCImage ( 265, 768, 949 ),
                new SCImage ( 253, 777, 1020 ),
                new SCImage ( 247, 692, 1020 ),
                new SCImage ( 244, 768, 951 ),
                new SCImage ( 243, 746, 1020 ),
                new SCImage ( 240, 768, 995 ),
                new SCImage ( 239, 847, 1020 ),
                new SCImage ( 237, 768, 980 ),
                new SCImage ( 236, 760, 947 ),
                new SCImage ( 233, 673, 1024 ),
                new SCImage ( 230, 730, 987 ),
                new SCImage ( 224, 739, 950 ),
                new SCImage ( 220, 744, 1020 ),
                new SCImage ( 214, 938, 1020 ),
                new SCImage ( 209, 760, 867 ),
                new SCImage ( 204, 551, 1020 ),
                new SCImage ( 200, 725, 1018 ),
                new SCImage ( 195, 703, 1000 ),
                new SCImage ( 193, 703, 1000 ),
                new SCImage ( 189, 703, 1000 ),
                new SCImage ( 184, 703, 1000 ),

                /*
                 *
                */

            };

            var r = Images.Random();

            r.Image.AttachTo(this);
            r.ClosureImage.AttachTo(this);
        }
示例#9
0
		public Rules(SolutionFileView v, SolutionBuilder sln, Action Update)
		{

			#region AtLink
			Action<Uri, Action<int>> AtLink =
				(Link, Handler) =>
				{
					var Counter = 0;

					v.LinkCommentClick +=
						uri =>
						{
							if (uri == Link)
							{
								Counter++;
								Handler(Counter);
							}
						};
				};
			#endregion


			AtLink(sln.Interactive.ToVisualCSharpLanguage,
				delegate
				{
					sln.Language = new VisualCSharpLanguage();
					sln.Name = "VisualCSharpProject1";
					Update();
				}
			);

			AtLink(sln.Interactive.ToVisualBasicLanguage,
				delegate
				{
					sln.Language = new VisualBasicLanguage();
					sln.Name = "VisualBasicProject1";
					Update();
				}
			);


			AtLink(sln.Interactive.ToVisualFSharpLanguage,
				delegate
				{
					sln.Language = new VisualFSharpLanguage();
					sln.Name = "VisualFSharpProject1";
					Update();
				}
			);



			AtLink(sln.Interactive.ApplicationToDocumentTitle.Comment,
				ApplicationToDocumentTitleVariation =>
				{
					var Now = DateTime.Now;


					if (ApplicationToDocumentTitleVariation % 2 == 0)
						sln.Interactive.ApplicationToDocumentTitle.Title.Value =
							"Time: " + Now.ToString();
					else
						sln.Interactive.ApplicationToDocumentTitle.Title.Value =
							sln.Name;

					Update();
				}
			);

			var WebMethod2_From = new[]
			{
				"IL",
				"C#",
				"Visual Basic",
				"F#",
			};

			var WebMethod2_To = new[]
			{
				"JavaScript",
				"ActionScript",
				"Java",
				"PHP",
			};

			AtLink(sln.Interactive.WebMethod2,
				Variation =>
				{

					sln.Interactive.WebMethod2.Title.Value =
						"jsc can convert " + WebMethod2_From.Random() + " to " + WebMethod2_To.Random();

					Update();
				}
			);

			Action<InteractiveComment> AtInteractiveComment =
				c =>
				{
					AtLink(c,
						vv =>
						{
							c.RaiseClick();
							Update();
						}
					);
				};


			sln.Interactive.Comments.WithEach(AtInteractiveComment);

			

		}
 public void Random__SourceHasOneElement_And_ElementDoesNotSatisfyPredicate__ReturnsNone()
 {
     var source = new[] { new object() };
     Assert.That(source.Random(o => false).IsNone);
 }
 public void Random__SourceHasOneElement_And_ElementSatisfiesPredicate__ReturnsThatElement()
 {
     var source = new[] { new object() };
     Assert.That(source.Random(o => true).Value, Is.SameAs(source[0]));
 }
 public void Random__SourceHasMoreThanOneElement_And_SomeElementsSatisfyPredicate__ReturnsAnElementFromTheSourceThatSatisfyPredicate()
 {
     var source = new [] { new object(), new object(), new object() };
     var elementsThatSatisfyPredicate = new[] { source[0], source[2] };
     CollectionAssert.Contains(elementsThatSatisfyPredicate, source.Random(elementsThatSatisfyPredicate.Contains).Value);
 }
 public void Random__SourceHasMoreThanOneElement_And_AllElementsSatisfyPredicate__ReturnsAnElementFromTheSource()
 {
     var source = new[] { new object(), new object(), new object() };
     CollectionAssert.Contains(source, source.Random(o => true).Value);
 }
        //const int Parallax1Width = DefaultWidth + 100;
        //const int Parallax1Height = DefaultHeight + 100;
        //Canvas Parallax1;
        private void InitializeBackground()
        {
            //this.Parallax1 = new Canvas
            //{

            //}.SizeTo(Parallax1Width, Parallax1Height).AttachTo(this);

            var TileSize = 96;
            var TilesAtBorder = 10;

            #region tiled background
            if (!IsBackgroundTransparent)
            {

                var BackgroundColors = new[]
                {
                    Brushes.Orange,
                    Brushes.White,
                    Brushes.Gray,
                    Brushes.DarkGray,
                    Brushes.Tan,
                    Brushes.Yellow,
                    Brushes.YellowGreen,
                    Brushes.Red,
                    Brushes.DarkGreen,
                    Brushes.PaleVioletRed
                };

                var BackgroundFill = new Rectangle
                {
                    Width = DefaultWidth + 2 * TileSize * TilesAtBorder,
                    Height = DefaultHeight + 2 * TileSize * TilesAtBorder,
                    Fill = BackgroundColors.Random()
                }.MoveTo(-TileSize * TilesAtBorder, -TileSize * TilesAtBorder).AttachTo(this);
            }

                for (int x = -TileSize * TilesAtBorder; x < DefaultWidth + 2 * TileSize * TilesAtBorder; x += TileSize)
                    for (int y = -TileSize * TilesAtBorder; y < DefaultHeight + 2 * TileSize * TilesAtBorder; y += TileSize)
                    {
                        //var n = ("assets/AvalonMinesweeper.Core/bg_red.png").ToImage(TileSize, TileSize).MoveTo(x, y).AttachTo(this);
                        var n = ("assets/AvalonMinesweeper.Core/bg_a50.png").ToImage(TileSize, TileSize).MoveTo(x, y).AttachTo(this);

                        //var n = ("assets/AvalonMinesweeper.Core/bg_lightgreen.png").ToImage(TileSize, TileSize).MoveTo(x, y).AttachTo(this);
                        //var n = ("assets/AvalonMinesweeper.Core/bg.png").ToImage(TileSize, TileSize).MoveTo(x, y).AttachTo(this);
                    }

            #endregion

            // http://forums.somethingawful.com/showthread.php?threadid=2929126&userid=0&perpage=40&pagenumber=29
            // http://forums.somethingawful.com/showthread.php?threadid=2929126&userid=0&perpage=40&pagenumber=33

            // http://bruno.mirror.waffleimages.com/files/ae/aecdf0451bd36998d40e77c4cb7d8f3d022cc1b2.png
            // http://bruno.mirror.waffleimages.com/files/78/784fa6431868f96af926637a39ee047f1e377a45.png
            // http://forums.somethingawful.com/showthread.php?threadid=2929126&userid=0&perpage=40&pagenumber=36

            #region zak

            // parrallax effect?
            // allow to buy zak?
            // http://www.pixeldam.net/project.asp?id=586
            //("assets/AvalonMinesweeper.Core/zak.png").ToImage(ZakWidth, ZakHeight).MoveTo((DefaultWidth - ZakWidth) / 2, (DefaultHeight - ZakHeight) / 2).AttachTo(this);
            var PossibleBackgroundScripts = new Action[]
            {
                delegate
                {

                    const int ZakWidth = 799;
                    const int ZakHeight = 467;

                    ("assets/AvalonMinesweeper.Core/zak_a.png").ToImage(ZakWidth, ZakHeight).MoveTo((-ZakWidth) *0.25, (-ZakHeight) / 2).AttachTo(this);
                    ("assets/AvalonMinesweeper.Core/zak_a.png").ToImage(ZakWidth, ZakHeight).MoveTo(DefaultWidth + (-ZakWidth) * 0.75, DefaultHeight + (-ZakHeight) / 2).AttachTo(this);

                },
                delegate
                {

                    // http://www.mixnmojo.com/features/read.php?article=zakmckracken&page=1
                    // http://www.reloaded.org/download/New-Adventures-Zak-McKracken/28/
                    // http://www.zak-site.com/fun.htm
                    // http://www.zak-site.com/fun.htm

                    const int StargateWidth = 541;
                    const int StargateHeight = 375;

                    ("assets/AvalonMinesweeper.Core/stargate.png").ToImage(StargateWidth, StargateHeight).MoveTo((-StargateWidth) * 0.25, (-StargateHeight) / 2).AttachTo(this);
                    ("assets/AvalonMinesweeper.Core/stargate.png").ToImage(StargateWidth, StargateHeight).MoveTo(DefaultWidth + (-StargateWidth) * 0.75, DefaultHeight + (-StargateHeight) / 2).AttachTo(this);

                }
            };

            PossibleBackgroundScripts.Random()();

            #endregion

            //            this.ScrollTrap = new Rectangle
            //            {
            //                Fill = Brushes.White,
            //                Width = DefaultWidth - ScrollMargin * 2,
            //                Height = DefaultHeight - ScrollMargin * 2,
            //#if DEBUG
            //                Opacity = 0.2
            //#else
            //                Opacity = 0
            //#endif

            //            }.MoveTo(ScrollMargin, ScrollMargin).AttachTo(this);

            #region jsc logo
            ("assets/AvalonMinesweeper.Core/jsc.png").ToImage(96, 96).MoveTo(
                (DefaultWidth - (96)),
                (DefaultHeight - (96))
            ).AttachTo(this);
            #endregion

            #region Notice
            var Notice = new TextBox
            {
                IsReadOnly = true,
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                Foreground = Brushes.Red,
                Text = Info.Title + " (" + BuildInformation + ")" + " is still under development. Please do not redistribute this game!",
                TextAlignment = TextAlignment.Center,
                Width = DefaultWidth,
                Height = 32,
                FontFamily = new FontFamily("Verdana")
            }.AttachTo(this).MoveTo(0, DefaultHeight - 32);
            //Notice.BitmapEffect = new DropShadowBitmapEffect();

            #endregion

            #region Title
            var TitleShadow = new TextBox
            {
                IsReadOnly = true,
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                Foreground = Brushes.Black,
                Text = Info.Title,
                TextAlignment = TextAlignment.Center,
                Width = DefaultWidth,
                Height = 40,
                FontFamily = new FontFamily("Verdana"),
                FontSize = 30
            }.AttachTo(this).MoveTo(0 + 1, DefaultHeight - 32 - 40 + 1);

            var Title = new TextBox
            {
                IsReadOnly = true,
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                Foreground = Brushes.White,
                Text = Info.Title,
                TextAlignment = TextAlignment.Center,
                Width = DefaultWidth,
                Height = 40,
                FontFamily = new FontFamily("Verdana"),
                FontSize = 30
            }.AttachTo(this).MoveTo(0, DefaultHeight - 32 - 40);
            #endregion

            #region Loading
            var LoadingShadow = new TextBox
            {
                IsReadOnly = true,
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                Foreground = Brushes.Black,
                Text = "Loading...",
                TextAlignment = TextAlignment.Center,
                Width = DefaultWidth,
                Height = 40,
                FontFamily = new FontFamily("Verdana"),
                FontSize = 20
            }.AttachTo(this).MoveTo(0 + 1, DefaultHeight / 2 - 40 + 1);

            var Loading = new TextBox
            {
                IsReadOnly = true,
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                Foreground = Brushes.White,
                Text = "Loading...",
                TextAlignment = TextAlignment.Center,
                Width = DefaultWidth,
                Height = 40,
                FontFamily = new FontFamily("Verdana"),
                FontSize = 20
            }.AttachTo(this).MoveTo(0, DefaultHeight / 2 - 40);
            #endregion

            var Status = new TextBox
            {
                IsReadOnly = true,
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                Foreground = Brushes.Yellow,
                Text = BuildInformation,
                TextAlignment = TextAlignment.Center,
                Width = DefaultWidth,
                Height = 20,
                FontFamily = new FontFamily("Verdana")
            }.AttachTo(this).MoveTo(0, 8);

            //Status.Effect = new DropShadowEffect();

            this.Status = new Action<string>(t => Status.Text = t);
        }
        public ApplicationCanvas()
        {
            this.Background = Brushes.Red;

            r.Fill = Brushes.White;
            r.AttachTo(this);
            r.MoveTo(4, 4);

            this.SizeChanged += (s, e) => r.SizeTo(this.Width - 8.0, this.Height - 8.0);

            {
                var ego = new ski1();

                ego.AttachTo(this).MoveTo(164, 96);

                (1000 / 60).AtIntervalWithCounter(
                    c =>
                    {
                        ego.MoveTo(164, c % this.Height);
                    }
                );
            }

            {
                var ego = new ski1();

                var dc = -64;

                ego.AttachTo(this).MoveTo(320, dc);

                (1000 / 60).AtIntervalWithCounter(
                    c =>
                    {
                        ego.MoveTo(320, (c + dc) % this.Height);
                    }
                );
            }

            Action<double, double> tree = (x, y) => new ski51().AttachTo(this).MoveTo(x, y);
            Action<double, double> deadtree = (x, y) => new ski50().AttachTo(this).MoveTo(x, y);
            Action<double, double> stone = (x, y) => new ski45().AttachTo(this).MoveTo(x, y);
            Action<double, double> stonefield = (x, y) => new ski27().AttachTo(this).MoveTo(x, y);

            tree(64, 32);

            var logo = new Avalon.Images.jsc().AttachTo(this);

            this.SizeChanged += (s, e) => logo.MoveTo(this.Width - logo.Width, this.Height - logo.Height);

            this.MouseLeftButtonUp +=
                (s, a) =>
                {
                    var pos = a.GetPosition(this);

                    var f = new[] {
                        tree,
                        tree,
                        tree,
                        tree,
                        deadtree,
                        deadtree,
                        stone,
                        stone,
                        stone,
                        stonefield };

                    f.Random()(pos.X, pos.Y);
                };

            var t = new TextBox
            {
                Text = "ski",
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0)
            };

            t.AttachTo(this).MoveTo(96, 8);

            var ax = 0.0;
            var ay = 0.0;
            var az = 0.0;

            Action SizeChangedOrAccelerated =
                delegate
                {
                    t.Text = "ski: " + new { this.Width, this.Height, ax, ay, az };
                };

            this.SizeChanged += (s, e) => { SizeChangedOrAccelerated(); };

            t2.AttachTo(this).MoveTo(96, 24);

            Accelerate =
                (_ax, _ay, _az) =>
                {
                    ax = _ax;
                    ay = _ay;
                    az = _az;

                    SizeChangedOrAccelerated();
                };
        }
        private string GetWelDoneMessage()
        {
            var messages = new[]
                {
                    "That’s great", "Good job", "Excellent", "I appreciate that", "That’s looking good", "Good work",
                    "Great work", "You’re doing well",
                    "Good to have you on the team", "You made the difference", "Exceptional", "Wonderful",
                    "That is so significant", "Superb",
                    "Perfect", "Just what was needed", "Centre button", "A significant contribution", "Wow", "Fantastic",
                    "Thanks you", "Just what the doctor ordered", "First class", "Nice job", "Way to go", "Far out",
                    "Just the ticket", "You are a legend", "Very professional", "Where would we be without you",
                    "Brilliant", "Top marks",
                    "Impressive", "You hit the target", "Neat", "Cool", "Bullseye", "How did you get so good",
                    "Beautiful", "Just what was wanted",
                    "Right on the money", "Great", "Just right", "Congratulations", "Very skilled",
                    "I’m glad you’re on my team", "It is good to work with you", "You did us proud",
                    "This is going to make us shine", "Well done", "I just love it", "You are fantastic", "Great job",
                    "Professional as usual", "You take the biscuit every time", "I’m proud of you",
                    "Don’t ever leave us","Are you good or what?","The stuff of champions","Cracking job","First class job",
                    "Magnificent","Bravo","Amazing","Simply superb","Triple A","Perfection",
                    "Poetry in motion","Sheer class","World class","Polished performance","Class act",
                    "Unbelievable","Gold plated","Just classic","Super","Now you’re cooking",
                    "You are so good","You deserve a pat on the back","Tremendous job","Unreal",
                    "Treasure","Crash hot","You beauty","The cat’s whiskers","I just can’t thank you enough",
                    "You always amaze me","Magic","Another miracle","Terrific","What a star",
                    "Colossal","Wonderful","Top form","You’re one of a kind","Unique",
                    "Way out","Incredible","Ace"};

            return messages.Random();
        }