public void TrimExcess_Test_Method(int elements)
        {
            var g = new StosWTablicy <int>(elements);

            for (int i = 0; i < elements; ++i)
            {
                g.Push(i);
            }
            g.TrimExcess();
            Assert.AreEqual(elements, (int)Math.Floor(g.GetTabLength() * 0.9));
        }
Ejemplo n.º 2
0
        public void TrimExcessDlaPustegoStosu_Valid(int size)
        {
            var s = new StosWTablicy <int>(size);

            for (int i = 0; i < size; ++i)
            {
                s.Push(i);
            }
            s.TrimExcess();
            Assert.AreEqual(size, (int)Math.Floor(s.GetTabLength() * 0.9));
        }
Ejemplo n.º 3
0
        public void CzyTrimDziala()
        {
            StosWTablicy <char> stos = new StosWTablicy <char>(2);

            stos.Push('a');
            stos.Push('b');
            stos.Push('c');
            stos.Push('d');
            stos.Push('e');
            stos.TrimExcess();
            Assert.AreEqual(stos.Count, 5);
            Assert.AreEqual(stos[0], 'a');
            Assert.AreEqual(stos[1], 'b');
            Assert.AreEqual(stos[2], 'c');
            Assert.AreEqual(stos[3], 'd');
            Assert.AreEqual(stos[4], 'e');
        }
Ejemplo n.º 4
0
        public void StackTrimExcess(int index)
        {
            int expectedLength;

            if (index <= 5)
            {
                expectedLength = index + 1;
            }
            else
            {
                expectedLength = index + Convert.ToInt32((1d / 10d) * index);
            }
            var s = new StosWTablicy <int>();

            for (int i = 0; i < index; i++)
            {
                s.Push(1);
            }
            s.TrimExcess();
            Assert.AreEqual(expectedLength, s.Length());
        }
Ejemplo n.º 5
0
        public void TrimExcessTestMethod(int elements)
        {
            int expectedLength;

            if (elements <= 5)
            {
                expectedLength = elements + 1;
            }
            else
            {
                expectedLength = elements + Convert.ToInt32((1 / 10d) * elements);
            }
            var s = new StosWTablicy <int>();

            for (int i = 0; i < elements; i++)
            {
                s.Push(1);
            }
            s.TrimExcess();
            Assert.AreEqual(expectedLength, s.GetActualTabLength());
        }
        static void Main(string[] args)
        {
            StosWTablicy <string> s = new StosWTablicy <string>();

            s.Push("km");
            s.Push("aa");
            s.Push("ab");
            s.Push("ac");
            s.Push("xx");

            foreach (var x in s)
            {
                Console.WriteLine(x);
            }
            Console.WriteLine("---top to bottom---");
            foreach (var x in ((StosWTablicy <string>)s).TopToBottom)
            {
                Console.WriteLine(x);
            }
            Console.WriteLine($"Actual tab length: {s.GetActualTabLength()}");
            s.TrimExcess();
            Console.WriteLine($"Length after TrimExcess: {s.GetActualTabLength()}");

            Console.WriteLine($"el at position 1 (\"aa\"): {s[1]} {"aa" == s[1]}");
            Console.WriteLine();

            var sToArray         = s.ToArray();
            var sToArrayReadOnly = s.ToArrayReadOnly();

            sToArray[1] = "ssss";
            foreach (var x in sToArray)
            {
                Console.WriteLine(x);
            }
            //sToArrayReadOnly[1] = "ss"; read only error
            Console.WriteLine("---StosWLiscie---");
            StosWLiscie <int> sl = new StosWLiscie <int>();

            sl.Push(5);
            sl.Push(6);
            Console.WriteLine($"el at index 1: {sl[1]}");
            sl.Push(7);
            sl.Push(8);
            int[] tab = sl.ToArray();
            foreach (var i in tab)
            {
                Console.Write($"{i} ");
            }
            Console.WriteLine("\nPop:");
            sl.Pop();
            tab = sl.ToArray();
            foreach (var i in tab)
            {
                Console.Write($"{i} ");
            }
            Console.WriteLine();
            Console.WriteLine("foreach through StosWLiscie");
            foreach (var i in sl)
            {
                Console.Write($"{i} ");
            }
            Console.WriteLine($"\nIs array empty? {sl.IsEmpty}");
            sl.Clear();
            Console.WriteLine("After clear:");
            Console.WriteLine($"Is array empty? {sl.IsEmpty}");
        }
        public void TrimExcess_PustegoStosu_StosEmptyException()
        {
            var f = new StosWTablicy <int>();

            f.TrimExcess();
        }
Ejemplo n.º 8
0
        public void TrimExcessDlaPustegoStosu_StosEmptyException()
        {
            var s = new StosWTablicy <int>();

            s.TrimExcess();
        }