Exemplo n.º 1
0
        public static SparseAList <int> init(int[] arr, int size)
        {
            var result = new SparseAList <int>();

            result.AddRange(arr);
            return(result);
        }
Exemplo n.º 2
0
        public void TestSwap()
        {
            List <int>        list1, list2;
            SparseAList <int> alist1 = NewList(10, out list1);
            SparseAList <int> alist2 = NewList(100, out list2);

            // Can't Swap with a frozen list
            SparseAList <int> frozen = alist1.Clone();

            frozen.Freeze();
            if (_testExceptions)
            {
                AssertThrows <ReadOnlyException>(() => alist1.Swap(frozen));
            }

            // Swap, and ensure that ListChanging and NodeObserver are swapped.
            alist1.ListChanging += (sender, args) => Assert.Fail();
            alist1.AddObserver(new AListTestObserver <int, int>());
            alist1.Swap(alist2);
            Assert.AreEqual(0, alist1.ObserverCount);
            Assert.AreEqual(1, alist2.ObserverCount);

            list2.Add(999);
            alist1.Add(999);
            ExpectList(alist1, list2, false);
            ExpectList(alist2, list1, true);
        }
Exemplo n.º 3
0
        public void TestPrependAppend()
        {
            List <int> list  = new List <int>();
            var        alist = NewList();

            List <int>[]        lists  = new List <int> [13];
            SparseAList <int>[] alists = new SparseAList <int>[]
            {
                NewList(0, 0, out lists[0]),
                NewList(2, 1, out lists[1]),
                NewList(6, 5, out lists[2]),
                NewList(10, 5, out lists[3]),
                NewList(15, 11, out lists[4]),
                NewList(30, 11, out lists[5]),
                NewList(30, 20, out lists[6]),
                NewList(60, 20, out lists[7]),
                NewList(50, 32, out lists[8]),
                NewList(100, 32, out lists[9]),
                NewList(80, 53, out lists[10]),
                NewList(150, 53, out lists[11]),
                NewList(150, 100, out lists[12]),
            };
            Assert.AreEqual(alists.Length, lists.Length);

            // So, let's just do a random series of Append and Prepend operations,
            // clearing the list occasionally so that both list sizes vary a lot,
            // which will cause the code paths to vary (important because there
            // are several different ways these operations can be done).
            for (int trial = 0; trial < 20; trial++)
            {
                if (trial % 4 == 0)
                {
                    alist.Clear();
                    list.Clear();
                }
                int whirl = _r.Next(alists.Length);
                SparseAList <int> other = alists[whirl];
                bool append             = _r.Next(2) == 0;

                int ric = alist.GetRealItemCount(), otherRic = other.GetRealItemCount(), oldTH = alist.TreeHeight;
                if (append)
                {
                    alist.Append(other);
                    list.AddRange(lists[whirl]);
                }
                else
                {
                    alist.Prepend(other);
                    list.InsertRange(0, lists[whirl]);
                }
                Assert.That(other.GetImmutableCount() == other.Count || other.TreeHeight <= 1);
                Assert.That(alist.GetRealItemCount() == ric + otherRic);
                Assert.That(alist.GetImmutableCount() >= other.GetImmutableCount() || oldTH == 1);
            }
        }
Exemplo n.º 4
0
        public void LeafCapacityLimitIsRespected()
        {
            var list = new SparseAList <int>(_maxLeafSize, _maxInnerSize);

            for (int i = 0; i < 100 + _maxLeafSize * _maxInnerSize; i++)
            {
                list.Insert(_r.Next(list.Count + 1), i);
            }

            VerifyLeafCapacityLimitIsRespected(list, _maxLeafSize);
        }
Exemplo n.º 5
0
        public override IListSource <ITagSpan <ITag> > RunAnalysis(ITextSnapshot snapshot,
                                                                   SparseAList <EditorToken> eTokens, CancellationToken cancellationToken)
        {
            var sourceFile = new TextSnapshotAsSourceFile(snapshot);
            var tokens     = ToNormalTokens(eTokens);
            var results    = new DList <ITagSpan <ClassificationTag> >();
            var parser     = new MyLesParser(tokens, sourceFile, TraceMessageSink.Value, results);
            var _          = parser.StmtList();

            results.Sort((t1, t2) => t1.Span.Start.Position.CompareTo(t2.Span.Start.Position));
            return(results);
        }
Exemplo n.º 6
0
        public void TestNextLowerItem()
        {
            var alist = new SparseAList <int>(_maxLeafSize, _maxInnerSize);
            int?i;

            for (i = 0; i < 100; i++)
            {
                alist.Add(i.Value);
                alist.InsertSpace(alist.Count, 1000);
            }
            i = int.MaxValue;
            Assert.AreEqual(alist.NextLowerItem(ref i), 99);
            Assert.AreEqual(i.Value, 99099);
            i = 99100;
            Assert.AreEqual(alist.NextLowerItem(ref i), 99);
            Assert.AreEqual(i.Value, 99099);
            Assert.AreEqual(alist.NextLowerItem(ref i), 98);
            Assert.AreEqual(i.Value, 98098);
            i = 55555;
            Assert.AreEqual(alist.NextLowerItem(ref i), 55);
            Assert.AreEqual(i.Value, 55055);
            i = 1002;
            Assert.AreEqual(alist.NextLowerItem(ref i), 1);
            Assert.AreEqual(i.Value, 1001);
            Assert.AreEqual(alist.NextLowerItem(ref i), 0);
            Assert.AreEqual(i.Value, 0);
            i = 1;
            Assert.AreEqual(alist.NextLowerItem(ref i), 0);
            Assert.AreEqual(i.Value, 0);
            Assert.AreEqual(alist.NextLowerItem(ref i), default(int));
            Assert.AreEqual(i.HasValue, false);
            i = int.MinValue;
            Assert.AreEqual(alist.NextLowerItem(ref i), default(int));
            Assert.AreEqual(i.HasValue, false);

            // Place a value at the edge of integer space
            alist.Clear();
            alist.InsertSpace(0, int.MaxValue - 1);
            alist.Add(777);
            i = int.MinValue;
            Assert.AreEqual(alist.NextLowerItem(ref i), default(int));
            Assert.AreEqual(i.HasValue, false);
            i = int.MaxValue;
            Assert.AreEqual(alist.NextLowerItem(ref i), default(int));
            Assert.AreEqual(i.HasValue, false);
            i = null;
            Assert.AreEqual(alist.NextLowerItem(ref i), 777);
            Assert.AreEqual(i.Value, int.MaxValue);
        }
Exemplo n.º 7
0
        public static DList <Token> ToNormalTokens(SparseAList <EditorToken> eTokens)
        {
            var output = new DList <Token>();
            int?index  = null;

            for (;;)
            {
                EditorToken eTok = eTokens.NextHigherItem(ref index);
                if (index == null)
                {
                    break;
                }
                output.Add(eTok.ToToken(index.Value));
            }
            return(output);
        }
Exemplo n.º 8
0
        public override IListSource <ITagSpan <ITag> > RunAnalysis(ITextSnapshot snapshot,
                                                                   SparseAList <EditorToken> eTokens, CancellationToken cancellationToken)
        {
            var sourceFile    = new TextSnapshotAsSourceFile(snapshot);
            var tokens        = ToNormalTokens(eTokens);
            var tokensAsLexer = new TokenListAsLexer(tokens, sourceFile);
            var tokensTree    = new TokensToTree(new TokenListAsLexer(tokens, sourceFile), true)
            {
                ErrorSink = MessageSink.Trace
            };
            var results = new DList <ITagSpan <ClassificationTag> >();
            var parser  = new MyLesParser(tokensTree.Buffered(), sourceFile, MessageSink.Trace, results);

            parser.ParseStmtsGreedy();
            results.Sort((t1, t2) => t1.Span.Start.Position.CompareTo(t2.Span.Start.Position));
            return(results);
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Input elements of a list in a row: ");
            var s   = Console.ReadLine().Split(' ');
            var arr = s.Select(f => Convert.ToInt32(f)).ToArray();

            // var arr = new int[] { 0, 0, 0, 0, 0, 2, 4, 7, 10 };

            facebookList = init(arr, arr.Length);

            // Gets 2 from test array
            Console.WriteLine($"{get(5)}");

            // Sets 2 to 100
            set(5, 100);

            // Gets 100 from test array
            Console.WriteLine($"{get(5)}");
        }
Exemplo n.º 10
0
        public void TestClearSpace()
        {
            for (int iter = 0; iter < 10; iter++)
            {
                int i1 = MathEx.Square(_r.Next(50)) + 1;                      // e.g. 100
                int i0 = _r.Next(i1);                                         // e.g. 50
                int i2 = i1 + MathEx.Square(_r.Next(50)) + 1;                 // e.g. 100
                int i3 = i2 + _r.Next(2500);                                  // e.g. 1000

                SparseAList <int> list = new SparseAList <int>();
                list.ClearSpace(0, i1);
                Assert.AreEqual(i1, list.Count);
                Assert.AreEqual(0, list.GetRealItemCount());
                Assert.AreEqual(0, list[i1 - 1]);
                if (_testExceptions)
                {
                    Assert.Throws <ArgumentOutOfRangeException>(() => { var _ = list[i1]; });
                    Assert.Throws <ArgumentOutOfRangeException>(() => { list.ClearSpace(0, -1); });
                    Assert.Throws <ArgumentOutOfRangeException>(() => { list.ClearSpace(-1, 10); });
                }
                list.ClearSpace(i0, i2 - i0);
                Assert.AreEqual(i2, list.Count);
                Assert.AreEqual(0, list.GetRealItemCount());
                for (int i = i0; i < i2; i++)
                {
                    list[i] = i;
                }
                list.ClearSpace(i1, i3 - i1);
                Assert.AreEqual(i3, list.Count);
                Assert.AreEqual(i1 - i0, list.GetRealItemCount());
                list.ClearSpace(i0 + 1, i1 - (i0 + 1));
                Assert.AreEqual(i3, list.Count);
                Assert.AreEqual(1, list.GetRealItemCount());
                list.ClearSpace(0, i0 + 1);
                Assert.AreEqual(i3, list.Count);
                Assert.AreEqual(0, list.GetRealItemCount());
            }
        }
Exemplo n.º 11
0
        protected SparseAList <int> NewList(int initialCount, int realCount, out List <int> list)
        {
            Debug.Assert(realCount <= initialCount);
            SparseAList <int> alist = NewList();

            list = new List <int>();

            // Make a list of random size <= initialCount
            for (int i = 0; i < realCount; i++)
            {
                AddToBoth(alist, list, i, i);
            }

            // Add empty spaces until Count == initialCount
            while (alist.Count < initialCount)
            {
                int i = _r.Next(alist.Count + 1);
                alist.InsertSpace(i);
                list.Insert(i, 0);
            }

            return(alist);
        }
Exemplo n.º 12
0
        SparseAList <int> NewList(int start, int count, ListChangingHandler <int> observer, out List <int> list)
        {
            var alist = new SparseAList <int>(_maxLeafSize, _maxInnerSize);

            list = new List <int>();
            for (int i = 0; i < count; i++)
            {
                if (_r.Next(2) == 0)
                {
                    alist.Add(start + i);
                    list.Add(start + i);
                }
                else
                {
                    alist.InsertSpace(i);
                    list.Add(0);
                }
            }
            if (observer != null)
            {
                alist.ListChanging += observer;
            }
            return(alist);
        }
Exemplo n.º 13
0
 protected override SparseAList <int> RemoveSection(SparseAList <int> alist, int start, int subcount)
 {
     return(alist.RemoveSection(start, subcount));
 }
Exemplo n.º 14
0
		public static DList<Token> ToNormalTokens(SparseAList<EditorToken> eTokens)
		{
			var output = new DList<Token>();
			int? index = null;
			for (;;) {
				EditorToken eTok = eTokens.NextHigherItem(ref index);
				if (index == null) break;
				output.Add(eTok.ToToken(index.Value));
			}
			return output;
		}
Exemplo n.º 15
0
 public static int Loyc_Collections()
 {
     return(MiniTest.RunTests.RunMany(
                new InternalDArrayTests(_seed),
                new TypeDictionaryWithBaseTypeLookupsTests(),
                new ListSourceSliceTests(),
                new ListSliceTests(),
                new ROLSliceTests(),
                new HeapTests(_seed),
                new SimpleCacheTests(),
                new InvertibleSetTests(),
                // Test with small node sizes as well as the standard node size,
                // including the minimum size of 3 (the most problematic size).
                new AListTests(false, _seed, 8, 8),
                new AListTests(false, _seed, 3, 3),
                new BListTests(false, _seed, 8, 8),
                new BListTests(false, _seed, 3, 3),
                new BDictionaryTests(false, _seed, 6, 6),
                new SparseAListTests(false, _seed, 3, 3),
                new SparseAListTests(false, _seed, 9, 9),
                new BMultiMapTests(4),
                new DequeTests <DList <int> >(delegate() { return new DList <int>(); }),
                new DequeTests <AList <int> >(delegate() { return new AList <int>(); }),
                new DequeTests <SparseAList <int> >(delegate() { return new SparseAList <int>(); }),
                new DictionaryTests <BDictionary <object, object> >(true, true),
                new ListTests <AList <int> >(false, delegate(int n) { var l = new AList <int>(); l.Resize(n); return l; }),
                new ListRangeTests <AList <int> >(false, delegate() { return new AList <int>(); }, 12345),
                new ListTests <SparseAList <int> >(false, delegate(int n) { var l = new SparseAList <int>(); l.Resize(n); return l; }, 12345),
                new ListRangeTests <SparseAList <int> >(false, delegate() { return new SparseAList <int>(); }, 12345),
                new WListTests(),
                new FWListTests(),
                new VListTests(),
                new FVListTests(),
                new MapTests(),
                new SparseAListTests(true, _seed, 8, 4),
                new SparseAListTests(),
                new AListTests(),
                new BListTests(),
                new BDictionaryTests(),
                new MSetTests(),        // derived from MutableSetTests<MSet<STI>, STI>
                new SymbolSetTests(),   // derived from MutableSetTests<MSet<Symbol>, Symbol>
                new ImmSetTests(),      // tests for Set<T>
                new MapTests()          // derived from DictionaryTests<MMap<object, object>>
                ));
 }
Exemplo n.º 16
0
        public static void Loyc_Collections()
        {
            MiniTest.RunTests.Run(new CPTrieTests());
            MiniTest.RunTests.Run(new SimpleCacheTests());
            MiniTest.RunTests.Run(new InvertibleSetTests());
            // Test with small node sizes as well as the standard node size,
            // including the minimum size of 3 (the most problematic size).
            int seed = 237588399;

            MiniTest.RunTests.Run(new AListTests(false, seed, 8, 8));
            MiniTest.RunTests.Run(new BListTests(false, seed, 3, 3));
            MiniTest.RunTests.Run(new BDictionaryTests(false, seed, 6, 6));
            MiniTest.RunTests.Run(new SparseAListTests(false, seed, 10, 10));
            MiniTest.RunTests.Run(new DequeTests <AList <int> >(delegate() { return(new AList <int>()); }));
            MiniTest.RunTests.Run(new DequeTests <SparseAList <int> >(delegate() { return(new SparseAList <int>()); }));
            MiniTest.RunTests.Run(new DictionaryTests <BDictionary <object, object> >(true, true));
            MiniTest.RunTests.Run(new ListTests <AList <int> >(false, delegate(int n) { var l = new AList <int>(); l.Resize(n); return(l); }));
            MiniTest.RunTests.Run(new ListRangeTests <AList <int> >(false, delegate() { return(new AList <int>()); }, 12345));
            MiniTest.RunTests.Run(new ListTests <SparseAList <int> >(false, delegate(int n) { var l = new SparseAList <int>(); l.Resize(n); return(l); }, 12345));
            MiniTest.RunTests.Run(new ListRangeTests <SparseAList <int> >(false, delegate() { return(new SparseAList <int>()); }, 12345));
            MiniTest.RunTests.Run(new RWListTests());
            MiniTest.RunTests.Run(new WListTests());
            MiniTest.RunTests.Run(new RVListTests());
            MiniTest.RunTests.Run(new VListTests());
            MiniTest.RunTests.Run(new MapTests());
            MiniTest.RunTests.Run(new SparseAListTests(true, seed, 8, 4));
            MiniTest.RunTests.Run(new SparseAListTests());
            MiniTest.RunTests.Run(new AListTests());
            MiniTest.RunTests.Run(new BListTests());
            MiniTest.RunTests.Run(new BDictionaryTests());
            MiniTest.RunTests.Run(new MSetTests());            // derived from MutableSetTests<MSet<STI>, STI>
            MiniTest.RunTests.Run(new SymbolSetTests());       // derived from MutableSetTests<MSet<Symbol>, Symbol>
            MiniTest.RunTests.Run(new ImmSetTests());          // tests for Set<T>
            MiniTest.RunTests.Run(new MapTests());             // derived from DictionaryTests<MMap<object, object>>
            MiniTest.RunTests.Run(new KeylessHashtableTests());
        }
Exemplo n.º 17
0
 // Derived class is responsible for parsing in this method
 public abstract ParseResults RunAnalysis(ITextSnapshot snapshot, SparseAList <EditorToken> input, CancellationToken cancelToken);
Exemplo n.º 18
0
        public static void Main(string[] args)
        {
            // Workaround for MS bug: Assert(false) will not fire in debugger
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new DefaultTraceListener());

            Console.WriteLine("Running tests on stable code...");
            // Omitted: unit tests that throw & catch exceptions (those are below)

            // Loyc.Essentials
            RunTests.Run(new ListExtTests());
            RunTests.Run(new MathExTests());
            RunTests.Run(new UStringTests());
            RunTests.Run(new StringExtTests());
            RunTests.Run(new HashTagsTests());
            RunTests.Run(new LocalizeTests());
            RunTests.Run(new SymbolTests());
            RunTests.Run(new ThreadExTests());
            RunTests.Run(new ListTests <InternalList <int> >(false, delegate(int n) { var l = InternalList <int> .Empty; l.Resize(n); return(l); }));
            RunTests.Run(new ListRangeTests <InternalList <int> >(false, delegate() { return(InternalList <int> .Empty); }));
            RunTests.Run(new ListTests <DList <int> >(false, delegate(int n) { var l = new DList <int>(); l.Resize(n); return(l); }));
            RunTests.Run(new DequeTests <DList <int> >(delegate() { return(new DList <int>()); }));
            RunTests.Run(new ListRangeTests <DList <int> >(false, delegate() { return(new DList <int>()); }));

            // Loyc.Collections
            RunTests.Run(new CPTrieTests());
            RunTests.Run(new SimpleCacheTests());
            RunTests.Run(new InvertibleSetTests());
            // Test with small node sizes as well as the standard node size,
            // including the minimum size of 3 (the most problematic size).
            int seed = 237588399;

            RunTests.Run(new AListTests(false, seed, 8, 8));
            RunTests.Run(new BListTests(false, seed, 3, 3));
            RunTests.Run(new BDictionaryTests(false, seed, 6, 6));
            RunTests.Run(new SparseAListTests(false, seed, 10, 10));
            RunTests.Run(new DequeTests <AList <int> >(delegate() { return(new AList <int>()); }));
            RunTests.Run(new DequeTests <SparseAList <int> >(delegate() { return(new SparseAList <int>()); }));
            RunTests.Run(new DictionaryTests <BDictionary <object, object> >(true, true));
            RunTests.Run(new ListTests <AList <int> >(false, delegate(int n) { var l = new AList <int>(); l.Resize(n); return(l); }));
            RunTests.Run(new ListRangeTests <AList <int> >(false, delegate() { return(new AList <int>()); }, 12345));
            RunTests.Run(new ListTests <SparseAList <int> >(false, delegate(int n) { var l = new SparseAList <int>(); l.Resize(n); return(l); }, 12345));
            RunTests.Run(new ListRangeTests <SparseAList <int> >(false, delegate() { return(new SparseAList <int>()); }, 12345));

            // Loyc.Syntax
            RunTests.Run(new TokenTests());
            RunTests.Run(new LesLexerTests());
            RunTests.Run(new LesParserTests());
            RunTests.Run(new LesPrinterTests());
            RunTests.Run(new TokensToTreeTests());
            RunTests.Run(new StreamCharSourceTests());
            RunTests.Run(new LexerSourceTests_Calculator());
            RunTests.Run(new ParserSourceTests_Calculator());
            RunTests.Run(new IndentTokenGeneratorTests());

            // Loyc.Utilities
            RunTests.Run(new LineMathTests());
            RunTests.Run(new PointMathTests());
            RunTests.Run(new Loyc.LLParserGenerator.IntSetTests());
            RunTests.Run(new TagsInWListTests());
            RunTests.Run(new UGTests());

            for (;;)
            {
                ConsoleKeyInfo k;

                Console.WriteLine();
                Console.WriteLine("What do you want to do?");
                Console.WriteLine("1. Run unit tests that expect exceptions");
                Console.WriteLine("2. Run unit tests on unstable code");
                Console.WriteLine("9. Benchmarks");
                Console.WriteLine("Z. List encodings");
                Console.WriteLine("Press ESC or ENTER to Quit");
                Console.WriteLine((k = Console.ReadKey(true)).KeyChar);
                if (k.Key == ConsoleKey.Escape || k.Key == ConsoleKey.Enter)
                {
                    break;
                }
                else if (k.KeyChar == '1')
                {
                    // Loyc.Essentials
                    RunTests.Run(new GTests());

                    // Loyc.Utilities
                    RunTests.Run(new GoInterfaceTests());

                    // Loyc.Collections
                    RunTests.Run(new RWListTests());
                    RunTests.Run(new WListTests());
                    RunTests.Run(new RVListTests());
                    RunTests.Run(new VListTests());
                    RunTests.Run(new MapTests());
                    RunTests.Run(new SparseAListTests(true, seed, 8, 4));
                    RunTests.Run(new SparseAListTests());
                    RunTests.Run(new AListTests());
                    RunTests.Run(new BListTests());
                    RunTests.Run(new BDictionaryTests());
                    RunTests.Run(new MSetTests());                    // derived from MutableSetTests<MSet<STI>, STI>
                    RunTests.Run(new SymbolSetTests());               // derived from MutableSetTests<MSet<Symbol>, Symbol>
                    RunTests.Run(new ImmSetTests());                  // tests for Set<T>
                    RunTests.Run(new MapTests());                     // derived from DictionaryTests<MMap<object, object>>
                }
                else if (k.KeyChar == '2')
                {
                    RunTests.Run(new KeylessHashtableTests());
                }
                else if (k.KeyChar == 'z' || k.KeyChar == 'Z')
                {
                    foreach (EncodingInfo inf in Encoding.GetEncodings())
                    {
                        Console.WriteLine("{0} {1}: {2}", inf.CodePage, inf.Name, inf.DisplayName);
                    }
                }
            }
        }
Exemplo n.º 19
0
        public static int Loyc_Collections()
        {
            // Test with small node sizes as well as the standard node size,
            // including the minimum size of 3 (the most problematic size).
            int seed = 237588399;

            return(MiniTest.RunTests.RunMany(
                       new SimpleCacheTests(),
                       new InvertibleSetTests(),
                       new AListTests(false, seed, 8, 8),
                       new BListTests(false, seed, 3, 3),
                       new BDictionaryTests(false, seed, 6, 6),
                       new SparseAListTests(false, seed, 10, 10),
                       new DequeTests <AList <int> >(delegate() { return new AList <int>(); }),
                       new DequeTests <SparseAList <int> >(delegate() { return new SparseAList <int>(); }),
                       new DictionaryTests <BDictionary <object, object> >(true, true),
                       new ListTests <AList <int> >(false, delegate(int n) { var l = new AList <int>(); l.Resize(n); return l; }),
                       new ListRangeTests <AList <int> >(false, delegate() { return new AList <int>(); }, 12345),
                       new ListTests <SparseAList <int> >(false, delegate(int n) { var l = new SparseAList <int>(); l.Resize(n); return l; }, 12345),
                       new ListRangeTests <SparseAList <int> >(false, delegate() { return new SparseAList <int>(); }, 12345),
                       new WListTests(),
                       new FWListTests(),
                       new VListTests(),
                       new FVListTests(),
                       new MapTests(),
                       new SparseAListTests(true, seed, 8, 4),
                       new SparseAListTests(),
                       new AListTests(),
                       new BListTests(),
                       new BDictionaryTests(),
                       new MSetTests(),        // derived from MutableSetTests<MSet<STI>, STI>
                       new SymbolSetTests(),   // derived from MutableSetTests<MSet<Symbol>, Symbol>
                       new ImmSetTests(),      // tests for Set<T>
                       new MapTests()          // derived from DictionaryTests<MMap<object, object>>
                       ));
        }
Exemplo n.º 20
0
 public override SparseAList <int> CopySection(SparseAList <int> alist, int start, int subcount)
 {
     return(alist.CopySection(start, subcount));
 }
Exemplo n.º 21
0
		public static void Main(string[] args)
		{
			// Workaround for MS bug: Assert(false) will not fire in debugger
			Debug.Listeners.Clear();
			Debug.Listeners.Add( new DefaultTraceListener() );

			Console.WriteLine("Running tests on stable code...");
			// Omitted: unit tests that throw & catch exceptions (those are below)

			// Loyc.Essentials
			RunTests.Run(new ListExtTests());
			RunTests.Run(new MathExTests());
			RunTests.Run(new UStringTests());
			RunTests.Run(new StringExtTests());
			RunTests.Run(new HashTagsTests());
			RunTests.Run(new LocalizeTests());
			RunTests.Run(new SymbolTests());
			RunTests.Run(new ThreadExTests());
			RunTests.Run(new ListTests<InternalList<int>>(false, delegate(int n) { var l = InternalList<int>.Empty; l.Resize(n); return l; }));
			RunTests.Run(new ListRangeTests<InternalList<int>>(false, delegate() { return InternalList<int>.Empty; }));
			RunTests.Run(new ListTests<DList<int>>(false, delegate(int n) { var l = new DList<int>(); l.Resize(n); return l; }));
			RunTests.Run(new DequeTests<DList<int>>(delegate() { return new DList<int>(); }));
			RunTests.Run(new ListRangeTests<DList<int>>(false, delegate() { return new DList<int>(); }));

			// Loyc.Collections
			RunTests.Run(new CPTrieTests());
			RunTests.Run(new SimpleCacheTests());
			RunTests.Run(new InvertibleSetTests());
			// Test with small node sizes as well as the standard node size,
			// including the minimum size of 3 (the most problematic size).
			int seed = 237588399;
			RunTests.Run(new AListTests(false, seed, 8, 8));
			RunTests.Run(new BListTests(false, seed, 3, 3));
			RunTests.Run(new BDictionaryTests(false, seed, 6, 6));
			RunTests.Run(new SparseAListTests(false, seed, 10, 10));
			RunTests.Run(new DequeTests<AList<int>>(delegate() { return new AList<int>(); }));
			RunTests.Run(new DequeTests<SparseAList<int>>(delegate() { return new SparseAList<int>(); }));
			RunTests.Run(new DictionaryTests<BDictionary<object, object>>(true, true));
			RunTests.Run(new ListTests<AList<int>>(false, delegate(int n) { var l = new AList<int>(); l.Resize(n); return l; }));
			RunTests.Run(new ListRangeTests<AList<int>>(false, delegate() { return new AList<int>(); }, 12345));
			RunTests.Run(new ListTests<SparseAList<int>>(false, delegate(int n) { var l = new SparseAList<int>(); l.Resize(n); return l; }, 12345));
			RunTests.Run(new ListRangeTests<SparseAList<int>>(false, delegate() { return new SparseAList<int>(); }, 12345));

			// Loyc.Syntax
			RunTests.Run(new TokenTests());
			RunTests.Run(new LesLexerTests());
			RunTests.Run(new LesParserTests());
			RunTests.Run(new LesPrinterTests());
			RunTests.Run(new TokensToTreeTests());
			RunTests.Run(new StreamCharSourceTests());
			RunTests.Run(new LexerSourceTests_Calculator());
			RunTests.Run(new ParserSourceTests_Calculator());
			RunTests.Run(new IndentTokenGeneratorTests());

			// Loyc.Utilities
			RunTests.Run(new LineMathTests());
			RunTests.Run(new PointMathTests());
			RunTests.Run(new Loyc.LLParserGenerator.IntSetTests());
			RunTests.Run(new TagsInWListTests());
			RunTests.Run(new UGTests());

			for(;;) {
				ConsoleKeyInfo k;

				Console.WriteLine();
				Console.WriteLine("What do you want to do?");
				Console.WriteLine("1. Run unit tests that expect exceptions");
				Console.WriteLine("2. Run unit tests on unstable code");
				Console.WriteLine("9. Benchmarks");
				Console.WriteLine("Z. List encodings");
				Console.WriteLine("Press ESC or ENTER to Quit");
				Console.WriteLine((k = Console.ReadKey(true)).KeyChar);
				if (k.Key == ConsoleKey.Escape || k.Key == ConsoleKey.Enter)
					break;
				else if (k.KeyChar == '1') {
					// Loyc.Essentials
					RunTests.Run(new GTests());
					
					// Loyc.Utilities
					RunTests.Run(new GoInterfaceTests());
					
					// Loyc.Collections
					RunTests.Run(new RWListTests()); 
					RunTests.Run(new WListTests());
					RunTests.Run(new RVListTests());
					RunTests.Run(new VListTests());
					RunTests.Run(new MapTests());
					RunTests.Run(new SparseAListTests(true, seed, 8, 4));
					RunTests.Run(new SparseAListTests());
					RunTests.Run(new AListTests());
					RunTests.Run(new BListTests());
					RunTests.Run(new BDictionaryTests());
					RunTests.Run(new MSetTests()); // derived from MutableSetTests<MSet<STI>, STI>
					RunTests.Run(new SymbolSetTests()); // derived from MutableSetTests<MSet<Symbol>, Symbol>
					RunTests.Run(new ImmSetTests()); // tests for Set<T>
					RunTests.Run(new MapTests()); // derived from DictionaryTests<MMap<object, object>>
				} else if (k.KeyChar == '2') {
					RunTests.Run(new KeylessHashtableTests());
				} else if (k.KeyChar == 'z' || k.KeyChar == 'Z') {
					foreach (EncodingInfo inf in Encoding.GetEncodings())
						Console.WriteLine("{0} {1}: {2}", inf.CodePage, inf.Name, inf.DisplayName);
				}
			}
		}
Exemplo n.º 22
0
		public static void Loyc_Collections()
		{
			MiniTest.RunTests.Run(new CPTrieTests());
			MiniTest.RunTests.Run(new SimpleCacheTests());
			MiniTest.RunTests.Run(new InvertibleSetTests());
			// Test with small node sizes as well as the standard node size,
			// including the minimum size of 3 (the most problematic size).
			int seed = 237588399;
			MiniTest.RunTests.Run(new AListTests(false, seed, 8, 8));
			MiniTest.RunTests.Run(new BListTests(false, seed, 3, 3));
			MiniTest.RunTests.Run(new BDictionaryTests(false, seed, 6, 6));
			MiniTest.RunTests.Run(new SparseAListTests(false, seed, 10, 10));
			MiniTest.RunTests.Run(new DequeTests<AList<int>>(delegate() { return new AList<int>(); }));
			MiniTest.RunTests.Run(new DequeTests<SparseAList<int>>(delegate() { return new SparseAList<int>(); }));
			MiniTest.RunTests.Run(new DictionaryTests<BDictionary<object, object>>(true, true));
			MiniTest.RunTests.Run(new ListTests<AList<int>>(false, delegate(int n) { var l = new AList<int>(); l.Resize(n); return l; }));
			MiniTest.RunTests.Run(new ListRangeTests<AList<int>>(false, delegate() { return new AList<int>(); }, 12345));
			MiniTest.RunTests.Run(new ListTests<SparseAList<int>>(false, delegate(int n) { var l = new SparseAList<int>(); l.Resize(n); return l; }, 12345));
			MiniTest.RunTests.Run(new ListRangeTests<SparseAList<int>>(false, delegate() { return new SparseAList<int>(); }, 12345));
			MiniTest.RunTests.Run(new RWListTests());
			MiniTest.RunTests.Run(new WListTests());
			MiniTest.RunTests.Run(new RVListTests());
			MiniTest.RunTests.Run(new VListTests());
			MiniTest.RunTests.Run(new MapTests());
			MiniTest.RunTests.Run(new SparseAListTests(true, seed, 8, 4));
			MiniTest.RunTests.Run(new SparseAListTests());
			MiniTest.RunTests.Run(new AListTests());
			MiniTest.RunTests.Run(new BListTests());
			MiniTest.RunTests.Run(new BDictionaryTests());
			MiniTest.RunTests.Run(new MSetTests()); // derived from MutableSetTests<MSet<STI>, STI>
			MiniTest.RunTests.Run(new SymbolSetTests()); // derived from MutableSetTests<MSet<Symbol>, Symbol>
			MiniTest.RunTests.Run(new ImmSetTests()); // tests for Set<T>
			MiniTest.RunTests.Run(new MapTests()); // derived from DictionaryTests<MMap<object, object>>
			MiniTest.RunTests.Run(new KeylessHashtableTests());
		}