public void Constructor_shall_not_call_within_short_timeframe_to_generate_unique_information() { using (new IndirectionsContext()) { // Arrange var seeds = new HashSet <int>(); PRandom.ConstructorInt32().Body = (@this, seed) => { IndirectionsContext.ExecuteOriginal(() => { var ctor = typeof(Random).GetConstructor(new[] { typeof(int) }); ctor.Invoke(@this, new object[] { seed }); }); seeds.Add(seed); }; new Random(); // preparing JIT seeds.Clear(); // Act var vil1 = new Village(); Thread.Sleep(TimeSpan.FromSeconds(1)); var vil2 = new Village(); // Assert Assert.AreEqual(2, seeds.Count); } }
public void GetShortestRoute_should_consider_routes_in_order_from_small_distance() { using (new IndirectionsContext()) { // Arrange var slot = 0; var numAndDistances = new[] { 4, 2, 4, 3, 1, 6, 7 }; PRandom.NextInt32().Body = (@this, maxValue) => numAndDistances[slot++]; var vil = new Village(); var considerations = new List <RicePaddy>(); PList <RicePaddy> .AddT().Body = (@this, item) => { IndirectionsContext.ExecuteOriginal(() => { considerations.Add(item); @this.Add(item); }); }; // Act var result = vil.GetShortestRoute(vil.RicePaddies.ElementAt(2), vil.RicePaddies.ElementAt(0)); // Assert Assert.AreEqual(3, result.TotalDistance); Assert.AreEqual(4, considerations.Count); Assert.AreEqual(2, considerations[0].Identifier); Assert.AreEqual(1, considerations[1].Identifier); Assert.AreEqual(0, considerations[2].Identifier); Assert.AreEqual(3, considerations[3].Identifier); } }
private Asteroid CreateAsteroid() { PRandom pr = new PRandom(); return(new Asteroid(_grid, new Position((int)_grid.Width, pr.Next((int)(_grid.Height - 80))), // -80 wtf new Vector(pr.Next((int)(-Asteroid.AsteroidsDefaultSpeed * 2), (int)(-Asteroid.AsteroidsDefaultSpeed)), pr.Next((int)(-Asteroid.AsteroidsDefaultSpeed / 2), (int)(Asteroid.AsteroidsDefaultSpeed / 2))), asteroidSize: 3)); }
public void Init(int stars) { if (stars > 0) { PRandom pr = new PRandom(); for (int i = 0; i < stars; i++) { _stars.Add(new Star(_grid, new Position(pr.Next((int)_grid.Width), pr.Next((int)_grid.Height), pr.NextDouble()), new Vector(-StarsDefaultSpeed, 0))); } Initialized = true; } }
public void Constructor_should_be_initialized_by_non_null_if_number_that_is_not_divisible_by_10_is_passed() { using (new IndirectionsContext()) { // Arrange var actualValue = 0; PRandom.Next().Body = @this => 9; PNullable <int> .ConstructorT().Body = (ref Nullable <int> @this, int value) => { actualValue = value; @this = IndirectionsContext.ExecuteOriginal(() => new Nullable <int>(value)); }; // Act var paddy = new RicePaddy(1, new Random()); // Assert Assert.AreEqual(9000, actualValue); } }
public void ValueWithRandomAdded_should_hold_passed_value_plus_random_value() { using (new IndirectionsContext()) { // Arrange var notifyingObject = new NotifyingObject(); var mockNext = new Mock <IndirectionFunc <Random, int> >(); mockNext.Setup(_ => _(It.IsAny <Random>())).Returns(10); PRandom.Next().Body = mockNext.Object; // Act notifyingObject.ValueWithRandomAdded = 32; var actual = notifyingObject.ValueWithRandomAdded; // Assert mockNext.Verify(_ => _(It.IsAny <Random>()), Times.Once()); Assert.AreEqual(42, actual); } }
public void ValueWithRandomAdded_should_hold_passed_value_plus_random_value() { using (new IndirectionsContext()) { // Arrange var notifyingObject = new NotifyingObject(); var mockNext = MockRepository.GenerateStub <IndirectionFunc <Random, int> >(); mockNext.Stub(_ => _(Arg <Random> .Is.Anything)).Return(10); PRandom.Next().Body = mockNext; // Act notifyingObject.ValueWithRandomAdded = 32; var actual = notifyingObject.ValueWithRandomAdded; // Assert mockNext.AssertWasCalled(_ => _(Arg <Random> .Is.Anything), options => options.Repeat.Once()); Assert.AreEqual(42, actual); } }
public void ValueWithRandomAdded_should_hold_passed_value_plus_random_value() { using (new IndirectionsContext()) { // Arrange var notifyingObject = new NotifyingObject(); var mockNext = Substitute.For <IndirectionFunc <Random, int> >(); mockNext(Arg.Any <Random>()).Returns(10); PRandom.Next().Body = mockNext; // Act notifyingObject.ValueWithRandomAdded = 32; var actual = notifyingObject.ValueWithRandomAdded; // Assert mockNext.Received(1)(Arg.Any <Random>()); Assert.AreEqual(42, actual); } }
public void ValueWithRandomAdded_should_hold_passed_value_plus_random_value() { using (new IndirectionsContext()) { // Arrange var notifyingObject = new NotifyingObject(); var mockNext = A.Fake <IndirectionFunc <Random, int> >(); A.CallTo(() => mockNext(A <Random> ._)).Returns(10); PRandom.Next().Body = mockNext; // Act notifyingObject.ValueWithRandomAdded = 32; var actual = notifyingObject.ValueWithRandomAdded; // Assert A.CallTo(() => mockNext(A <Random> ._)).MustHaveHappened(); Assert.AreEqual(42, actual); } }
public List <Asteroid> Destroy() { List <Asteroid> result = new List <Asteroid>(); ToRemove = true; AsteroidDestroyed?.Invoke(this, new EventArgs()); Remove(); if (_asteroidSize != 1) { Asteroid a1 = new Asteroid(_grid, _pos.Copy(), _vec.Copy(), asteroidSize: (byte)(_asteroidSize - 1)); Position p2 = _pos.Copy(); p2.X += DefaultSize; p2.Y += DefaultSize; PRandom pr = new PRandom(); GBsharp2.Primitives.Vector v2 = new GBsharp2.Primitives.Vector(pr.Next((int)(-AsteroidsDefaultSpeed * 2), (int)(-AsteroidsDefaultSpeed)), pr.Next((int)(-AsteroidsDefaultSpeed / 2), (int)(AsteroidsDefaultSpeed / 2))); Asteroid a2 = new Asteroid(_grid, p2, v2, asteroidSize: (byte)(_asteroidSize - 1)); result.Add(a1); result.Add(a2); } return(result); }
public Point2 GetInitialPosition(MazeChunk[,] map) { return(new Point2(PRandom.Range(0, map.GetUpperBound(0) - 1), PRandom.Range(0, map.GetUpperBound(1)))); }
protected override void InitializeSources() { AddSource(PRandom.WeightedRandom(originalSettings.Sources, originalSettings.Weights)); }
public static float WhiteNoise(OscillationSettings settings, float time) { return(settings.Amplitude * PRandom.Range(-1f, 1f) + settings.Center); }
public AsteroidField(Grid grid) { _asteroids = new List <Asteroid>(); _rand = new PRandom(); _grid = grid; }