Randomizer returns a set of random values in a repeatable way, to allow re-running of tests if necessary.
Наследование: System.Random
Пример #1
0
 public void Randomizer_Should_Initialize()
 {
     var target = new Randomizer();
     Assert.IsNotNull(target);
     target.Should ().NotBeNull ();
     target.Should ().BeOfType<Randomizer> ();
 }
		public void IntensiveEditingSession()
		{
			var table = PieceTable.ForArray(new int[0]);

			const int iterations = 10*1000;
			const int insertionsPerIteration = 30;
			const int deletionsPerIteration = 2;

			var random = new Randomizer(42);
			var totalTime = BenchmarkIterations(iterations, delegate
			{
				var insertionPoint = random.Next(table.Length);
				for (var i = 0; i < insertionsPerIteration; ++i)
					table = table.Insert(insertionPoint + i, i);

				var readPosition = random.Next(table.Length);
				table.ToArray(readPosition, Math.Min(table.Length - readPosition, insertionsPerIteration));

				for (var i = 0; i < deletionsPerIteration; ++i)
					table = table.Delete(random.Next(table.Length), 1);
			});

			const int totalNumberOfOperations = iterations*(insertionsPerIteration + deletionsPerIteration);
			ReportTotalNumberOfOperations(totalTime, totalNumberOfOperations);
			Assert.AreEqual(iterations*insertionsPerIteration - iterations*deletionsPerIteration, table.Length);
		}
Пример #3
0
 public void Setup()
 {
     var rnd = new Randomizer();
     _instance = new DcmIntegerString(DicomTags.ReferencedFrameNumber);
     _instance.SetValues(
         rnd.GetInts(0, 65535, 5000).Select(i => i.ToString(CultureInfo.InvariantCulture)).
         Concat(new[] { "32767" }).ToArray());
 }
Пример #4
0
 public void Randomizer_Should_Initialize_And_Dispose()
 {
     using (var target = new Randomizer())
     {
         target.Should ().NotBeNull ();
         target.Should ().BeOfType<Randomizer> ();
     }
 }
Пример #5
0
        public void Create_an_SSN()
        {
            var ssn = new Randomizer().Replace("###-##-####");
            ssn.Dump();

            var code = new Randomizer().Replace("##? ??? ####");
            code.Dump();
        }
 public void WhenFillingTheFieldsWithValidData()
 {
     Random randomizer = new Randomizer();
     WebBrowser.Current.TextField("Name").Value = "name";
     WebBrowser.Current.TextField("Email").Value = randomizer.Next().ToString(CultureInfo.InvariantCulture) + "@test.com";
     WebBrowser.Current.TextField("Password").Value = "abcdefghijk";
     WebBrowser.Current.TextField("PasswordConfirmation").Value = "abcdefghijk";
 }
Пример #7
0
        /// <summary>
        /// Get a randomizer for a particular member, returning
        /// one that has already been created if it exists.
        /// This ensures that the same values are generated
        /// each time the tests are reloaded.
        /// </summary>
        public static Randomizer GetRandomizer(MemberInfo member)
        {
            Randomizer r = (Randomizer)randomizers[member];

            if ( r == null )
                randomizers[member] = r = new Randomizer();

            return r;
        }
Пример #8
0
        public void TestRangeSelection()
        {
            Randomizer randomizer = new Randomizer();
            int[] indices = randomizer.GetInts(0, this.selectionModel.Items.Count, 2);
            Array.Sort(indices);
            this.selectionModel.SelectRange(indices[0], indices[1]);

            AssertRangeSelected(indices);
        }
Пример #9
0
        public void Randomizer_Should_Return_Random_Entries_From_A_Collection()
        {
            var values = new List<string>();
            for (int i = 0; i < 99; i++)
                values.Add("UserNo" + i);

            using (var randomizer = new Randomizer())
            {
                var firstValue = randomizer.Random(values);
                var secondValue = randomizer.Random(values);

                // Assert that in the list of 100 values, two randomly choses will not be the same
                // Statitically, this is a rubbish test; there is always a slight probability the
                // two values are the same
                Assert.AreNotEqual(firstValue, secondValue);
            }
        }
		public void SequentialAccessAfterManyDeletions()
		{
			const int numberOfDeletions = 100;
			const int numberOfCharacters = 500;
			const int iterations = 10 * 1000;

			var randomizer = new Randomizer(42);

			var table = PieceTable.ForString(new string(' ', 5 * 1024));
			for (var i = 0; i < numberOfDeletions; ++i)
				table = table.Delete(randomizer.Next(table.Length), 1);

			Console.WriteLine("** CopyTo iteration **");
			var buffer = new char[1];
			var totalWithout = BenchmarkIterations(iterations, delegate
			{
				var position = randomizer.Next(table.Length - numberOfCharacters * 2) + numberOfCharacters;
				for (var i = 0; i < numberOfCharacters; ++i)
					table.CopyTo(buffer, 0, position + i, 1);
				for (var i = 0; i < numberOfCharacters; ++i)
					table.CopyTo(buffer, 0, position - i, 1);
			});
			const int totalNumberOfOperations = iterations*numberOfCharacters;
			ReportTotalNumberOfOperations(totalWithout, totalNumberOfOperations);

			Console.WriteLine("** Point iteration **");
			var totalWith = BenchmarkIterations(iterations, delegate
			{
				var position = randomizer.Next(table.Length - numberOfCharacters * 2) + numberOfCharacters;
				var pivot = table[position];
				var current = pivot;
				for (var i = 0; i < numberOfCharacters; ++i)
				{
					current.GetValue();
					current = current.Next;
				}
				current = pivot;
				for (var i = 0; i < numberOfCharacters; ++i)
				{
					current.GetValue();
					current = current.Previous;
				}
			});
			ReportTotalNumberOfOperations(totalWith, totalNumberOfOperations);
		}
		public void Benchmark()
		{
			SetText("");

			const int iterations = 500;
			const int insertionsPerIteration = 30;
			const int deletionsPerIteration = 2;

			var totalTime = 0L;
			var worst = 0L;
			var random = new Randomizer(42);
			for (var i = 0; i < iterations; ++i)
			{
				var watch = Stopwatch.StartNew();

				var insertionPoint = random.Next(Buffer.CurrentSnapshot.Length);
				for (var j = 0; j < insertionsPerIteration; ++j)
					Buffer.Insert(insertionPoint + j, " ");

				var length = Buffer.CurrentSnapshot.Length;
				var readPosition = random.Next(length);
				Buffer.CurrentSnapshot.GetText(readPosition, Math.Min(length - readPosition, insertionsPerIteration));

				for (var j = 0; j < deletionsPerIteration; ++j)
					Buffer.Delete(random.Next(Buffer.CurrentSnapshot.Length), 1);

				watch.Stop();
				var iterationTime = watch.ElapsedMilliseconds;
				if (worst < iterationTime)
					worst = iterationTime;
				totalTime += iterationTime;
			}
			Console.WriteLine("Worst iteration time: {0}ms.", worst);
			Console.WriteLine("Average iteration time: {0}ms.", totalTime / (float)iterations);

			const int totalNumberOfOperations = iterations * (insertionsPerIteration + deletionsPerIteration);
			Console.WriteLine("{0} operations in {1}ms or {2} operations/sec.", totalNumberOfOperations, totalTime, totalNumberOfOperations / (totalTime / 1000.0));

			Assert.AreEqual(iterations * insertionsPerIteration - iterations * deletionsPerIteration, Buffer.CurrentSnapshot.Length);
		}
Пример #12
0
        public void Randomizer_Should_Give_Different_Results_Each_Time_Initialized()
        {
            // Arrange
            var values = new List<string>();
            for (int i = 0; i < 99; i++)
                values.Add("UserNo" + i);

            string firstValue = string.Empty, secondValue = string.Empty;

            // Act - initialize two Randomizer instances and fetch a random value
            using (var randomizer = new Randomizer()) {
                firstValue = randomizer.Random(values);
            }

            using (var randomizer = new Randomizer()) {
                secondValue = randomizer.Random(values);
            }

            // Assert - that in the list of lots of values, two randomly choses will not be the same
            // Statitically, this is a rubbish test; there is always a slight probability the
            // two values are the same
            firstValue.Should().NotBe(secondValue, "multiple randomizers should give different results");
        }
Пример #13
0
        public void TestRandomCrypto()
        {
            Console.WriteLine();
            var bytes = new byte[512];
            var serverRandom = new byte[14];
            var randomizerSeed = Randomizer.RandomSeed;
            m_Randomizer = new Randomizer(randomizerSeed);
            var seed = m_Randomizer.Next();

            m_Randomizer.NextBytes(serverRandom);
            m_Crypto.UpdateCiphers((ulong)seed, serverRandom);
            m_Crypto.Encrypt(bytes);

            Console.WriteLine("Randomizer Seed: {0}", randomizerSeed);
            Console.WriteLine("Seed: {0}", seed);
            Console.WriteLine("ServerRandom Dump");
            Console.WriteLine("-----------------");
            TestUtils.Print(serverRandom);
            Console.WriteLine();

            Console.WriteLine("RandomCrypto Dump");
            Console.WriteLine("-----------------");
            TestUtils.Print(bytes);
        }
Пример #14
0
 protected override ulong GetNext(Randomizer randomizer, ulong min, ulong max)
 {
     return(randomizer.NextULong(min, max));
 }
Пример #15
0
 protected override Guid GetNext(Randomizer randomizer)
 {
     return(randomizer.NextGuid());
 }
Пример #16
0
 public void BeforeRunningTestSession()
 {
     r = new Randomizer();
 }
Пример #17
0
            public void should_not_cause_channel_exception()
            {
                var countdown = new CountdownEvent(10000);
                var random = new Randomizer();

                IBus producer = this.StartBus(
                    "producer",
                    cfg => cfg.Route("request").
                               WithDefaultCallbackEndpoint());
                this.StartBus(
                    "consumer",
                    cfg => cfg.On<DummyRequest>("request").
                               ReactWith(
                                   (m, ctx) => Task.Factory.StartNew(
                                       () =>
                                           {
                                               Thread.Sleep(random.Next(10));
                                               ctx.Accept();
                                               ctx.Reply(new DummyResponse(m.Num));
                                               countdown.Signal();
                                           })).
                               RequiresAccept());

                Enumerable.Range(0, 10000).
                    ForEach(i => producer.RequestAsync<DummyRequest, DummyResponse>("request", new DummyRequest(i)));

                countdown.Wait(40.Seconds()).
                    Should().
                    BeTrue();
            }
Пример #18
0
 protected abstract T GetNext(Randomizer randomizer);
Пример #19
0
 protected override float GetNext(Randomizer randomizer, float min, float max)
 {
     return(randomizer.NextFloat(min, max));
 }
Пример #20
0
 protected override float GetNext(Randomizer randomizer)
 {
     return(randomizer.NextFloat());
 }
Пример #21
0
 protected override double GetNext(Randomizer randomizer, double min, double max)
 {
     return(randomizer.NextDouble(min, max));
 }
Пример #22
0
 protected override double GetNext(Randomizer randomizer)
 {
     return(randomizer.NextDouble());
 }
Пример #23
0
 protected override ushort GetNext(Randomizer randomizer, ushort min, ushort max)
 {
     return(randomizer.NextUShort(min, max));
 }
Пример #24
0
 protected override ushort GetNext(Randomizer randomizer)
 {
     return(randomizer.NextUShort());
 }
Пример #25
0
        public void OnNodeAddedToMap()
        {
            //Arrange
            var randomizer = new Randomizer();
            var x = randomizer.Next(-100, 100);
            var y = randomizer.Next(-100, 100);
            var point = new Point(x, y);
            var node = new NodeModel { NodeId = Guid.NewGuid(), Name = "SomeNode" };
            var args = new MapNodeEventArgs {NodeId = node.NodeId, Position = point };

            //Act
            _form.OnNodeAddedToMap(null, args);

            //Assert
            _mockNodeList.Verify(l => l.RemoveNode(node.NodeId));
            _mockPresenter.Verify(p => p.NodeAddedToMap(node.NodeId, x, y));
        }
Пример #26
0
        public void OnNodeMove()
        {
            //Arrange
            var randomizer = new Randomizer();
            var x = randomizer.Next(-100, 100);
            var y = randomizer.Next(-100, 100);
            var point = new Point(x, y);
            var args = new MapNodeEventArgs {NodeId = Guid.NewGuid(), Position = point};

            //Act
            _form.OnNodeMoved(null,args);

            //Assert
            _mockPresenter.Verify(p => p.NodeMovedOnMap(args.NodeId, x, y));
        }
Пример #27
0
 protected override sbyte GetNext(Randomizer randomizer)
 {
     return(randomizer.NextSByte());
 }
Пример #28
0
 protected abstract T GetNext(Randomizer randomizer, T min, T max);
Пример #29
0
        public void TestSelectAllThenRange()
        {
            Randomizer randomizer = new Randomizer();
            int[] indices = randomizer.GetInts(0, this.selectionModel.Items.Count, 2);
            Array.Sort(indices);

            this.selectionModel.Select(this.selectionModel.Items[indices[0]]);
            this.selectionModel.SelectAll();
            this.selectionModel.SelectRange(indices[1], true);

            this.AssertRangeSelected(indices);
        }
Пример #30
0
            public void should_open_single_connection()
            {
                var random = new Randomizer();
                IBus bus = this.ConfigureBus("Test", cfg => cfg.Route("some.label"));

                bus.Start();

                Task[] tasks = Enumerable.Range(0, 20).Select(
                        _ =>
                            {
                                Thread.Sleep(random.Next(10));
                                if (random.Next(10) % 2 == 0)
                                {
                                    return Task.Factory.StartNew(() => bus.Start());
                                }

                                return Task.Factory.StartNew(bus.Stop);
                            }).ToArray();

                Task.WaitAll(tasks, 15.Seconds()).Should().BeTrue();
            }
Пример #31
0
 protected override decimal GetNext(Randomizer randomizer)
 {
     return(randomizer.NextDecimal());
 }
Пример #32
0
 protected override decimal GetNext(Randomizer randomizer, decimal min, decimal max)
 {
     return(randomizer.NextDecimal(min, max));
 }
Пример #33
0
 protected override uint GetNext(Randomizer randomizer, uint min, uint max)
 {
     return(randomizer.NextUInt(min, max));
 }
Пример #34
0
 public void Without_Fluent_Syntax()
 {
     var random = new Randomizer();
     var lorem = new Lorem();
     var o = new Order()
         {
             OrderId = random.Number(1, 100),
             Item = lorem.Sentence(),
             Quantity = random.Number(1, 10)
         };
     o.Dump();
 }
 public void WhenFillingTheFieldsWithUnknownUser()
 {
     Random randomizer = new Randomizer();
     WebBrowser.Current.TextField("Email").Value = randomizer.Next().ToString(CultureInfo.InvariantCulture) + "@test.com";
     WebBrowser.Current.TextField("Password").Value = "abcdefghijk";
 }
Пример #36
0
 protected override Guid GetNext(Randomizer randomizer, Guid min, Guid max)
 {
     throw new NotSupportedException($"{typeof(Guid)} does not support range of parameters being specified.");
 }
Пример #37
0
 protected override uint GetNext(Randomizer randomizer)
 {
     return(randomizer.NextUInt());
 }
Пример #38
0
 protected override sbyte GetNext(Randomizer randomizer, sbyte min, sbyte max)
 {
     return(randomizer.NextSByte(min, max));
 }
Пример #39
0
 protected override ulong GetNext(Randomizer randomizer)
 {
     return(randomizer.NextULong());
 }