Example #1
0
        public void InitializeFrom_GivenNullPattern_ThrowsException()
        {
            // arrange
            var mockRules = new Mock <RulesBase>(new[] { 1 }, new[] { 2 });
            var game      = new LinqGame(mockRules.Object);

            // act:ish
            Action action = () => game.InitializeFrom(null);

            // assert
            AssertExtension.Throws <ArgumentNullException>(action);
        }
Example #2
0
        public void StepForward_GivenEventHandlerIsAttached_CallsHandler()
        {
            // arrange
            var mockRules = new Mock <RulesBase>(new[] { 1 }, new[] { 2 });
            var game      = new LinqGame(mockRules.Object);

            int numberOfTimesCalled = 0;

            game.GameStepEvent += (sender, args) => { ++numberOfTimesCalled; };

            // act
            game.StepForward();

            // assert
            Assert.AreEqual(1, numberOfTimesCalled);
        }
Example #3
0
        public void InitializeFrom_GivenPattern_InitializesGameCorrectly()
        {
            // arrange
            var mockRules = new Mock <RulesBase>(new[] { 1 }, new[] { 2 });
            var game      = new LinqGame(mockRules.Object);
            var pattern   = new FivePoint();

            // act
            game.InitializeFrom(pattern.GetPattern());

            // assert
            Assert.AreEqual(
                expected: 5,
                actual: game.Population,
                message: "The universe population was not initialized correctly.");
        }
        public void StepForward_GivenEmptyUniverse_ResultsInEmptyUniverse()
        {
            // arrange
            var game = new LinqGame(new StandardRules());

            // act
            game.StepForward();

            // assert
            Assert.AreEqual(
                expected: 0,
                actual: game.Population,
                message: "The universe is not empty.");

            Assert.AreEqual(
                expected: 1,
                actual: game.Generation,
                message: "The game did not progress by one generation.");
        }
Example #5
0
        public void Constructor_WhenInvoked_PreparesLinqGameCorrectly()
        {
            // arrange
            var mockRules = new Mock <RulesBase>(new[] { 1 }, new[] { 2 });

            // act
            var game = new LinqGame(mockRules.Object);

            // assert
            Assert.AreEqual(
                expected: 0,
                actual: game.Population,
                message: "The initial population was not exactly zero.");

            Assert.AreEqual(
                expected: 0,
                actual: game.Generation,
                message: "The game did not start at generation zero.");
        }
        public void StepForward_GivenFivePointAndEventHandler_ResultsInPopulationOfFourAndFiveRemoved()
        {
            // arrange
            var pattern = new FivePoint();
            var game    = new LinqGame(new StandardRules());

            object            sender    = null;
            GameStepEventArgs eventArgs = null;
            EventHandler <GameStepEventArgs> handler = (object s, GameStepEventArgs e) =>
            {
                sender    = s;
                eventArgs = e;
            };

            game.InitializeFrom(pattern.GetPattern());
            game.GameStepEvent += handler;

            // act
            game.StepForward();

            // assert
            Assert.AreEqual(
                expected: 4,
                actual: game.Population,
                message: "The universe does not contain exactly 4 cells.");

            Assert.AreSame(
                expected: game,
                actual: sender,
                message: "Incorrect sender reference in event handler.");

            Assert.AreEqual(
                expected: 5,
                actual: eventArgs.DeadCells.Count(),
                message: "The set of removed cells does not contain exactly 5 cells.");

            Assert.AreEqual(
                expected: 4,
                actual: eventArgs.NewCells.Count(),
                message: "The set of added cells does not contain exactly 4 cells.");
        }
        public void StepForward_GivenFivePoint_ResultsInPopulationOfFour()
        {
            // arrange
            var pattern = new FivePoint();
            var game    = new LinqGame(new StandardRules());

            game.InitializeFrom(pattern.GetPattern());

            // act
            game.StepForward();

            // assert
            Assert.AreEqual(
                expected: 4,
                actual: game.Population,
                message: "The universe does not contain exactly 4 cells.");

            Assert.AreEqual(
                expected: 1,
                actual: game.Generation,
                message: "The game did not progress by one generation.");
        }
Example #8
0
	private void detach_LinqGames(LinqGame entity)
	{
		this.SendPropertyChanging();
		entity.User = null;
	}
Example #9
0
	private void attach_LinqGames(LinqGame entity)
	{
		this.SendPropertyChanging();
		entity.User = this;
	}
Example #10
0
 partial void DeleteLinqGame(LinqGame instance);
Example #11
0
 partial void UpdateLinqGame(LinqGame instance);
Example #12
0
 partial void InsertLinqGame(LinqGame instance);