コード例 #1
0
        public void Test0()
        {
            var intArrows =
                new []
                {
                    new IntArrow<int>(0, 10),
                    new IntArrow<int>(2, 20),
                    new IntArrow<int>(5, 10, 30),
                };

            const int DefaultValue = -1;

            var target = new BinaryDecisionTreeBuilder(DefaultValue, platformInfo);
            var node = target.Build(intArrows);
            PrintProgram(node);

            Assert.AreEqual(DefaultValue, Eval(node, -1));
            Assert.AreEqual(10, Eval(node, 0));
            Assert.AreEqual(DefaultValue, Eval(node, 1));
            Assert.AreEqual(20, Eval(node, 2));
            Assert.AreEqual(DefaultValue, Eval(node, 3));
            Assert.AreEqual(DefaultValue, Eval(node, 4));
            Assert.AreEqual(30, Eval(node, 5));
            Assert.AreEqual(30, Eval(node, 10));
            Assert.AreEqual(DefaultValue, Eval(node, 11));
        }
コード例 #2
0
        public void SingleValueInterval()
        {
            var intArrows =
                new []
                {
                    new IntArrow<int>(0, 10),
                };

            const int DefaultValue = -1;

            var target = new BinaryDecisionTreeBuilder(DefaultValue, platformInfo);
            var node = target.Build(intArrows);
            PrintProgram(node);

            Assert.AreEqual(DefaultValue, Eval(node, -1));
            Assert.AreEqual(10, Eval(node, 0));
            Assert.AreEqual(DefaultValue, Eval(node, 1));
        }
コード例 #3
0
        protected override void DoBuild(
            EmitSyntax            emit,
            Pipe<EmitSyntax>      ldvalue,
            SwitchGeneratorAction action)
        {
            this.action = action;

            #if false
            var decisionTree = new BinaryDecisionTreeBuilder(intMap.DefaultValue, platformInfo);
            var node = decisionTree.Build(intMap.Enumerate().ToArray());
            #else
            this.builder = new DecisionTreeBuilder(platformInfo);
            var node = builder.Build(
                    intMap,
                    possibleBounds,
                    frequency);
            #endif
            this.emit = emit;
            this.ldvalue = ldvalue;
            this.labels = new List<Ref<Labels>>();

            strategy.PlanCode(node);
            strategy.GenerateCode();

            // Debug.Write(node);
        }