コード例 #1
0
ファイル: CodifierTests.cs プロジェクト: MarcosCobena/GoTo
        // [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
ファイル: CodifierTests.cs プロジェクト: MarcosCobena/GoTo
        private void AssertEqualCodifiedFormat(
            InstructionNode instruction,
            int expectedResult)
        {
            var number = Codifier.CodifyFormat(instruction);

            Assert.Equal(expectedResult, number);
        }
コード例 #3
0
ファイル: CodifierTests.cs プロジェクト: MarcosCobena/GoTo
        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
ファイル: CodifierTests.cs プロジェクト: MarcosCobena/GoTo
        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
ファイル: CodifierTests.cs プロジェクト: MarcosCobena/GoTo
        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
ファイル: CodifierTests.cs プロジェクト: MarcosCobena/GoTo
        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);
        }