コード例 #1
0
        public void UndoTest()
        {
            // arrange
            var undoRedo = new UndoRedo();

            undoRedo.AddAction(1, 2, 3, 4, "manual");
            undoRedo.AddAction(5, 6, 7, 8, "manually");

            // act and assert
            Assert.AreEqual(2, undoRedo.UndoLength());
            Assert.AreEqual(0, undoRedo.RedoLength());

            var(row, column, oldValue, value, method, undoLength, redoLength) = undoRedo.Undo();
            Assert.AreEqual(5, row);
            Assert.AreEqual(6, column);
            Assert.AreEqual(7, oldValue);
            Assert.AreEqual(8, value);
            Assert.AreEqual("manually", method);
            Assert.AreEqual(1, undoLength);
            Assert.AreEqual(1, redoLength);

            (row, column, oldValue, value, method, undoLength, redoLength) = undoRedo.Undo();
            Assert.AreEqual(1, row);
            Assert.AreEqual(2, column);
            Assert.AreEqual(3, oldValue);
            Assert.AreEqual(4, value);
            Assert.AreEqual("manual", method);
            Assert.AreEqual(0, undoLength);
            Assert.AreEqual(2, redoLength);
        }
コード例 #2
0
        public void AddActionTest()
        {
            // arrange
            byte   row      = 1;
            byte   column   = 1;
            byte   oldValue = 0;
            byte   value    = 3;
            string method   = "manual";
            var    undoRedo = new UndoRedo();

            // act
            undoRedo.AddAction(row, column, oldValue, value, method);
            undoRedo.AddAction(2, 2, 0, 4, "manual");

            // assert
            Assert.AreEqual(2, undoRedo.UndoLength());
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: Zaamby/Mnogoygolniki
        public Form1()
        {
            InitializeComponent();
            g = pictureBox1.CreateGraphics();
            Shape strt = new Circle(Size.Width / 2, Size.Height / 2);

            tochka.Add(strt);
            pictureBox1.Invalidate();
            circleToolStripMenuItem.Checked = true;
            t[0]      = typeof(List <Circle>);
            t[1]      = typeof(List <Square>);
            t[2]      = typeof(List <Triangle>);
            formatter = new XmlSerializer(typeof(List <Shape>), t);
            saveFileDialog1.AddExtension = true;
            saveFileDialog1.DefaultExt   = ".mng";
            openFileDialog1.DefaultExt   = ".mng";
            openFileDialog1.Filter       = "Многоугольники(*.mng)|*.mng";
            undoredo = new UndoRedo(5);
            undoredo.AddAction(tochka, Shape.Getc, Shape.Getcout, Shape.Getr);
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: Zaamby/Mnogoygolniki
 private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right && tochka.Count > 0)
     {
         for (int i = 0; i < tochka.Count; i++)
         {
             if (tochka[i].Popali(e.X, e.Y) == true)
             {
                 del = i;
             }
         }
         if (del >= 0)
         {
             tochka.RemoveAt(del);
         }
         del = -1;
         pictureBox1.Invalidate();
         undoredo.AddAction(tochka, Shape.Getc, Shape.Getcout, Shape.Getr);
     }
 }