Changeset 16159


Ignore:
Timestamp:
09/20/18 13:18:47 (13 months ago)
Author:
bburlacu
Message:

#2886: Refactor unit test using only C# 4.5 features.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2886_SymRegGrammarEnumeration/Test/TreeHashingTest.cs

    r16157 r16159  
    153153      //const int nvars = 1;
    154154      //var variables = Enumerable.Range(1, nvars).Select(x => $"x{x}").ToArray();
    155       var variables = new[] { "b", "a" };
     155      var variables = new[] { "x", "y", "z", "w" };
    156156      var grammar = new Grammar(variables, Enum.GetValues(typeof(GrammarRule)).Cast<GrammarRule>());
    157157
    158       int hash(SymbolList s) => grammar.Hasher.CalcHashCode(s);
     158      Func<SymbolList, int> hash = s => grammar.Hasher.CalcHashCode(s);
    159159
    160160      List<SymbolList> sentences = EnumerateGrammarBreadth(grammar, length: 20, hashPhrases: false).ToList();
    161       Console.WriteLine($"Breadth: {sentences.Count};{sentences.Select(hash).Distinct().Count() }");
     161      Console.WriteLine("Breadth: {0} generated, {1} distinct sentences", sentences.Count, sentences.GroupBy(hash).Count());
    162162
    163163      sentences = EnumerateGrammarBreadth(grammar, length: 20, hashPhrases: true).ToList();
    164       Console.WriteLine($"Breadth (hashed): {sentences.Count};{sentences.Select(hash).Distinct().Count() }");
     164      Console.WriteLine("Breadth (hashed): {0} generated, {1} distinct sentences", sentences.Count, sentences.GroupBy(hash).Count());
    165165
    166166      sentences = EnumerateGrammarDepth(grammar, length: 20, hashPhrases: false).ToList();
    167       Console.WriteLine($"Depth: {sentences.Count};{sentences.Select(hash).Distinct().Count() }");
     167      Console.WriteLine("Depth: {0} generated, {1} distinct sentences", sentences.Count, sentences.GroupBy(hash).Count());
    168168
    169169      sentences = EnumerateGrammarDepth(grammar, length: 20, hashPhrases: true).ToList();
    170       Console.WriteLine($"Depth (hashed): {sentences.Count};{sentences.Select(hash).Distinct().Count() }");
     170      Console.WriteLine("Depth (hashed): {0} generated, {1} distinct sentences", sentences.Count, sentences.GroupBy(hash).Count());
    171171    }
    172172
Note: See TracChangeset for help on using the changeset viewer.