Exemplo n.º 1
0
        public void Run()
        {
            MaxStack<int> stack = new MaxStack<int>();
            string command = null;
            Console.Write("Enter a command:");
            while (!string.IsNullOrEmpty(command = Console.ReadLine()))
            {
                string[] tokens = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                try
                {
                    if (tokens[0] == "p")
                    {
                        stack.Push(int.Parse(tokens[1]));
                    }
                    else if (tokens[0] == "x")
                    {
                        if (stack.Count == 0) Console.WriteLine("Stack empty");
                        else Console.WriteLine("Popped {0}", stack.Pop());
                    }
                    else if (tokens[0] == "m")
                    {
                        if (stack.Count == 0) Console.WriteLine("Stack empty");
                        else Console.WriteLine("Max is {0}", stack.Max);
                    }
                }
                catch(Exception)
                {
                    Console.WriteLine("Bad Command");
                }
                Console.Write("Enter a command:");
            }
        }
        public void GetMaxFromStack()
        {
            //[6] => getMax() => 6
            //[6, 10] => getMax() => 10
            //[6, 10, 10] => getMax() => 10
            //[6, 10, 10, 4] => getMax() => 10

            var stack = new MaxStack();

            stack.Push(6);
            var max = stack.GetMax();

            Assert.AreEqual(max, 6);
            stack.Push(10);
            max = stack.GetMax();
            Assert.AreEqual(max, 10);
            stack.Push(10);
            max = stack.GetMax();
            Assert.AreEqual(max, 10);
            stack.Push(4);
            max = stack.GetMax();
            Assert.AreEqual(max, 10);
            stack.Pop();
            max = stack.GetMax();
            Assert.AreEqual(max, 10);
            stack.Pop();
            max = stack.GetMax();
            Assert.AreEqual(max, 10);
            stack.Pop();
            max = stack.GetMax();
            Assert.AreEqual(max, 6);
        }
Exemplo n.º 3
0
        public void Max_WhenCalled_Returns_Maximum_Value()
        {
            var stack = new MaxStack <int>();

            var list = new List <int> {
                1, 8, 44, 44, 3, 9, 2, 20, 12, 10, 4, 50, -70, 100, 99, 0, 8, 45
            };

            var max = list[0];

            for (var i = 0; i < list.Count; i++)
            {
                if (list[i] > max)
                {
                    max = list[i];
                }

                stack.Push(list[i]);
                Assert.AreEqual(max, stack.Max());
            }

            for (var i = list.Count - 1; i >= 0; i--)
            {
                Assert.AreEqual(list.Max(), stack.Max());

                stack.Pop();
                list.RemoveAt(i);
            }
        }
Exemplo n.º 4
0
    // Use this for initialization
    public virtual void Initialize(MacroAIParty party, Faction faction)
    {
        RunningNodeHist = new MaxStack <string>(20);

        AimSkill                     = UnityEngine.Random.Range(0.6f, 1f);
        MyShip                       = transform.GetComponent <ShipBase>();
        AvoidanceDetector            = MyShip.MyReference.AvoidanceDetector;
        AvoidanceDetector.ParentShip = MyShip;

        Whiteboard = new Whiteboard();
        Whiteboard.Initialize();

        //AttackTarget = GameManager.Inst.PlayerControl.PlayerShip;

        //Whiteboard.Parameters["TargetEnemy"] = AttackTarget;
        Whiteboard.Parameters["SpeedLimit"] = -1f;

        MyParty       = party;
        MyFaction     = faction;
        MyPartyNumber = MyParty.PartyNumber;

        WeaponControl = new AIWeaponControl();
        WeaponControl.Initialize(this);

        TreeSet = new Dictionary <string, BehaviorTree>();
        TreeSet.Add("BaseBehavior", GameManager.Inst.DBManager.XMLParserBT.LoadBehaviorTree("BaseBehavior", this, party));
        TreeSet.Add("Travel", GameManager.Inst.DBManager.XMLParserBT.LoadBehaviorTree("Travel", this, party));
        TreeSet.Add("FollowFriendly", GameManager.Inst.DBManager.XMLParserBT.LoadBehaviorTree("FollowFriendly", this, party));
        TreeSet.Add("FighterCombat", GameManager.Inst.DBManager.XMLParserBT.LoadBehaviorTree("FighterCombat", this, party));
        TreeSet.Add("BigShipCombat", GameManager.Inst.DBManager.XMLParserBT.LoadBehaviorTree("BigShipCombat", this, party));
    }
Exemplo n.º 5
0
        public void Shrink_GivesCorrectNewSize()
        {
            var ms = new MaxStack <string>(10);

            ms.Shrink(0.5f);
            Assert.AreEqual(5, ms.MaxSize);
        }
Exemplo n.º 6
0
        public void Grow_GivesCorrectNewSize()
        {
            var ms = new MaxStack <string>(10);

            ms.Grow(0.5f);
            Assert.AreEqual(15, ms.MaxSize);
        }
Exemplo n.º 7
0
        public void Peek_WhenEmpty_returnDefault()
        {
            var ms1 = new MaxStack <int>(5);

            Assert.AreEqual(0, ms1.Peek());
            var ms2 = new MaxStack <string>(5);

            Assert.IsNull(ms2.Peek());
        }
Exemplo n.º 8
0
        public void Push_Pop_CorrectItem()
        {
            var ms = new MaxStack <int>(5);

            ms.Push(1);
            ms.Push(2);
            ms.Push(3);
            Assert.AreEqual(3, ms.Pop());
        }
Exemplo n.º 9
0
        public void MaxStack_NothingInStack_Pop_ThrowsException()
        {
            // Arrange
            MaxStack maxStack = new MaxStack();
            // Act
            Action action = () => maxStack.Pop();

            // Assert
            Assert.ThrowsException <EmptyStackException>(action, stackEmptyMessage);
        }
Exemplo n.º 10
0
 public MapGrid(Map map_0)
 {
     Class13.lOBHd9Nzn7x2T();
     this._lock = new object();
     base..ctor();
     this.Map       = map_0;
     this.ScaleX    = 100;
     this.ScaleY    = 50;
     this.PathCache = new MaxStack <PathSequence>(32);
     this.method_11();
 }
Exemplo n.º 11
0
        public void PushMoreThenMax_ExcessIsLost()
        {
            var ms = new MaxStack <string>(2);

            ms.Push("1");
            ms.Push("2");
            ms.Push("3");
            Assert.AreEqual("3", ms.Pop());
            Assert.AreEqual("2", ms.Pop());
            Assert.IsNull(ms.Peek());
        }
Exemplo n.º 12
0
 public MapGrid(Map map_0)
 {
     Class13.NP5bWyNzLwONS();
     this._lock = new object();
     base..ctor();
     this.Map       = map_0;
     this.ScaleX    = 100;
     this.ScaleY    = 50;
     this.PathCache = new MaxStack <PathSequence>(32);
     this.method_10();
 }
Exemplo n.º 13
0
        public void Contains_givesCorrectResult()
        {
            var ms = new MaxStack <string>(2);

            ms.Push("1");
            ms.Push("2");
            ms.Push("3");
            Assert.IsTrue(ms.Contains("3"));
            Assert.IsTrue(ms.Contains("2"));
            Assert.IsFalse(ms.Contains("1"));
        }
Exemplo n.º 14
0
        public void SetSize_ExcessIsLost()
        {
            var ms = new MaxStack <int>(4);

            ms.Push(1);
            ms.Push(2);
            ms.Push(3);
            ms.Push(4);
            ms.MaxSize = 1;
            Assert.AreEqual(1, ms.MaxSize);
            Assert.AreEqual(4, ms.Pop());
        }
Exemplo n.º 15
0
        public void Grow_AddSpaceAtEnd()
        {
            var ms = new MaxStack <int>(2);

            ms.Push(1);
            ms.Push(2);
            ms.Grow(0.5f);
            Assert.AreEqual(3, ms.MaxSize);
            Assert.AreEqual(2, ms.Pop());
            Assert.AreEqual(1, ms.Pop());
            Assert.AreEqual(0, ms.Peek());
        }
Exemplo n.º 16
0
        public void RemoveItem_GivesCorrectSequence()
        {
            var ms = new MaxStack <string>(3);

            ms.Push("1");
            ms.Push("2");
            ms.Push("3");
            ms.Remove("2");
            Assert.AreEqual("3", ms.Pop());
            Assert.AreEqual("1", ms.Pop());
            Assert.IsNull(ms.Peek());
        }
Exemplo n.º 17
0
        protected override void Run()
        {
            MaxStack <int> stack = new MaxStack <int>();

            stack.Push(5);
            stack.Push(3);
            stack.Push(18);
            Console.WriteLine("Assert max = 18: {0}.", stack.Max() == 18);
            int value = stack.Pop();

            Console.WriteLine("Assert pop = 18: {0}.", value == 18);
            Console.WriteLine("Assert max = 5: {0}.", stack.Max() == 5);
        }
Exemplo n.º 18
0
        public void MaxStack_PushThreeIntegers_Pop_PopReturnsLast()
        {
            // Arrange
            int      expectedInt = 5;
            MaxStack maxStack    = new MaxStack();

            // Act
            maxStack.Push(1);
            maxStack.Push(-2);
            maxStack.Push(expectedInt);
            // Assert
            Assert.AreEqual(expectedInt, maxStack.Pop());
        }
Exemplo n.º 19
0
        public void Clear_removeAll()
        {
            var ms = new MaxStack <string>(3);

            ms.Push("1");
            ms.Push("2");
            ms.Push("3");
            ms.Clear();
            Assert.IsFalse(ms.Contains("3"));
            Assert.IsFalse(ms.Contains("2"));
            Assert.IsFalse(ms.Contains("1"));
            Assert.AreEqual(3, ms.MaxSize);
        }
Exemplo n.º 20
0
        public void Shrink_ExcessIsLost()
        {
            var ms = new MaxStack <int>(4);

            ms.Push(1);
            ms.Push(2);
            ms.Push(3);
            ms.Push(4);
            ms.Shrink(0.5f);
            Assert.AreEqual(2, ms.MaxSize);
            Assert.AreEqual(4, ms.Pop());
            Assert.AreEqual(3, ms.Pop());
            Assert.AreEqual(0, ms.Peek());
        }
Exemplo n.º 21
0
 public static void RunTests()
 {
     MaxStack stack = new MaxStack();
     stack.Push(5);
     stack.Push(0);
     stack.Push(-10);
     Console.WriteLine(stack.Max());
     stack.Push(12);
     Console.WriteLine(stack.Max());
     stack.Push(15);
     Console.WriteLine(stack.Max());
     stack.Pop();
     stack.Pop();
     Console.WriteLine(stack.Max());
 }
Exemplo n.º 22
0
        public override void Run(string[] args)
        {
            var ms = new MaxStack();

            ms.Push(2);
            ms.Push(3);
            ms.Push(6);
            ms.Push(1);
            ms.Push(5);
            ms.Push(4);
            Debug.Assert(() => ms.PeekMax(), 6);
            ms.PopMax();

            Debug.Assert(() => ms.PeekMax(), 5);
        }
Exemplo n.º 23
0
        public void MaxStackTest()
        {
            MaxStack ms = new MaxStack();

            ms.mPush(3);
            ms.mPush(11);
            ms.mPop();
            ms.mPush(4);
            ms.mPush(6);
            ms.mPop();
            ms.mPush(2);
            ms.mPop();

            Assert.Equal(ms.GetMax(), 4);
        }
Exemplo n.º 24
0
    public static void RunTests()
    {
        MaxStack stack = new MaxStack();

        stack.Push(5);
        stack.Push(0);
        stack.Push(-10);
        Console.WriteLine(stack.Max());
        stack.Push(12);
        Console.WriteLine(stack.Max());
        stack.Push(15);
        Console.WriteLine(stack.Max());
        stack.Pop();
        stack.Pop();
        Console.WriteLine(stack.Max());
    }
Exemplo n.º 25
0
        public void MaxStack()
        {
            MaxStack node = new MaxStack();

            node.Push(1);
            node.Push(5);
            node.Push(2);

            node.Push(10);

            node.Pop();

            int actual   = node.Max();
            int expected = 5;

            Assert.AreEqual(actual, expected);
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            var stack = new MaxStack();

            //stack.Push(5);
            stack.Push(1);
            stack.Push(5);
            stack.Push(3);
            stack.Top();
            stack.PopMax();
            stack.Top();
            stack.PeekMax();
            stack.Pop();
            stack.Top();

            Console.WriteLine();
        }
Exemplo n.º 27
0
        public void MaxStackTest()
        {
            var s = new MaxStack();

            s.Push(5);
            Assert.AreEqual(5, s.GetMax());
            s.Push(4);
            s.Push(7);
            s.Push(7);
            s.Push(8);
            Assert.AreEqual(8, s.GetMax());
            Assert.AreEqual(8, s.Pop());
            Assert.AreEqual(7, s.GetMax());
            Assert.AreEqual(7, s.Pop());
            Assert.AreEqual(7, s.GetMax());
            Assert.AreEqual(7, s.Pop());
            Assert.AreEqual(5, s.GetMax());
            Assert.AreEqual(4, s.Pop());
            Assert.AreEqual(5, s.GetMax());
        }
Exemplo n.º 28
0
    public override void Initialize(MacroAIParty party, Faction faction)
    {
        RunningNodeHist = new MaxStack <string>(20);
        MyShip          = transform.GetComponent <ShipBase>();


        Whiteboard = new Whiteboard();
        Whiteboard.Initialize();

        //AttackTarget = GameManager.Inst.PlayerControl.PlayerShip;

        //Whiteboard.Parameters["TargetEnemy"] = AttackTarget;
        Whiteboard.Parameters["SpeedLimit"] = -1f;

        MyParty   = party;
        MyFaction = faction;

        TreeSet = new Dictionary <string, BehaviorTree>();
        TreeSet.Add("BaseBehavior", GameManager.Inst.DBManager.XMLParserBT.LoadBehaviorTree("BaseBehavior", this, party));
        TreeSet.Add("APTravel", GameManager.Inst.DBManager.XMLParserBT.LoadBehaviorTree("APTravel", this, party));
        TreeSet.Add("FollowFriendly", GameManager.Inst.DBManager.XMLParserBT.LoadBehaviorTree("FollowFriendly", this, party));
    }
Exemplo n.º 29
0
 public MacroAIParty()
 {
     RunningNodeHist = new MaxStack <string>(20);
 }
Exemplo n.º 30
0
 /// <summary>
 /// Contructor
 /// </summary>
 /// <param name="stackSize">Tamaño del stack</param>
 public GridCaretaker(int stackSize)
 {
     this._stack = new MaxStack <GridMemento>(stackSize);
 }
Exemplo n.º 31
0
        public void MaxSize_CorrectValue()
        {
            var ms = new MaxStack <int>(2);

            Assert.AreEqual(2, ms.MaxSize);
        }
Exemplo n.º 32
0
        public void Pop_WhenEmpty_throwsInvalidOperationException()
        {
            var ms = new MaxStack <string>(5);

            ms.Pop();
        }