PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/gebi/jungerl
C# | 182 lines | 147 code | 6 blank | 29 comment | 0 complexity | 9d1827956e8ee03a6b713ab2a30a4f3a MD5 | raw file
Possible License(s): AGPL-1.0, JSON, LGPL-2.1, BSD-3-Clause
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. using Otp;
  7. namespace Otp
  8. {
  9. /// <summary>
  10. /// Summary description for UnitTest1
  11. /// </summary>
  12. [TestClass]
  13. public class UnitTest1
  14. {
  15. public UnitTest1()
  16. {
  17. //
  18. // TODO: Add constructor logic here
  19. //
  20. }
  21. private TestContext testContextInstance;
  22. /// <summary>
  23. ///Gets or sets the test context which provides
  24. ///information about and functionality for the current test run.
  25. ///</summary>
  26. public TestContext TestContext
  27. {
  28. get
  29. {
  30. return testContextInstance;
  31. }
  32. set
  33. {
  34. testContextInstance = value;
  35. }
  36. }
  37. #region Additional test attributes
  38. //
  39. // You can use the following additional attributes as you write your tests:
  40. //
  41. // Use ClassInitialize to run code before running the first test in the class
  42. // [ClassInitialize()]
  43. // public static void MyClassInitialize(TestContext testContext) { }
  44. //
  45. // Use ClassCleanup to run code after all tests in a class have run
  46. // [ClassCleanup()]
  47. // public static void MyClassCleanup() { }
  48. //
  49. // Use TestInitialize to run code before running each test
  50. // [TestInitialize()]
  51. // public void MyTestInitialize() { }
  52. //
  53. // Use TestCleanup to run code after each test has run
  54. // [TestCleanup()]
  55. // public void MyTestCleanup() { }
  56. //
  57. #endregion
  58. [TestMethod]
  59. public void TestFormat()
  60. {
  61. {
  62. Erlang.Object obj1 = Erlang.Object.Format("a");
  63. Assert.IsInstanceOfType(obj1, typeof(Erlang.Atom));
  64. Assert.AreEqual("a", (obj1 as Erlang.Atom).atomValue());
  65. }
  66. {
  67. Erlang.Object obj1 = Erlang.Object.Format("$a");
  68. Assert.IsInstanceOfType(obj1, typeof(Erlang.Char));
  69. Assert.AreEqual('a', (obj1 as Erlang.Char).charValue());
  70. }
  71. {
  72. Erlang.Object obj1 = Erlang.Object.Format("'Abc'");
  73. Assert.IsInstanceOfType(obj1, typeof(Erlang.Atom));
  74. Assert.AreEqual("Abc", (obj1 as Erlang.Atom).atomValue());
  75. }
  76. {
  77. Erlang.Object obj1 = Erlang.Object.Format("\"Abc\"");
  78. Assert.IsInstanceOfType(obj1, typeof(Erlang.String));
  79. Assert.AreEqual("Abc", (obj1 as Erlang.String).stringValue());
  80. }
  81. {
  82. Erlang.Object obj1 = Erlang.Object.Format("Abc");
  83. Assert.IsInstanceOfType(obj1, typeof(Erlang.Var));
  84. Assert.AreEqual("Abc", (obj1 as Erlang.Var).name());
  85. }
  86. {
  87. Erlang.Object obj1 = Erlang.Object.Format("1");
  88. Assert.IsInstanceOfType(obj1, typeof(Erlang.Long));
  89. Assert.AreEqual(1, (obj1 as Erlang.Long).longValue());
  90. }
  91. {
  92. Erlang.Object obj1 = Erlang.Object.Format("1.23");
  93. Assert.IsInstanceOfType(obj1, typeof(Erlang.Double));
  94. Assert.AreEqual(1.23, (obj1 as Erlang.Double).doubleValue());
  95. }
  96. {
  97. Erlang.Object obj1 = Erlang.Object.Format("V");
  98. Assert.IsInstanceOfType(obj1, typeof(Erlang.Var));
  99. Assert.AreEqual("V", (obj1 as Erlang.Var).name());
  100. }
  101. {
  102. Erlang.Object obj1 = Erlang.Object.Format("{1}");
  103. Assert.IsInstanceOfType(obj1, typeof(Erlang.Tuple));
  104. Assert.AreEqual(1, (obj1 as Erlang.Tuple).arity());
  105. Assert.IsInstanceOfType((obj1 as Erlang.Tuple)[0], typeof(Erlang.Long));
  106. Assert.AreEqual(1, ((obj1 as Erlang.Tuple)[0] as Erlang.Long).longValue());
  107. }
  108. {
  109. Erlang.Object obj0 = Erlang.Object.Format("[]");
  110. Assert.IsInstanceOfType(obj0, typeof(Erlang.List));
  111. Assert.AreEqual(0, (obj0 as Erlang.List).arity());
  112. Erlang.Object obj1 = Erlang.Object.Format("[1]");
  113. Assert.IsInstanceOfType(obj1, typeof(Erlang.List));
  114. Assert.AreEqual(1, (obj1 as Erlang.List).arity());
  115. Assert.IsInstanceOfType((obj1 as Erlang.List)[0], typeof(Erlang.Long));
  116. Assert.AreEqual(1, ((obj1 as Erlang.List)[0] as Erlang.Long).longValue());
  117. }
  118. {
  119. Erlang.Object obj1 = Erlang.Object.Format("[{1,2}, []]");
  120. Assert.IsInstanceOfType(obj1, typeof(Erlang.List));
  121. Assert.AreEqual(2, (obj1 as Erlang.List).arity());
  122. Assert.IsInstanceOfType((obj1 as Erlang.List)[0], typeof(Erlang.Tuple));
  123. Assert.AreEqual(2, ((obj1 as Erlang.List)[0] as Erlang.Tuple).arity());
  124. Assert.AreEqual(0, ((obj1 as Erlang.List)[1] as Erlang.List).arity());
  125. }
  126. {
  127. Erlang.Object obj1 = Erlang.Object.Format("{a, [b, 1, 2.0, \"abc\"], {1, 2}}");
  128. Assert.IsInstanceOfType(obj1, typeof(Erlang.Tuple));
  129. Assert.AreEqual(3, (obj1 as Erlang.Tuple).arity());
  130. }
  131. {
  132. Erlang.Object obj1 = Erlang.Object.Format("~w", 1);
  133. Assert.IsInstanceOfType(obj1, typeof(Erlang.Long));
  134. Assert.AreEqual(1, (obj1 as Erlang.Long).longValue());
  135. Erlang.Object obj2 = Erlang.Object.Format("{~w, ~w,~w}", 1, 2, 3);
  136. Assert.IsInstanceOfType(obj2, typeof(Erlang.Tuple));
  137. Assert.AreEqual(3, (obj2 as Erlang.Tuple).arity());
  138. Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[0], typeof(Erlang.Long));
  139. Assert.AreEqual(1, ((obj2 as Erlang.Tuple)[0] as Erlang.Long).longValue());
  140. Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[1], typeof(Erlang.Long));
  141. Assert.AreEqual(2, ((obj2 as Erlang.Tuple)[1] as Erlang.Long).longValue());
  142. Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[2], typeof(Erlang.Long));
  143. Assert.AreEqual(3, ((obj2 as Erlang.Tuple)[2] as Erlang.Long).longValue());
  144. }
  145. {
  146. Erlang.Object obj2 = Erlang.Object.Format("{~w, ~w,~w,~w, ~w}", 1.0, 'a', "abc", 2, true);
  147. Assert.IsInstanceOfType(obj2, typeof(Erlang.Tuple));
  148. Assert.AreEqual(5, (obj2 as Erlang.Tuple).arity());
  149. Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[0], typeof(Erlang.Double));
  150. Assert.AreEqual(1.0, ((obj2 as Erlang.Tuple)[0] as Erlang.Double).doubleValue());
  151. Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[1], typeof(Erlang.Char));
  152. Assert.AreEqual('a', ((obj2 as Erlang.Tuple)[1] as Erlang.Char).charValue());
  153. Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[2], typeof(Erlang.String));
  154. Assert.AreEqual("abc", ((obj2 as Erlang.Tuple)[2] as Erlang.String).stringValue());
  155. Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[3], typeof(Erlang.Long));
  156. Assert.AreEqual(2, ((obj2 as Erlang.Tuple)[3] as Erlang.Long).longValue());
  157. Assert.IsInstanceOfType((obj2 as Erlang.Tuple)[4], typeof(Erlang.Boolean));
  158. Assert.AreEqual(true, ((obj2 as Erlang.Tuple)[4] as Erlang.Boolean).booleanValue());
  159. }
  160. }
  161. [TestMethod]
  162. public void TestPatternMatch()
  163. {
  164. {
  165. Erlang.Object pattern = Erlang.Object.Format("{test, A, B, C}");
  166. Erlang.Object obj = Erlang.Object.Format("{test, 10, a, [1,2,3]}");
  167. Erlang.VarBind binding = new Otp.Erlang.VarBind();
  168. Assert.IsTrue(pattern.match(obj, binding));
  169. Assert.AreEqual(3, binding.Count);
  170. Assert.AreEqual(10, binding["A"].longValue());
  171. Assert.AreEqual("a", binding["B"].atomValue());
  172. Assert.AreEqual("[1,2,3]", binding["C"].ToString());
  173. }
  174. }
  175. }
  176. }