PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Excel.Expressions.Test/Test8 (2).cs

#
C# | 363 lines | 236 code | 35 blank | 92 comment | 8 complexity | e46b7508fc51cbbedb1e71fbc1230489 MD5 | raw file
  1. using System.Diagnostics;
  2. using System.Globalization;
  3. using Excel.Expressions.Compiler;
  4. using Expressions.Compiler;
  5. using Expressions.Compiler.Interfaces;
  6. using Microsoft.VisualStudio.TestTools.UnitTesting;
  7. using Excel.Expressions.Interfaces;
  8. namespace Tests
  9. {
  10. /// <summary>
  11. ///This is a test class for Test8_ and is intended
  12. ///to contain all Test8_ Unit Tests
  13. ///</summary>
  14. [TestClass()]
  15. public class Test8__
  16. {
  17. private TestContext testContextInstance;
  18. /// <summary>
  19. ///Gets or sets the test context which provides
  20. ///information about and functionality for the current test run.
  21. ///</summary>
  22. public TestContext TestContext
  23. {
  24. get
  25. {
  26. return testContextInstance;
  27. }
  28. set
  29. {
  30. testContextInstance = value;
  31. }
  32. }
  33. #region Additional test attributes
  34. //
  35. //You can use the following additional attributes as you write your tests:
  36. //
  37. //Use ClassInitialize to run code before running the first test in the class
  38. //[ClassInitialize()]
  39. //public static void MyClassInitialize(TestContext testContext)
  40. //{
  41. //}
  42. //
  43. //Use ClassCleanup to run code after all tests in a class have run
  44. //[ClassCleanup()]
  45. //public static void MyClassCleanup()
  46. //{
  47. //}
  48. //
  49. //Use TestInitialize to run code before running each test
  50. //[TestInitialize()]
  51. //public void MyTestInitialize()
  52. //{
  53. //}
  54. //
  55. //Use TestCleanup to run code after each test has run
  56. //[TestCleanup()]
  57. //public void MyTestCleanup()
  58. //{
  59. //}
  60. //
  61. #endregion
  62. private static Parser CreateGrammar()
  63. {
  64. Nonterminal G = "G";
  65. G.Definition = new Rules()
  66. {
  67. () => "5.25"
  68. };
  69. Parser input = "5.25";
  70. G.Initialize();
  71. G.Validate();
  72. G.Parse(input);
  73. return input;
  74. }
  75. /// <summary>
  76. ///A test for Terminal Constructor
  77. ///</summary>
  78. [TestMethod(), Conditional("DEBUG")]
  79. public void Test8_1()
  80. {
  81. string ch = string.Empty;
  82. Terminal expected = Terminal.Null;
  83. Terminal actual = ch;
  84. Assert.AreEqual(expected, actual);
  85. }
  86. /// <summary>
  87. ///A test for Parse
  88. ///</summary>
  89. [TestMethod(), Conditional("DEBUG")]
  90. public void Test8_2()
  91. {
  92. char ch = ')';
  93. Terminal target = ch;
  94. Parser input = ")";
  95. bool expected = true;
  96. bool actual;
  97. actual = target.Parse(input) == true;
  98. Assert.AreEqual(expected, actual);
  99. }
  100. /// <summary>
  101. ///A test for ToString
  102. ///</summary>
  103. [TestMethod(), Conditional("DEBUG")]
  104. public void Test8_3()
  105. {
  106. char ch = ')';
  107. Terminal target = ch;
  108. string expected = ")";
  109. string actual;
  110. actual = target.Name;
  111. Assert.AreEqual(expected, actual);
  112. }
  113. /// <summary>
  114. ///A test for op_Implicit
  115. ///</summary>
  116. [TestMethod(), Conditional("DEBUG")]
  117. public void Test8_4()
  118. {
  119. Terminal terminal = '(';
  120. string expected = "(";
  121. string actual;
  122. actual = terminal.Name;
  123. Assert.AreEqual(expected, actual);
  124. }
  125. /// <summary>
  126. ///A test for null
  127. ///</summary>
  128. [TestMethod(), Conditional("DEBUG")]
  129. public void Test8_7()
  130. {
  131. string ch = null;
  132. Terminal terminal = ((Terminal)ch)[true];
  133. string expected = "(|)";
  134. string actual = terminal.Name;
  135. Assert.AreEqual(expected, actual);
  136. }
  137. /// <summary>
  138. ///A test for null
  139. ///</summary>
  140. [TestMethod(), Conditional("DEBUG")]
  141. public void Test8_20()
  142. {
  143. string key = Terminal.Null.ToString();
  144. Terminal terminal = ((Terminal)key)[true];
  145. string expected = "(|)";
  146. string actual = terminal.Name;
  147. Assert.AreEqual(expected, actual);
  148. }
  149. /// <summary>
  150. ///A test for null
  151. ///</summary>
  152. [TestMethod(), Conditional("DEBUG")]
  153. public void Test8_8()
  154. {
  155. string ch = null;
  156. string key = Terminal.Null.ToString();
  157. Parser text = (Parser)ch;
  158. Terminal terminal = ((Terminal)ch)[true];
  159. text = "(|)";
  160. string expected = "(|)";
  161. string actual = terminal.Name;
  162. Assert.AreEqual(expected, actual);
  163. }
  164. /// <summary>
  165. ///A test for null
  166. ///</summary>
  167. [TestMethod(), Conditional("DEBUG")]
  168. public void Test8_9()
  169. {
  170. string ch = "(|)";
  171. string key = Terminal.Null.ToString();
  172. Parser text = (Parser)null;
  173. Terminal terminal = ((Terminal)ch)[true];
  174. text = "(|)";
  175. Nonterminal G = "G";
  176. G.Definition = new Rules
  177. {
  178. () => '(' + Terminal.Null.ToString()
  179. };
  180. bool expected = false;
  181. G.Initialize();
  182. G.Validate();
  183. bool actual = G.Parse(text);
  184. Assert.AreEqual(expected, actual);
  185. }
  186. /// <summary>
  187. ///A test for null
  188. ///</summary>
  189. [TestMethod(), Conditional("DEBUG")]
  190. public void Test8_10()
  191. {
  192. string key = Terminal.Null.ToString();
  193. Parser text = null;
  194. string expected = null;
  195. string actual = (string)text;
  196. Assert.AreEqual(expected, actual);
  197. }
  198. /// <summary>
  199. ///A test for null
  200. ///</summary>
  201. [TestMethod(), Conditional("DEBUG")]
  202. public void Test8_11()
  203. {
  204. string key = "uiop";
  205. Parser text = key;
  206. text.Close();
  207. bool expected = true;
  208. bool actual = text.Tree == null;
  209. Assert.AreEqual(expected, actual);
  210. }
  211. /// <summary>
  212. ///A test for null
  213. ///</summary>
  214. [TestMethod(), Conditional("DEBUG")]
  215. public void Test8_12()
  216. {
  217. Parser text = "uiop";
  218. Terminal u = Terminal.Null;
  219. string expected = Terminal.Null.ToString();
  220. string actual = u.Value;
  221. Assert.AreEqual(expected, actual);
  222. }
  223. /// <summary>
  224. ///A test for null
  225. ///</summary>
  226. [TestMethod(), Conditional("DEBUG")]
  227. public void Test8_13()
  228. {
  229. Parser text = "uiop";
  230. Terminal u = "uiop";
  231. string expected = "uiop";
  232. string actual = u.Value;
  233. Assert.AreEqual(expected, actual);
  234. }
  235. /// <summary>
  236. ///A test for null
  237. ///</summary>
  238. [TestMethod(), Conditional("DEBUG")]
  239. public void Test8_14()
  240. {
  241. Parser text = "(|)";
  242. string expected = "(|)";
  243. string actual = text.ToString();
  244. Assert.AreEqual(expected, actual);
  245. }
  246. /// <summary>
  247. ///A test for null
  248. ///</summary>
  249. [TestMethod(), Conditional("DEBUG")]
  250. public void Test8_15()
  251. {
  252. Parser input = CreateGrammar();
  253. Number text = new Number(input.Tree[0].Context.ToString());
  254. bool expected = true;
  255. bool actual = text == 5.25;
  256. Assert.AreEqual(expected, actual);
  257. }
  258. /// <summary>
  259. ///A test for null
  260. ///</summary>
  261. [TestMethod()]
  262. public void Test8_16()
  263. {
  264. string value = "5.25";
  265. Parser input = CreateGrammar();
  266. Number text = new Number(input.Tree[0].Context.ToString());
  267. bool expected = true;
  268. bool actual = string.Compare(text.Eval().ToString(CultureInfo.InvariantCulture), value) == 0;
  269. Assert.AreEqual(expected, actual);
  270. }
  271. /// <summary>
  272. ///A test for null
  273. ///</summary>
  274. [TestMethod(), Conditional("DEBUG")]
  275. public void Test8_17()
  276. {
  277. Parser input = CreateGrammar();
  278. Number a = new Number(input.Tree[0].Context.ToString());
  279. Number b = new Number(input.Tree[0].Context.ToString());
  280. Plus add = new Plus(a, b);
  281. bool expected = true;
  282. bool actual = a + b == add;
  283. Assert.AreEqual(expected, actual);
  284. }
  285. /// <summary>
  286. ///A test for null
  287. ///</summary>
  288. [TestMethod(), Conditional("DEBUG")]
  289. public void Test9_18()
  290. {
  291. Parser input = CreateGrammar();
  292. Number a = new Number(input.Tree[0].Context.ToString());
  293. Number b = new Number(input.Tree[0].Context.ToString());
  294. Minus sub = new Minus(a, b);
  295. bool expected = true;
  296. bool actual = a - b == sub;
  297. Assert.AreEqual(expected, actual);
  298. }
  299. /// <summary>
  300. ///A test for null
  301. ///</summary>
  302. [TestMethod(), Conditional("DEBUG")]
  303. public void Test9_19()
  304. {
  305. Parser input = CreateGrammar();
  306. Number a = new Number(input.Tree[0].Context.ToString());
  307. Number b = new Number(input.Tree[0].Context.ToString());
  308. Mul mul = new Mul(a, b);
  309. bool expected = true;
  310. bool actual = a * b == mul;
  311. Assert.AreEqual(expected, actual);
  312. }
  313. /// <summary>
  314. ///A test for null
  315. ///</summary>
  316. [TestMethod(), Conditional("DEBUG")]
  317. public void Test9_20()
  318. {
  319. Parser input = CreateGrammar();
  320. Number a = new Number(input.Tree[0].Context.ToString());
  321. Number b = new Number(input.Tree[0].Context.ToString());
  322. Div div = new Div(a, b);
  323. bool expected = true;
  324. bool actual = a / b == div;
  325. Assert.AreEqual(expected, actual);
  326. }
  327. }
  328. }