public static IAutomaton CreateSpaceship(ICellLifeService cellLifeService = null) { const int width = 10; const int height = 10; if (cellLifeService == null) { cellLifeService = Mock.Of <ICellLifeService>(); } var automaton = new Automaton(width, height, cellLifeService, Mock.Of <ILogger>()); var pointList = new[] { // Lightweight spaceship new Point(1, 1), new Point(4, 1), new Point(5, 2), new Point(1, 3), new Point(5, 3), new Point(2, 4), new Point(3, 4), new Point(4, 4), new Point(5, 4), }; var statistics = new Statistics(); automaton.SetPoints(pointList, ref statistics); return(automaton); }
public void CellLifeService_ShouldThrow_ExceptionOnNullLifePreset() { ICellLifeService lifeCellService = null; ILifePreset lifePreset = null; var message = $"Value cannot be null.{Environment.NewLine}Parameter name: {nameof(lifePreset)}"; //var message = $"Exception of type 'System.ArgumentNullException' was thrown.{Environment.NewLine}Parameter name: {nameof(lifePreset)}"; var exception = Record.Exception(() => lifeCellService = new MooreCellLifeService(lifePreset)); lifeCellService.Should().BeNull(); exception.Should().NotBeNull(); exception.Message.Should().Be(message); }
public void Automaton_ShouldThrow_ExceptionOnNullService() { const int width = 4; const int height = 7; ICellLifeService cellLifeService = null; //var message = $"Exception of type 'System.ArgumentNullException' was thrown.{Environment.NewLine}Parameter name: {nameof(cellLifeService)}"; var message = $"Value cannot be null.{Environment.NewLine}Parameter name: {nameof(cellLifeService)}"; IAutomaton automaton = null; var exception = Record.Exception(() => automaton = new Automaton(width, height, cellLifeService, Mock.Of <ILogger>())); // checks automaton.Should().BeNull(); exception.Should().NotBeNull(); exception.Message.Should().Be(message); }
public Automaton(Size size, ICellLifeService cellLifeService, ILogger logger) { size.ThrowIfNull(nameof(size)); if (size.Width < 5) { //throw new ArgumentOutOfRangeException(nameof(Size), size.Width, "Width of automaton should be more than 3"); logger.Log($"{nameof(size.Width)} of automaton should be more than 5"); } if (size.Height < 5) { //throw new ArgumentOutOfRangeException(nameof(Size), size.Height, "Height of automaton should be more than 3"); logger.Log($"{nameof(size.Height)} of automaton should be more than 5"); } cellLifeService.ThrowIfNull(nameof(cellLifeService)); CellLifeService = cellLifeService; logger.ThrowIfNull(nameof(logger)); _logger = logger; Size = new Size(System.Math.Max(size.Width, 5), System.Math.Max(size.Height, 5)); CellSet = new CellSet(); Init(); }
public AutomatonViewModel( ICellLifeService cellLifeService, ISettings settings, IChartRepository chartRepository, ICommandProvider automatonCommandProvider, ILogger logger) { settings.ThrowIfNull(nameof(settings)); Settings = settings; chartRepository.ThrowIfNull(nameof(chartRepository)); _chartRepository = chartRepository; automatonCommandProvider.ThrowIfNull(nameof(automatonCommandProvider)); logger.ThrowIfNull(nameof(logger)); _logger = logger; cellLifeService.ThrowIfNull(nameof(cellLifeService)); CellLifeService = cellLifeService; CellLifeService.LifePreset = KnownLifePresets.GetKnownLifePreset(Settings.KnownLifePreset); _resizeTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100), }; _resizeTimer.Tick += ResizeTimerTick; _iterateTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(Settings.IterationDelay), }; _iterateTimer.Tick += IterateTimerTick; _logger.Log("AutomatonViewModel constructor is completed"); Application.Current.MainWindow.Closing += new CancelEventHandler(MainWindow_Closing); // create commands IterateCommand = new DelegateCommand(Iterate, () => CanIterate) { IsActive = IsActive }; StartIteratingCommand = new DelegateCommand(StartTimer, () => CanStartIterating) { IsActive = IsActive }; StopIteratingCommand = new DelegateCommand(StopTimer, () => CanStopIterating) { IsActive = IsActive }; RestartCommand = new DelegateCommand(SetInitialAutomaton, () => CanRestart) { IsActive = IsActive }; automatonCommandProvider.IterateCommand.RegisterCommand(IterateCommand); automatonCommandProvider.StartIteratingCommand.RegisterCommand(StartIteratingCommand); automatonCommandProvider.StopIteratingCommand.RegisterCommand(StopIteratingCommand); automatonCommandProvider.RestartCommand.RegisterCommand(RestartCommand); SetAutomatonCommandProviderMode(AutomatonCommandProviderMode.None); }
public Automaton(int width, int height, ICellLifeService cellLifeService, ILogger logger) : this(new Size(width, height), cellLifeService, logger) { }