Beispiel #1
0
 private void LoadData(string path, bool doubleSolve = false)
 {
     GridHelpers.ResetCache();
     _grid   = new PicrossGrid(path, GridInitializerEnum.ImageFilePath);
     _solver = new PicrossSolver(_grid.RowCount, _grid.ColumnCount, _grid.Rows, _grid.Columns);
     _solver.Solve();
     if (doubleSolve)
     {
         _solver.Solve();
     }
     Rows = new List <RowPresenter>();
     for (int i = 0; i < _grid.RowCount; i++)
     {
         Rows.Add(new RowPresenter(_solver.WorkingGrid.GetRow(i)));
     }
     Notify(() => Rows);
     RowClassifiers    = _solver.Rows.Select(r => new ClassifierPresenter(r)).ToList();
     ColumnClassifiers = _solver.Columns.Select(c => new ClassifierPresenter(c)).ToList();
 }
Beispiel #2
0
        protected void Run(bool doubleSolve = false)
        {
            var errorSb            = new StringBuilder();
            var errorLevels        = new List <string>();
            var inconclusiveLevels = new List <string>();
            var inconclusiveSb     = new StringBuilder();

            foreach (var level in Levels)
            {
                GridHelpers.ResetCache();
                var levelName   = level.Identifier;
                var initializer = level.Initializer;
                var step        = Step.Setup;
                try {
                    Setup(initializer);
                    step = Step.ManualSetup;
                    if (ManualSetup != null)
                    {
                        ManualSetup();
                    }
                    step = Step.Solve;
                    Solver.Solve();
                    if (doubleSolve)
                    {
                        Solver.Solve();
                    }
                    step = Step.Assert;
                    AssertMatrix();
                } catch (Exception ex) {
                    if (ex.Message.Contains("Invalid color!"))
                    {
                        inconclusiveLevels.Add(levelName);
                        AppendLog(inconclusiveSb, ex, step, level);
                    }
                    else
                    {
                        errorLevels.Add(levelName);
                        AppendLog(errorSb, ex, step, level);
                    }
                }
            }
            var totalOutput = Environment.NewLine;

            if (errorSb.Length != 0)
            {
                totalOutput += string.Format("Number of failing levels: {0}{1}", errorLevels.Count, Environment.NewLine);
                errorSb.AppendLine(HorizontalSplitter);
            }
            if (inconclusiveSb.Length != 0)
            {
                totalOutput += string.Format("Number of inconclusive levels: {0}{1}", inconclusiveLevels.Count, Environment.NewLine);
                inconclusiveSb.AppendLine(HorizontalSplitter);
            }
            totalOutput += HorizontalSplitter + errorSb + inconclusiveSb;
            if (errorLevels.Any())
            {
                Assert.Fail(totalOutput);
            }
            if (inconclusiveLevels.Any())
            {
                Assert.Inconclusive(totalOutput);
            }
        }