示例#1
0
        public void TestSimpleJeweled()
        {
            const string path     = @"..\..\..\..\..\TestCases\TestSimpleJeweled.xlsx";
            var          fullPath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, path);

            ExcelLoader.LoadAndRun(fullPath);
        }
示例#2
0
        public static void LoadAndRun(string file)
        {
            file = file.Replace("/", "" + Path.DirectorySeparatorChar).Replace("\\", "" + Path.DirectorySeparatorChar);
            var el      = new ExcelLoader(file);
            var initial = el.GenerateInitial();

            var pf       = initial.Playfield;
            var dp       = initial.DropPiece;
            var prevTime = initial.Timeline;

            pf.Timeline.PositionAbs = initial.Timeline * pf.Timeline.NumColumns;

            foreach (var c in pf.GetEnumeratorCells())
            {
                c.Transferred += (sender, e) =>
                {
                    Assert.IsTrue(e.Cell.IsOccupied);
                    Assert.IsFalse((sender as Cell).IsOccupied);
                };
            }

            foreach (var v in el)
            {
                if (v.Stats.DebuggerBreak)
                {
                    System.Diagnostics.Debugger.Break();
                }

                // update playfield:
                pf.Timeline.IncrementPosition(v.Timeline - prevTime);

                string cellStateActual   = pf.PrintCells("\t");
                string cellStateExpected = v.Playfield.PrintCells("\t");

                string msgCells = $"Cells aren't equal at time step {v.Timeline}, column ${pf.Timeline}.{Environment.NewLine}";

                msgCells += "Expected State:" + Environment.NewLine;
                msgCells += cellStateExpected + Environment.NewLine;
                msgCells += "Actual State:" + Environment.NewLine;
                msgCells += cellStateActual + Environment.NewLine;

                Assert.IsTrue(pf.GetEnumeratorCells().SequenceEqual(v.Playfield.GetEnumeratorCells()), msgCells);
                Assert.IsTrue(pf.GetEnumeratorSquares().SequenceEqual(v.Playfield.GetEnumeratorSquares()), $"Squares aren't equal at time step {v.Timeline}");

                string timeMsg = $"At time {v.Timeline}, ";

                // check drop piece:
                if (v.DropPiece != null && dp != null)
                {
                    dp.Update(TimeSpan.FromSeconds(v.Timeline - prevTime),
                              DropPiece.MoveDirection.None,
                              (c, r, i) => c >= 0 && c < pf.NumCellColumns, (md) => { },
                              (p) => p.Row >= pf.NumCellRows || pf.GetCell(p).IsOccupied,
                              (p, s) => pf.GetCell(p).State = s);


                    if (dp.CurrentState == DropPiece.State.Whole || dp.CurrentState == DropPiece.State.SplitLeft)
                    {
                        Assert.AreEqual(v.DropPiece.Cells[0][0], dp.Cells[0][0], $"{timeMsg} Cell doesn't match");
                        Assert.AreEqual(v.DropPiece.Cells[0][1], dp.Cells[0][1], $"{timeMsg} Cell doesn't match");
                    }
                    if (dp.CurrentState == DropPiece.State.Whole || dp.CurrentState == DropPiece.State.SplitRight)
                    {
                        Assert.AreEqual(v.DropPiece.Cells[1][0], dp.Cells[1][0], $"{timeMsg} Cell doesn't match");
                        Assert.AreEqual(v.DropPiece.Cells[1][1], dp.Cells[1][1], $"{timeMsg} Cell doesn't match");
                    }

                    Assert.AreEqual(2, dp.Positions.Length);
                    if (dp.CurrentState == DropPiece.State.Whole || dp.CurrentState == DropPiece.State.SplitLeft)
                    {
                        Assert.AreEqual(v.DropPiece.Positions[0], dp.Positions[0], $"{timeMsg} Positions don't match");
                    }
                    if (dp.CurrentState == DropPiece.State.Whole || dp.CurrentState == DropPiece.State.SplitRight)
                    {
                        Assert.AreEqual(v.DropPiece.Positions[1], dp.Positions[1], $"{timeMsg} Positions don't match");
                    }
                }

                // check stats info:
                StatsInfo si = v.Stats;
                si.CheckStat(si.Frame, pf.Stats.Frame, $"{timeMsg} Frame doesn't match");
                si.CheckStat(si.FrameSquaresRemoved, pf.Stats.FrameSquaresRemoved, $"{timeMsg} FrameSquaresRemoved doesn't match");
                si.CheckStat(si.NumPrevBonuses, pf.Stats.NumPrevBonuses, $"{timeMsg} NumPrevBonuses doesn't match");
                si.CheckStat(si.TotalSquaresRemoved, pf.Stats.TotalSquaresRemoved, $"{timeMsg} TotalSquaresRemoved doesn't match");
                si.CheckStat(si.TotalSquaresBonuses, pf.Stats.TotalSquaresBonuses, $"{timeMsg} TotalSquaresBonuses doesn't match");
                si.CheckStat(si.TotalNumSingleColorBonuses, pf.Stats.TotalNumSingleColorBonuses, $"{timeMsg} TotalNumSingleColorBonuses doesn't match");
                si.CheckStat(si.TotalNumEmptyColorBonuses, pf.Stats.TotalNumEmptyColorBonuses, $"{timeMsg} TotalNumEmptyColorBonuses doesn't match");

                prevTime += v.Timeline - prevTime;
            }
        }