コード例 #1
0
 public void Rewriter_Empty_Empty()
 {
     var rules = new Dictionary<IResolverType, IEnumerable<IResolver>>();
     var linkedClass = MockRepository.GenerateStub<ILinkedLibrary>();
     var linker = new Linker(rules, linkedClass);
     Assert.That(linker.Rules.Any(), Is.False);
 }
コード例 #2
0
        public void Resolve_UnresolverIdentifier_Throw(string text)
        {
            var lexical = new LexicalAnalyzer(StandardProcessorBuilder.LexicalRules);
            var syntactic = new SyntacticAnalyzer(StandardProcessorBuilder.SyntacticRules);
            var translator = new Translator(StandardProcessorBuilder.TranslateRules);
            var linkedLibraryFactory = new StaticLinkedLibraryFactory(typeof(StandardProcessorBuilder.LinkedMath));
            var linker = new Linker(StandardProcessorBuilder.LinkerRules, linkedLibraryFactory.CreateLinkedLibrary());

            var tokens = lexical.Parse(text);
            var tree = syntactic.Parse(tokens, StandardProcessorBuilder.SyntacticTarget);
            var translatedTree = translator.Translate(tree);
            translator.CheckResult(translatedTree);
            linker.Resolve(translatedTree);

        }
コード例 #3
0
 public void Rewriter_SomeList_SameCount()
 {
     var rules = new Dictionary<IResolverType, IEnumerable<IResolver>>()
     {
         [MockRepository.GenerateStub<IResolverType>()] = new[]
         {
             MockRepository.GenerateStub<IResolver>(),
             MockRepository.GenerateStub<IResolver>()
         },
         [MockRepository.GenerateStub<IResolverType>()] = new[]
         {
             MockRepository.GenerateStub<IResolver>(),
         }
     };
     var linkedClass = MockRepository.GenerateStub<ILinkedLibrary>();
     var linker = new Linker(rules, linkedClass);
     Assert.That(linker.Rules.Count(), Is.EqualTo(2));
 }
コード例 #4
0
        public void Compile_Expressiion_RightResult(string text, double value)
        {
            var linkedLibraryFactory = new StaticLinkedLibraryFactory(typeof(StandardProcessorBuilder.LinkedMath));

            var lexical = new LexicalAnalyzer(StandardProcessorBuilder.LexicalRules);
            var syntactic = new SyntacticAnalyzer(StandardProcessorBuilder.SyntacticRules);
            var translator = new Translator(StandardProcessorBuilder.TranslateRules);
            var linker = new Linker(StandardProcessorBuilder.LinkerRules, 
                linkedLibraryFactory.CreateLinkedLibrary());
            var tokens = lexical.Parse(text);
            var tree = syntactic.Parse(tokens, StandardProcessorBuilder.SyntacticTarget);
            var translatedTree = translator.Translate(tree);
            translator.CheckResult(translatedTree);
            var linkedTree = linker.Resolve(translatedTree);
            linker.CheckResult(linkedTree);
            var compilator = new Compiler();
            var lambda = compilator.CreateExpression(linkedTree);
            var result = lambda.Compile()();
            Assert.That(result, Is.EqualTo(value).Within(1e-1));
        }
コード例 #5
0
 public void CheckResult_NonLinkedTermNode_ThrowException()
 {
     var rules = new Dictionary<IResolverType, IEnumerable<IResolver>>();
     var node = new TermSyntacticNode(
         MockRepository.GenerateStub<ITerm>(),
         Enumerable.Empty<ISyntacticNode>());
     var linkedClass = MockRepository.GenerateStub<ILinkedLibrary>();
     var linker = new Linker(rules, linkedClass);
     linker.CheckResult(node);
 }
コード例 #6
0
 public void Rewriter_Null_Null()
 {
     var linkedClass = MockRepository.GenerateStub<ILinkedLibrary>();
     var linker = new Linker(null, linkedClass);
 }
コード例 #7
0
 public void CheckResult_LinkedTermNode_DoesNotError()
 {
     var rules = new Dictionary<IResolverType, IEnumerable<IResolver>>();
     var node = new TermSyntacticNode(
         MockRepository.GenerateStub<IResolvedTerm>(),
         Enumerable.Empty<ISyntacticNode>());
     var linkedClass = MockRepository.GenerateStub<ILinkedLibrary>();
     var linker = new Linker(rules, linkedClass);
     Assert.DoesNotThrow(() => linker.CheckResult(node));
 }