public void Stack()
        {
            Stack <string> q = new Stack <string>();

            q.Push("test1");
            q.Push("test2");
            StackClass a = new StackClass()
            {
                Strings = q,
            };

            XmlDocument target = new XmlDocument();

            Serializer.Serialize((SystemXmlAdapter)target, a);

            Assert.AreEqual(1, target.DocumentElement.ChildNodes.Count);

            StackClass b = Deserializer.Deserialize <StackClass>((SystemXmlAdapter)target);

            while (true)
            {
                bool emptyA = a.Strings.Count == 0;
                bool emptyB = b.Strings.Count == 0;

                Assert.AreEqual(emptyA, emptyB);
                if (emptyA)
                {
                    break;
                }

                Assert.AreEqual(a.Strings.Pop(), b.Strings.Pop());
            }
        }
Example #2
0
    /// <summary>
    /// 向堆栈记录里面,添加一条操作,每次添加一条记录后,就不能执行恢复操作了,恢复按钮需要灰态不可点击
    /// </summary>
    /// <param name="stackType">Stack type.</param>
    /// <param name="go">Go.</param>
    /// <param name="previousPosition">Previous position.</param>
    public void AddStack(StackType stackType, GameObject go, Vector3 previousPosition = default(Vector3))
    {
        StackClass stackClass = new StackClass();

        stackClass.gameObject = go;
        stackClass.stackType  = stackType;
        //struct数据类型的默认值,通过Default进行给默认值
        stackClass.previousPosition = previousPosition;
        //如果堆栈中存在对应索引的数值,那么覆盖过去
        if (stack.Count > stackIndex)
        {
            Destroy(stack[stackIndex].gameObject);
            stack[stackIndex] = stackClass;
        }
        else
        {
            //否则就添加
            stack.Add(stackClass);
        }

        stackIndex++;
        print("当前索引为:" + stackIndex);

        //每次添加操作记录后,恢复按钮都不可点击
        Container.RedoButton.interactable = false;
        Container.UndoButton.interactable = true;
    }
Example #3
0
        public void Stack()
        {
            Stack <string> q = new Stack <string>();

            q.Push("test1");
            q.Push("test2");
            StackClass a = new StackClass()
            {
                Strings = q,
            };

            JObject target = new JObject();

            Serializer.Serialize((NewtonsoftJsonAdapter)target, a);

            AssertChildren(3, target);

            StackClass b = Deserializer.Deserialize <StackClass>((NewtonsoftJsonAdapter)target);

            while (true)
            {
                bool emptyA = a.Strings.Count == 0;
                bool emptyB = b.Strings.Count == 0;

                Assert.AreEqual(emptyA, emptyB);
                if (emptyA)
                {
                    break;
                }

                Assert.AreEqual(a.Strings.Pop(), b.Strings.Pop());
            }
        }
Example #4
0
    private static void GetStack(StackClass <int> stackClass)
    {
        string input = string.Empty;

        while ((input = Console.ReadLine()) != "END")
        {
            string[] commandOfArgs = input.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
            string   command       = commandOfArgs[0];

            try
            {
                switch (command)
                {
                case "Pop":
                    stackClass.Pop();
                    break;

                case "Push":
                    int[] elements = commandOfArgs
                                     .Skip(1)
                                     .Select(int.Parse)
                                     .ToArray();
                    stackClass.Push(elements);
                    break;

                default:
                    break;
                }
            }
            catch (ArgumentException ArgEx)
            {
                Console.WriteLine(ArgEx.Message);
            }
        }
    }
Example #5
0
        public void PushOne()
        {
            StackClass myStack = new StackClass();

            myStack.Push("my first element");
            Assert.IsFalse(myStack.IsEmpty, "IsEmpty muss falsch sein");
        }
Example #6
0
    /// <summary>
    /// 撤销实现函数,将需要
    /// </summary>
    /// <param name="stackClass">操作实体类型</param>
    private void Undo(StackClass stackClass)
    {
        //根据类型进行反向操作
        switch (stackClass.stackType)
        {
        case StackType.Create:
            //如果撤销的试创建物体的操作,那么就删除这个物体,不进行删除,而是进行隐藏
            //Destroy(stackClass.gameObject);
            stackClass.gameObject.SetActive(false);
            break;

        case StackType.Move:
            //如果是移动,那么撤销后需要获取到上一个物体的位置
            stackClass.gameObject.transform.position = stackClass.previousPosition;
            break;

        case StackType.Delete:
            //如果是撤销删除,那么就在原本的位置生成出来,

            break;
        }
        //操作索引减少
        stackIndex--;
        //只有撤销操作后,才可以点击恢复按钮
        Container.RedoButton.interactable = true;
    }
Example #7
0
        static void Main(string[] args)
        {//معرفی ثوابت
            int andis_ofint = 0, andis_ofstring = 0, andis_ofclass = 0;

            //معرفی ارایه جهت استک اینت
            int[] arrayint = null;
            //معرفی ارایه جهت استک استرینگ
            string[] arraystring = null;
            //ساخت کلاس و ارایه جهت استک کلاس
            StackClass c = new StackClass();
            StackClass d = new StackClass();

            StackClass[] arrayclass = null;
            //ساخت کلاس جهت رفتارهای مرتبط با استک
            StackGenericeClass a = new StackGenericeClass();

            //int
            arrayint = a.Push(4, ref andis_ofint, arrayint);
            arrayint = a.Push(7, ref andis_ofint, arrayint);
            arrayint = a.Pop(ref andis_ofint, arrayint);
            int peckint = a.Peck(arrayint, andis_ofint);

            //string
            arraystring = a.Push("ali", ref andis_ofstring, arraystring);
            arraystring = a.Push("reza", ref andis_ofstring, arraystring);
            arraystring = a.Pop(ref andis_ofstring, arraystring);
            string peckstring = a.Peck(arraystring, andis_ofint);

            //class
            arrayclass = a.Push(c, ref andis_ofclass, arrayclass);
            arrayclass = a.Push(d, ref andis_ofclass, arrayclass);
            arrayclass = a.Pop(ref andis_ofclass, arrayclass);
            StackClass peckclass = a.Peck(arrayclass, andis_ofclass);
        }
Example #8
0
        public void PopOne()
        {
            StackClass myStack = new StackClass();

            myStack.Push("my first element");
            myStack.Pop();
            Assert.IsTrue(myStack.IsEmpty);
        }
Example #9
0
        public void CanPushOntoStack()
        {
            StackClass <int> stack = new StackClass <int>();
            Node <int>       node  = new Node <int>();

            node.Value = 5;
            stack.Push(node.Value);
            Assert.Equal(5, stack.Top.Value);
        }
Example #10
0
    static void Main()
    {
        StackClass <int> stackClass = new StackClass <int>();

        GetStack(stackClass);

        PrintStack(stackClass);
        PrintStack(stackClass);
    }
Example #11
0
 public void PopTest()
 {
     StackClass stack = new StackClass();
     stack.Pop(56);
     stack.Push(4);
     stack.Pop(4);
     Assert.IsTrue(stack.IsEmpty());
     stack.Push(4);
     stack.Pop(48);
 }
Example #12
0
        public static void RunPushMethod()
        {
            StackClass <int> stack = new StackClass <int>();

            Console.WriteLine("Choose a number to push to stack");
            int input1 = Convert.ToInt32(Console.ReadLine());



            stack.Push(input1);

            Console.WriteLine(stack.Peek());
        }
Example #13
0
        // [Fact]
        public void CanPeek()
        {
            StackClass <int> stack = new StackClass <int>();
            Node <int>       node  = new Node <int>();

            node.Value = 5;
            stack.Push(node.Value);
            Node <int> node2 = new Node <int>();

            node.Value = 15;
            stack.Push(node.Value);
            var output = stack.Peek();
        }
Example #14
0
    private static void PrintStack(StackClass <int> stackClass)
    {
        StringBuilder sb = new StringBuilder();

        foreach (var element in stackClass)
        {
            sb.AppendLine(element.ToString());
        }

        if (sb.ToString().Trim() != string.Empty)
        {
            Console.WriteLine(sb.ToString().TrimEnd());
        }
    }
Example #15
0
        static void Stack()
        {
            var _stack = new StackClass();

            int ini = 1;
            int max = 5;

            for (int i = ini; i <= max; i++)
            {
                _stack.Push(i);
            }
            _stack.Clear();
            for (int i = ini; i <= max; i++)
            {
                Console.WriteLine(_stack.Pop());
            }
        }
Example #16
0
        public void CanPushMultipleNodes()
        {
            StackClass <int> stack = new StackClass <int>();
            Node <int>       node  = new Node <int>();

            node.Value = 5;
            stack.Push(node.Value);
            Node <int> node2 = new Node <int>();

            node.Value = 15;
            stack.Push(node.Value);
            Node <int> node3 = new Node <int>();

            node.Value = 22;
            stack.Push(node.Value);
            Assert.Equal(22, stack.Top.Value);
        }
Example #17
0
        public void CanPopOffStack()
        {
            StackClass <int> stack = new StackClass <int>();
            Node <int>       node  = new Node <int>();

            node.Value = 5;
            stack.Push(node.Value);
            Node <int> node2 = new Node <int>();

            node.Value = 15;
            stack.Push(node.Value);
            Node <int> node3 = new Node <int>();

            node.Value = 22;
            stack.Push(node.Value);
            stack.Pop();
            Assert.Equal(15, stack.Top.Value);
        }
Example #18
0
        public void Push_Integer()
        {
            // Arrange
            int[] startingStack = { 1, 2, 3, 4 };
            int   theInteger    = 111;

            int[]      expected = { 1, 2, 3, 4, 111 };
            StackClass sc       = new StackClass(startingStack);

            // Act
            sc.Push(theInteger);

            // Assert
            int[] actual = sc.Stack;
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i], "The stack is not pushed correctly");
            }
        }
Example #19
0
    private void Redo(StackClass stackClass)
    {
        //根据类型进行重新实现
        switch (stackClass.stackType)
        {
        case StackType.Create:
            //如果是创建物体的操作,
            //Instantiate(stackClass.gameObject, stackClass.gameObject.transform.position, stackClass.gameObject.transform.rotation);
            stackClass.gameObject.SetActive(true);
            break;

        case StackType.Move:
            //如果是移动
            stackClass.gameObject.transform.position = stackClass.gameObject.transform.position;
            break;

        case StackType.Delete:
            //如果是恢复删除,那么就摧毁这个物体

            break;
        }
        //操作索引+1
        stackIndex++;
    }
Example #20
0
        public void CanEmptyStack()
        {
            StackClass <int> stack = new StackClass <int>();
            Node <int>       node  = new Node <int>();

            node.Value = 5;
            stack.Push(node.Value);
            Node <int> node2 = new Node <int>();

            node.Value = 15;
            stack.Push(node.Value);
            Node <int> node3 = new Node <int>();

            node.Value = 22;
            stack.Push(node.Value);
            while (node.Next != null)
            {
                stack.Pop();
            }
            stack.Pop();
            var result = stack.Peek();

            Assert.Null(result);
        }
Example #21
0
        public void IsEmptyIsTrue()
        {
            StackClass myStack = new StackClass();

            Assert.IsTrue(myStack.IsEmpty);
        }
Example #22
0
 public void Init()
 {
     StackClass myStack = new StackClass();
 }
Example #23
0
 public void PushTest()
 {
     StackClass stack = new StackClass();
     stack.Push(7);
     Assert.IsFalse(stack.IsEmpty());
 }
Example #24
0
 public void PrintTest()
 {
     StackClass stack = new StackClass();
     stack.Print();
 }