Example #1
0
        public string GenerateFullTestSuite(List <BehaviourTestSuite> profileTests, List <AspectTestSuite> aspectTests, bool invertPriority = false)
        {
            _skeleton.AddDep("inv");
            _skeleton.AddDep("double_compare");


            var aspectTestSuite =
                string.Join("\n\n",
                            aspectTests
                            .Where(x => x != null)
                            .Select(
                                GenerateAspectTestSuite
                                ));

            var profileTestSuite =
                string.Join("\n\n",
                            profileTests
                            .Where(x => x != null)
                            .Select(
                                t => GenerateProfileTestSuite(t, invertPriority)
                                ));

            return(string.Join("\n\n\n", new List <string>
            {
                "function test_all()",
                "    " + aspectTestSuite.Indent(),
                "  -- Behaviour tests --",
                "    " + profileTestSuite.Indent(),
                "end"
            }));
        }
        public string ToLua()
        {
            _skeleton.AddDep("spoken_instructions");

            var(membershipFunction, extraKeys)       = GenerateMembershipPreprocessor();
            var(profileOverview, behaviourFunctions) = GenerateProfileFunctions();
            var mainFunction = GenerateMainProfileFunction();
            var tests        = new LuaTestPrinter(_skeleton, new List <string> {
                "unitTest", "unitTestProfile"
            }).GenerateFullTestSuite(_profileTests, _aspectTestSuites);


            var keys = _profile.AllExpressions(_context).PossibleTags().Keys
                       .Concat(extraKeys)
                       .Select(key => "\"" + key + "\"")
                       .ToHashSet();

            var header = new List <string>
            {
                $"-- Itinero 1.0-profile, generated by AspectedRouting.",
                $"name = \"{_profile.Name}\"",
                "normalize = false",
                "vehicle_types = {" + string.Join(", ", _profile.VehicleTyps.Select(s => "\"" + s + "\"")) + "}",
                // meta_whitelist is defined in the profile file, these are tags that are included in the generated route, but are not relevant for determining weights
                "meta_whitelist = {\n"
                + string.Join("\n    , ", _profile.Metadata.Select(s => "\"" + s + "\""))
                + " }",
                "profile_whitelist = {\n      " + string.Join("\n    , ", keys) + "\n    }",
                "",
                "",
                "",
                profileOverview,
                "",
                _parameterPrinter.GenerateDefaultParameters()
            };


            // Add the aspect functions to the skeleton
            var usedFunctions = _profile.CalledFunctionsRecursive(_context).Values.SelectMany(v => v).ToHashSet();

            foreach (var functionName in usedFunctions)
            {
                _skeleton.AddFunction(_context.GetAspect(functionName));
            }


            // The dependencies should be generated after all the other functions are generated, to make sure all are added
            var dependencies = _skeleton.GenerateDependencies();
            var functions    = _skeleton.GenerateFunctions();

            var allCode = new List <List <string> >
            {
                header,
                behaviourFunctions,
                mainFunction.InList(),
                membershipFunction.InList(),
                "---------------------- ASPECTS ----------------------".InList(),
                functions,
                "---------------------- UTILS ------------------------".InList(),
                dependencies,
                _skeleton.GenerateConstants().ToList(),
                "----------------------- TESTS ------------------------".InList(),
                tests.InList(),
                GenerateLegacyTail().InList()
            };


            return(string.Join("\n\n\n", allCode.Select(code => string.Join("\n", code))));
        }