コード例 #1
0
ファイル: TestListardPosition.cs プロジェクト: j0035/Snek
        public void TestAddExt()
        {
            Listard <Position> l = new Listard <Position>();
            int cnt = 0;

            for (int i = 0; i < 100; i++)
            {
                Position v = new Position(i * 2, 1 * 3);
                cnt++;
                l.Add(v);
                if (l.Count != cnt)
                {
                    throw new Exception();
                }
                if (l[l.Count - 1] != v)
                {
                    throw new Exception();
                }
                try {
                    Position test = l[-1];
                    throw new Exception();
                } catch (IndexOutOfRangeException) { /* expected error */ }
                try {
                    Position test = l[l.Count];
                    throw new Exception();
                } catch (IndexOutOfRangeException) { /* expected error */ }
            }
        }
コード例 #2
0
ファイル: TestListardPosition.cs プロジェクト: j0035/Snek
        public void TestAddBlock()
        {
            Listard <Position> l = new Listard <Position>();

            Position[] block = new Position[] { new Position("47|11"), new Position("47|12"), new Position("48|13") };
            l.Add(block);
            if (l.Count != block.Length)
            {
                throw new Exception();
            }
            for (int i = 0; i < block.Length; i++)
            {
                if (l[i] != block[i])
                {
                    throw new Exception();
                }
            }
            try {
                Position test = l[-1];
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
            try {
                Position test = l[l.Count];
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Listard myListard = new Listard(10);

            myListard.Set(4710, 0);
            myListard.Set(4711, 1);

            // Eigene Klassen wie ein Array benutzen
            myListard[1] = 99;    // schreibender Zugriff
            int y = myListard[1]; // lesender Zugriff

            for (int i = 0; i < 100; i++)
            {
                myListard.Add(4712);
            }

            DateTime t1 = DateTime.Now;

            myListard.Add(new int[100000]);
            DateTime t2 = DateTime.Now;
            TimeSpan dt = t2 - t1;

            Listard myListard2 = new Listard();

            myListard2.Set(3710, 4);
            myListard2.Add(3711);
        }
コード例 #4
0
        public void TestForEach()
        {
            // test iteration upon empty list
            Listard <int> l = new Listard <int>();

            foreach (int v in l)
            {
                throw new Exception();
            }

            // test iteration upon filled list
            int[] block = new int[] { 4711, 4712, 4713 };
            l.Add(block);
            if (l.Count != block.Length)
            {
                throw new Exception();
            }
            int i = 0;

            foreach (int v in l)
            {
                if (v != block[i++])
                {
                    throw new Exception();
                }
            }
        }
コード例 #5
0
ファイル: TestListardPosition.cs プロジェクト: j0035/Snek
        public void TestGetSet()
        {
            Listard <Position> l = new Listard <Position>();

            Position[] block = new Position[] { new Position("47|11"), new Position("47|12"), new Position("48|13") };
            l.Add(block);
            l[0].X = 10 * l[0].X;
            l.Set(new Position(l.Get(1).X, l.Get(1).Y * 10), 1);
            if (l[0].Text != "470|11")
            {
                throw new Exception();
            }
            if (l[1].Text != "47|120")
            {
                throw new Exception();
            }
            if (l.Get(2).Text != "48|13")
            {
                throw new Exception();
            }
            try {
                Position test = l.Get(-1);
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
            try {
                Position test = l.Get(l.Count);
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
        }
コード例 #6
0
ファイル: TestListardPosition.cs プロジェクト: j0035/Snek
        public void TestForEach()
        {
            // test iteration upon empty list
            Listard <Position> l = new Listard <Position>();

            foreach (Position v in l)
            {
                throw new Exception();
            }

            // test iteration upon filled list
            Position[] block = new Position[] { new Position("47|11"), new Position("47|12"), new Position("48|13") };
            l.Add(block);
            if (l.Count != block.Length)
            {
                throw new Exception();
            }
            int i = 0;

            foreach (Position v in l)
            {
                // equal by reference?
                if (v != block[i])
                {
                    throw new Exception();
                }
                // equal by text representation?
                if (v.Text != block[i++].Text)
                {
                    throw new Exception();
                }
            }
        }
コード例 #7
0
        public void TestAdd()
        {
            Listard <int> l = new Listard <int>();

            l.Add(4711);
            if (l.Count != 1)
            {
                throw new Exception();
            }
            if (l.Size != 1)
            {
                throw new Exception();
            }
            if (l[0] != 4711)
            {
                throw new Exception();
            }
            try {
                int test = l[-1];
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
            try {
                int test = l[l.Count];
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
        }
コード例 #8
0
ファイル: Run.cs プロジェクト: Masuka606/Listard
        public void TestAdd()
        {
            Listard l = new Listard();

            if (l.Count != 0)
            {
                throw new Exception("Liste nicht leer");
            }

            l.Add(13);
            if (l.Count != 1)
            {
                throw new Exception("Fehler: TestAdd Error 0001");
            }

            if (l[0] != 13)
            {
                throw new Exception("TestAdd Error 0002");
            }

            l.Add(5);
            if (l.Count == 2)
            {
                throw new Exception("Fehler: TestAdd Error 0003");
            }
            if (l[1] != 5)
            {
                throw new Exception("Fehler: TestAdd Error 0004");
            }
        }
コード例 #9
0
        public void TestBig()
        {
            int           huge = 1000000;
            Listard <int> l    = new Listard <int>(huge);

            l[0] = 4711;
            if (l[0] != 4711)
            {
                throw new Exception();
            }
            if (l[1] != 0)
            {
                throw new Exception();
            }

            l[l.Count - 1] = 4712;
            if (l[huge - 1] != 4712)
            {
                throw new Exception();
            }
            if (l[huge - 2] != 0)
            {
                throw new Exception();
            }
        }
コード例 #10
0
 public void TestNewExt()
 {
     // test a new Listard<int> with initial count
     int[] list = { 1, 2, 3, 10, 100, 100 };
     foreach (int n in list)
     {
         Listard <int> l = new Listard <int>(n);
         if (l.Count != n)
         {
             throw new Exception();
         }
         if (l.Size != n)
         {
             throw new Exception();
         }
         for (int i = 0; i < n; i++)
         {
             if (l[i] != 0)
             {
                 throw new Exception();
             }
         }
         try {
             int test = l[-1];
             throw new Exception();
         } catch (IndexOutOfRangeException) { /* expected error */ }
         try {
             int test = l[l.Count];
             throw new Exception();
         } catch (IndexOutOfRangeException) { /* expected error */ }
     }
 }
コード例 #11
0
        public void TestGetSet()
        {
            Listard <int> l = new Listard <int>();

            int[] block = new int[] { 4711, 4712, 4713 };
            l.Add(block);
            l[0] = 10 * l[0];
            l.Set(10 * l.Get(1), 1);
            if (l[0] != 47110)
            {
                throw new Exception();
            }
            if (l[1] != 47120)
            {
                throw new Exception();
            }
            if (l.Get(2) != 4713)
            {
                throw new Exception();
            }
            try {
                int test = l.Get(-1);
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
            try {
                int test = l.Get(l.Count);
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
        }
コード例 #12
0
        public void TestAddBlock()
        {
            Listard <int> l = new Listard <int>();

            int[] block = new int[] { 4711, 4712, 4713 };
            l.Add(block);
            if (l.Count != block.Length)
            {
                throw new Exception();
            }
            for (int i = 0; i < block.Length; i++)
            {
                if (l[i] != block[i])
                {
                    throw new Exception();
                }
            }
            try {
                int test = l[-1];
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
            try {
                int test = l[l.Count];
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
        }
コード例 #13
0
        public void TestAddExt()
        {
            Listard <int> l   = new Listard <int>();
            int           cnt = 0;

            for (int v = 4711; v < 4722; v++)
            {
                cnt++;
                l.Add(v);
                if (l.Count != cnt)
                {
                    throw new Exception();
                }
                if (l[l.Count - 1] != v)
                {
                    throw new Exception();
                }
                try {
                    int test = l[-1];
                    throw new Exception();
                } catch (IndexOutOfRangeException) { /* expected error */ }
                try {
                    int test = l[l.Count];
                    throw new Exception();
                } catch (IndexOutOfRangeException) { /* expected error */ }
            }
        }
コード例 #14
0
ファイル: TestListardPosition.cs プロジェクト: j0035/Snek
        public void TestAdd()
        {
            Listard <Position> l = new Listard <Position>();

            l.Add(new Position("47|11"));
            if (l.Count != 1)
            {
                throw new Exception();
            }
            if (l.Size != 1)
            {
                throw new Exception();
            }
            if (l[0].Text != "47|11")
            {
                throw new Exception();
            }
            try {
                Position test = l[-1];
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
            try {
                Position test = l[l.Count];
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
        }
コード例 #15
0
ファイル: TestListardPosition.cs プロジェクト: j0035/Snek
        public void TestBig()
        {
            int huge             = 1000000;
            Listard <Position> l = new Listard <Position>(huge);

            l[0] = new Position("47|11");
            if (l[0].Text != "47|11")
            {
                throw new Exception();
            }
            if (l[1] != null)
            {
                throw new Exception();
            }

            l[l.Count - 1] = new Position("47|12");
            if (l[huge - 1].Text != "47|12")
            {
                throw new Exception();
            }
            if (l[huge - 2] != null)
            {
                throw new Exception();
            }
        }
コード例 #16
0
ファイル: TestListardPosition.cs プロジェクト: j0035/Snek
        public void TestInsert()
        {
            var l = new Listard <Position>();

            Position[] block = new Position[] { new Position("47|11"), new Position("47|12"), new Position("48|13") };
            l.Add(block);
            l.InsertAt(new Position[] { new Position("57|14"), new Position("57|15") }, 3);
            l.InsertAt(new Position[] { new Position("57|16"), new Position("57|17") }, 2);
            l.InsertAt(new Position[] { new Position("57|18"), new Position("57|19") }, 1);
            l.InsertAt(new Position[] { new Position("57|20"), new Position("57|21") }, 0);

            string[] check =
            {
                "57|20", "57|21", "47|11",
                "57|18", "57|19", "47|12",
                "57|16", "57|17", "48|13",
                "57|14", "57|15"
            };
            for (int i = 0; i < check.Length; i++)
            {
                if (l[i].Text != check[i])
                {
                    throw new Exception();
                }
            }
        }
コード例 #17
0
        public void TestInsert()
        {
            var l = new Listard <int>();

            l.Add(new int[] { 10, 20, 30 });
            l.InsertAt(new int[] { 300, 301 }, 3);
            l.InsertAt(new int[] { 200, 201 }, 2);
            l.InsertAt(new int[] { 100, 101 }, 1);
            l.InsertAt(new int[] { 000, 001 }, 0);

            int[] block = { 0, 1, 10, 100, 101, 20, 200, 201, 30, 300, 301 };
            for (int i = 0; i < block.Length; i++)
            {
                if (l[i] != block[i])
                {
                    throw new Exception();
                }
            }
        }
コード例 #18
0
        public void TestNew()
        {
            // test a new Listard<int> with default count
            Listard <int> l = new Listard <int>();

            if (l.Count != 0)
            {
                throw new Exception();
            }
            if (l.Size != 0)
            {
                throw new Exception();
            }
            try {
                int test = l[-1];
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
            try {
                int test = l[l.Count];
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
        }
コード例 #19
0
        public void TestDelete()
        {
            Listard <int> l = new Listard <int>();

            int[] block = new int[] { 4711, 4712, 4713, 4714, 4715 };
            l.Add(block);
            l.Delete(1, 2);
            if (l.Count != 3)
            {
                throw new Exception();
            }
            if (l[0] != 4711)
            {
                throw new Exception();
            }
            if (l[1] != 4714)
            {
                throw new Exception();
            }
            if (l[2] != 4715)
            {
                throw new Exception();
            }
            l.Delete(2, 0);
            if (l.Count != 3)
            {
                throw new Exception();
            }
            if (l[0] != 4711)
            {
                throw new Exception();
            }
            if (l[1] != 4714)
            {
                throw new Exception();
            }
            if (l[2] != 4715)
            {
                throw new Exception();
            }
            l.Delete(2, 1);
            if (l.Count != 2)
            {
                throw new Exception();
            }
            if (l[0] != 4711)
            {
                throw new Exception();
            }
            if (l[1] != 4714)
            {
                throw new Exception();
            }
            l.Delete(0);
            if (l.Count != 1)
            {
                throw new Exception();
            }
            if (l[0] != 4714)
            {
                throw new Exception();
            }

            try {
                l.Delete(-1);
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
            try {
                l.Delete(1);
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
            try {
                l.Delete(0, -1);
                throw new Exception();
            } catch (ArgumentException) { /* expected error */ }
            try {
                l.Delete(0, 2);
                throw new Exception();
            } catch (ArgumentException) { /* expected error */ }

            l.Delete(0, 1);
            if (l.Count != 0)
            {
                throw new Exception();
            }
        }
コード例 #20
0
 public ListardEnumerator(Listard <T> listard)
 {
     this.listard = listard;
     this.Reset();
 }
コード例 #21
0
ファイル: TestListardPosition.cs プロジェクト: j0035/Snek
        public void TestDelete()
        {
            Listard <Position> l = new Listard <Position>();

            Position[] block = new Position[] {
                new Position("47|11"), new Position("47|12"),
                new Position("48|13"), new Position("48|14"), new Position("48|15")
            };
            l.Add(block);
            l.Delete(3, 2);
            if (l.Count != 3)
            {
                throw new Exception();
            }
            if (l[0].Text != "47|11")
            {
                throw new Exception();
            }
            if (l[1].Text != "47|12")
            {
                throw new Exception();
            }
            if (l[2].Text != "48|13")
            {
                throw new Exception();
            }
            l.Delete(1, 0);
            if (l.Count != 3)
            {
                throw new Exception();
            }
            if (l[0].Text != "47|11")
            {
                throw new Exception();
            }
            if (l[1].Text != "47|12")
            {
                throw new Exception();
            }
            if (l[2].Text != "48|13")
            {
                throw new Exception();
            }
            l.Delete(1, 1);
            if (l.Count != 2)
            {
                throw new Exception();
            }
            if (l[0].Text != "47|11")
            {
                throw new Exception();
            }
            if (l[1].Text != "48|13")
            {
                throw new Exception();
            }
            l.Delete(0);
            if (l.Count != 1)
            {
                throw new Exception();
            }
            if (l[0].Text != "48|13")
            {
                throw new Exception();
            }

            try {
                l.Delete(-1);
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
            try {
                l.Delete(1);
                throw new Exception();
            } catch (IndexOutOfRangeException) { /* expected error */ }
            try {
                l.Delete(0, -1);
                throw new Exception();
            } catch (ArgumentException) { /* expected error */ }
            try {
                l.Delete(0, 2);
                throw new Exception();
            } catch (ArgumentException) { /* expected error */ }

            l.Delete(0, 1);
            if (l.Count != 0)
            {
                throw new Exception();
            }
        }