示例#1
0
        // [Fact]
        // public void Foo()
        // {
        //     var number = BigInteger.Parse("1");
        //     var program = CodifierHelpers.UncodifyProgram(number);
        //     throw new System.Exception(program);
        // }

        private void AssertEqualCodified(string inputProgram, string expectedResult)
        {
            Framework.TryAnalyze(
                inputProgram,
                out string _,
                out ProgramNode program,
                out IEnumerable <Message> _);

            var number = Codifier.Codify(program);

            var expected = BigInteger.Parse(expectedResult);

            Assert.Equal(expected, number);

            if (expected == 0)
            {
                // The uncodified instruction [E] Y = Y may not equal passed one
                // but both are actually the same
                return;
            }

            var uncodifiedProgram = Codifier.UncodifyProgram(number);

            Assert.Equal(
                inputProgram,
                uncodifiedProgram.Replace("\n", " "));
        }
示例#2
0
        private void AssertEqualCodifiedFormat(
            InstructionNode instruction,
            int expectedResult)
        {
            var number = Codifier.CodifyFormat(instruction);

            Assert.Equal(expectedResult, number);
        }
示例#3
0
        public void ConditionalInstructionFormat()
        {
            const string rawLabel = "A";

            var instruction   = new ConditionalInstructionNode("X", rawLabel, 0);
            var label         = new Label(rawLabel);
            var codifiedLabel = Codifier.Codify(label);

            AssertEqualCodifiedFormat(instruction, codifiedLabel + 2);
        }
示例#4
0
        public void Label(string rawLabel, int expectedResult)
        {
            var label = new Label(rawLabel);

            var number = Codifier.Codify(label);

            Assert.Equal(expectedResult, number);

            var uncodifiedLabel = Codifier.UncodifyLabel(number);

            Assert.Equal(label, uncodifiedLabel);
        }
示例#5
0
        private void AssertEqualCodified(
            InstructionNode instruction,
            int expectedResult)
        {
            var number = Codifier.Codify(instruction);

            Assert.Equal(expectedResult, number);

            var uncodifiedInstruction = Codifier.UncodifyInstruction(number);

            Assert.Equal(instruction.ToString(), uncodifiedInstruction.ToString());
        }
示例#6
0
        public void Variable(string rawVar, int expectedResult)
        {
            var var = new Var(rawVar);

            var number = Codifier.Codify(var);

            Assert.Equal(expectedResult, number);

            var uncodifiedVar = Codifier.UncodifyVar(number);

            Assert.Equal(var, uncodifiedVar);
        }