jungerl /lib/otp.net/UnitTest/UnitTest1.cs

Language C# Lines 183
MD5 Hash f7ebbf367c49bbb4d18cd8088c68d493 Estimated Cost $3,608 (why?)
Repository https://github.com/gebi/jungerl.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Otp;

namespace Otp
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        public UnitTest1()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestFormat()
        {
            {
                Erlang.Object obj1 = Erlang.Object.Format("a");
                Assert.IsInstanceOfType(obj1, typeof(Erlang.Atom));
                Assert.AreEqual("a", (obj1 as Erlang.Atom).atomValue());
            }
            {
                Erlang.Object obj1 = Erlang.Object.Format("$a");
                Assert.IsInstanceOfType(obj1, typeof(Erlang.Char));
                Assert.AreEqual('a', (obj1 as Erlang.Char).charValue());
            }
            {
                Erlang.Object obj1 = Erlang.Object.Format("'Abc'");
                Assert.IsInstanceOfType(obj1, typeof(Erlang.Atom));
                Assert.AreEqual("Abc", (obj1 as Erlang.Atom).atomValue());
            }
            {
                Erlang.Object obj1 = Erlang.Object.Format("\"Abc\"");
                Assert.IsInstanceOfType(obj1, typeof(Erlang.String));
                Assert.AreEqual("Abc", (obj1 as Erlang.String).stringValue());
            }
            {
                Erlang.Object obj1 = Erlang.Object.Format("Abc");
                Assert.IsInstanceOfType(obj1, typeof(Erlang.Var));
                Assert.AreEqual("Abc", (obj1 as Erlang.Var).name());
            }
            {
                Erlang.Object obj1 = Erlang.Object.Format("1");
                Assert.IsInstanceOfType(obj1, typeof(Erlang.Long));
                Assert.AreEqual(1, (obj1 as Erlang.Long).longValue());
            }
            {
                Erlang.Object obj1 = Erlang.Object.Format("1.23");
                Assert.IsInstanceOfType(obj1, typeof(Erlang.Double));
                Assert.AreEqual(1.23, (obj1 as Erlang.Double).doubleValue());
            }
            {
                Erlang.Object obj1 = Erlang.Object.Format("V");
                Assert.IsInstanceOfType(obj1, typeof(Erlang.Var));
                Assert.AreEqual("V", (obj1 as Erlang.Var).name());
            }
            {
                Erlang.Object obj1 = Erlang.Object.Format("{1}");
                Assert.IsInstanceOfType(obj1, typeof(Erlang.Tuple));
                Assert.AreEqual(1, (obj1 as Erlang.Tuple).arity());
                Assert.IsInstanceOfType((obj1 as Erlang.Tuple)[0], typeof(Erlang.Long));
                Assert.AreEqual(1, ((obj1 as Erlang.Tuple)[0] as Erlang.Long).longValue());
            }
            {
                Erlang.Object obj0 = Erlang.Object.Format("[]");
                Assert.IsInstanceOfType(obj0, typeof(Erlang.List));
                Assert.AreEqual(0, (obj0 as Erlang.List).arity());
                Erlang.Object obj1 = Erlang.Object.Format("[1]");
                Assert.IsInstanceOfType(obj1, typeof(Erlang.List));
                Assert.AreEqual(1, (obj1 as Erlang.List).arity());
                Assert.IsInstanceOfType((obj1 as Erlang.List)[0], typeof(Erlang.Long));
                Assert.AreEqual(1, ((obj1 as Erlang.List)[0] as Erlang.Long).longValue());
            }
            {
                Erlang.Object obj1 = Erlang.Object.Format("[{1,2}, []]");
                Assert.IsInstanceOfType(obj1, typeof(Erlang.List));
                Assert.AreEqual(2, (obj1 as Erlang.List).arity());
                Assert.IsInstanceOfType((obj1 as Erlang.List)[0], typeof(Erlang.Tuple));
                Assert.AreEqual(2, ((obj1 as Erlang.List)[0] as Erlang.Tuple).arity());
                Assert.AreEqual(0, ((obj1 as Erlang.List)[1] as Erlang.List).arity());
            }
            {
                Erlang.Object obj1 = Erlang.Object.Format("{a, [b, 1, 2.0, \"abc\"], {1, 2}}");
                Assert.IsInstanceOfType(obj1, typeof(Erlang.Tuple));
                Assert.AreEqual(3, (obj1 as Erlang.Tuple).arity());
            }
            {
                Erlang.Object obj1 = Erlang.Object.Format("~w", 1);
                Assert.IsInstanceOfType(obj1, typeof(Erlang.Long));
                Assert.AreEqual(1, (obj1 as Erlang.Long).longValue());
                Erlang.Object obj2 = Erlang.Object.Format("{~w, ~w,~w}", 1, 2, 3);
                Assert.IsInstanceOfType(obj2, typeof(Erlang.Tuple));
                Assert.AreEqual(3, (obj2 as Erlang.Tuple).arity());
                Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[0], typeof(Erlang.Long));
                Assert.AreEqual(1, ((obj2 as Erlang.Tuple)[0] as Erlang.Long).longValue());
                Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[1], typeof(Erlang.Long));
                Assert.AreEqual(2, ((obj2 as Erlang.Tuple)[1] as Erlang.Long).longValue());
                Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[2], typeof(Erlang.Long));
                Assert.AreEqual(3, ((obj2 as Erlang.Tuple)[2] as Erlang.Long).longValue());
            }
            {
                Erlang.Object obj2 = Erlang.Object.Format("{~w, ~w,~w,~w, ~w}", 1.0, 'a', "abc", 2, true);
                Assert.IsInstanceOfType(obj2, typeof(Erlang.Tuple));
                Assert.AreEqual(5, (obj2 as Erlang.Tuple).arity());
                Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[0], typeof(Erlang.Double));
                Assert.AreEqual(1.0, ((obj2 as Erlang.Tuple)[0] as Erlang.Double).doubleValue());
                Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[1], typeof(Erlang.Char));
                Assert.AreEqual('a', ((obj2 as Erlang.Tuple)[1] as Erlang.Char).charValue());
                Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[2], typeof(Erlang.String));
                Assert.AreEqual("abc", ((obj2 as Erlang.Tuple)[2] as Erlang.String).stringValue());
                Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[3], typeof(Erlang.Long));
                Assert.AreEqual(2, ((obj2 as Erlang.Tuple)[3] as Erlang.Long).longValue());
                Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[4], typeof(Erlang.Boolean));
                Assert.AreEqual(true, ((obj2 as Erlang.Tuple)[4] as Erlang.Boolean).booleanValue());
            }
        }
        [TestMethod]
        public void TestPatternMatch()
        {
            {
                Erlang.Object pattern = Erlang.Object.Format("{test, A, B, C}");
                Erlang.Object obj = Erlang.Object.Format("{test, 10, a, [1,2,3]}");

                Erlang.VarBind binding = new Otp.Erlang.VarBind();
                Assert.IsTrue(pattern.match(obj, binding));
                Assert.AreEqual(3, binding.Count);
                Assert.AreEqual(10, binding["A"].longValue());
                Assert.AreEqual("a", binding["B"].atomValue());
                Assert.AreEqual("[1,2,3]", binding["C"].ToString());
            }
        }
    }
}
Back to Top