PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Aplus/AplusCoreUnitTests/Dlr/Function/Dyadic/NonScalar/Replicate.cs

http://aplusdotnet.googlecode.com/
C# | 296 lines | 256 code | 40 blank | 0 comment | 0 complexity | 0a95a006d058e52fa7fbcda95fc55d0e MD5 | raw file
Possible License(s): 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 AplusCore.Runtime;
  7. using AplusCore.Types;
  8. using Microsoft.Scripting.Hosting;
  9. namespace AplusCoreUnitTests.Dlr.Function.Dyadic.NonScalar
  10. {
  11. [TestClass]
  12. public class Replicate : AbstractTest
  13. {
  14. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  15. public void ReplicateIntegerList2IntegerList()
  16. {
  17. AType expected = AArray.Create(
  18. ATypes.AInteger,
  19. AInteger.Create(1),
  20. AInteger.Create(1),
  21. AInteger.Create(4),
  22. AInteger.Create(4),
  23. AInteger.Create(4)
  24. );
  25. AType result = this.engine.Execute<AType>("2 3 0 / 1 4 8");
  26. Assert.AreEqual(expected, result);
  27. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  28. }
  29. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  30. public void ReplicateIntegerList2MatrixWithFrame()
  31. {
  32. AType expected = AArray.Create(
  33. ATypes.AInteger,
  34. AArray.Create(
  35. ATypes.AInteger,
  36. AArray.Create(
  37. ATypes.AInteger,
  38. AInteger.Create(0),
  39. AInteger.Create(1),
  40. AInteger.Create(2)
  41. ),
  42. AArray.Create(
  43. ATypes.AInteger,
  44. AInteger.Create(3),
  45. AInteger.Create(4),
  46. AInteger.Create(5)
  47. )
  48. )
  49. );
  50. AType result = this.engine.Execute<AType>("1 0 / iota 2 2 3");
  51. Assert.AreEqual(expected, result);
  52. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  53. }
  54. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  55. public void ReplicateIntegerList2Integer()
  56. {
  57. AType expected = AArray.Create(
  58. ATypes.AInteger,
  59. AInteger.Create(0),
  60. AInteger.Create(0),
  61. AInteger.Create(0),
  62. AInteger.Create(0),
  63. AInteger.Create(0)
  64. );
  65. AType result = this.engine.Execute<AType>("2 3 / iota 1");
  66. Assert.AreEqual(expected, result);
  67. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  68. }
  69. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  70. public void ReplicateInteger2Matrix()
  71. {
  72. AType expected = AArray.Create(
  73. ATypes.AInteger,
  74. AArray.Create(
  75. ATypes.AInteger,
  76. AInteger.Create(0),
  77. AInteger.Create(1),
  78. AInteger.Create(2)
  79. ),
  80. AArray.Create(
  81. ATypes.AInteger,
  82. AInteger.Create(0),
  83. AInteger.Create(1),
  84. AInteger.Create(2)
  85. ),
  86. AArray.Create(
  87. ATypes.AInteger,
  88. AInteger.Create(3),
  89. AInteger.Create(4),
  90. AInteger.Create(5)
  91. ),
  92. AArray.Create(
  93. ATypes.AInteger,
  94. AInteger.Create(3),
  95. AInteger.Create(4),
  96. AInteger.Create(5)
  97. )
  98. );
  99. AType result = this.engine.Execute<AType>("2 / iota 2 3");
  100. Assert.AreEqual(expected, result);
  101. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  102. }
  103. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  104. public void ReplicateNull2Strand()
  105. {
  106. AType expected = AArray.Create(
  107. ATypes.ANull
  108. );
  109. AType result = this.engine.Execute<AType>("0 / (2;3)");
  110. Assert.AreEqual(expected, result);
  111. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  112. }
  113. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  114. public void ReplicateInteger2Box()
  115. {
  116. AType expected = AArray.Create(
  117. ATypes.ABox,
  118. ABox.Create(Helpers.BuildString("test")),
  119. ABox.Create(Helpers.BuildString("test")),
  120. ABox.Create(Helpers.BuildString("test"))
  121. );
  122. AType result = this.engine.Execute<AType>("3 / < 'test'");
  123. Assert.AreEqual(expected, result);
  124. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  125. }
  126. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  127. public void ReplicateInteger2Null()
  128. {
  129. AType expected = AArray.Create(
  130. ATypes.ANull
  131. );
  132. AType result = this.engine.Execute<AType>("3 / ()");
  133. Assert.AreEqual(expected, result);
  134. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  135. }
  136. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  137. public void ReplicateInteger2Float()
  138. {
  139. AType expected = AArray.Create(
  140. ATypes.AFloat,
  141. AFloat.Create(4.5),
  142. AFloat.Create(4.5),
  143. AFloat.Create(4.5)
  144. );
  145. AType result = this.engine.Execute<AType>("3 / 4.5");
  146. Assert.AreEqual(expected, result);
  147. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  148. }
  149. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  150. public void ReplicateIntegerList2CharacterConstant2()
  151. {
  152. AType expected = Helpers.BuildString("aaaaa");
  153. AType result = this.engine.Execute<AType>("2 0 3 0 / 'a'");
  154. Assert.AreEqual(expected, result);
  155. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  156. }
  157. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  158. public void ReplicateIntegerList2CharacterConstant()
  159. {
  160. AType expected = AArray.Create(
  161. ATypes.AChar,
  162. Helpers.BuildString("ab"),
  163. Helpers.BuildString("ab"),
  164. Helpers.BuildString("ab"),
  165. Helpers.BuildString("ef")
  166. );
  167. AType result = this.engine.Execute<AType>("3 0 1 / 3 2 rho 'abcdef'");
  168. Assert.AreEqual(expected, result);
  169. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  170. }
  171. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  172. public void ReplicateCompress1()
  173. {
  174. AType expected = AArray.Create(
  175. ATypes.AInteger,
  176. AInteger.Create(4),
  177. AInteger.Create(3),
  178. AInteger.Create(0),
  179. AInteger.Create(8)
  180. );
  181. AType result = this.engine.Execute<AType>("(a >= 0) / a := 4 -1 3 0 8 -5");
  182. Assert.AreEqual(expected, result);
  183. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  184. }
  185. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  186. public void ReplicateCompress2()
  187. {
  188. AType expected = AArray.Create(ATypes.AInteger);
  189. expected.Length = 0;
  190. expected.Shape = new List<int>() { 0, 4 };
  191. expected.Rank = 2;
  192. AType result = this.engine.Execute<AType>("0 0 0 / iota 3 4");
  193. Assert.AreEqual(expected, result);
  194. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  195. }
  196. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  197. public void ReplicateIntegerList2NestedMixedArray()
  198. {
  199. ScriptScope scope = this.engine.CreateScope();
  200. AType f = this.engine.Execute<AType>("f := {+}", scope);
  201. AType expected = AArray.Create(
  202. ATypes.ASymbol,
  203. ASymbol.Create("a"),
  204. ASymbol.Create("a"),
  205. ABox.Create(AInteger.Create(4)),
  206. ABox.Create(f),
  207. ABox.Create(f)
  208. );
  209. AType result = this.engine.Execute<AType>("2 0 1 2 / `a , (3;4;f)", scope);
  210. Assert.AreEqual(expected, result);
  211. Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
  212. }
  213. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  214. [ExpectedException(typeof(Error.Domain))]
  215. public void ReplicateDomainError()
  216. {
  217. AType result = this.engine.Execute<AType>("4 -2 2 / 3 4");
  218. }
  219. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  220. [ExpectedException(typeof(Error.Type))]
  221. public void ReplicateTypeError()
  222. {
  223. AType result = this.engine.Execute<AType>("3.0000000000003 4.3 / 3 4");
  224. }
  225. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  226. [ExpectedException(typeof(Error.Type))]
  227. public void ReplicateTypeError2()
  228. {
  229. AType result = this.engine.Execute<AType>("`test / 3 4");
  230. }
  231. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  232. [ExpectedException(typeof(Error.Rank))]
  233. public void ReplicateRankError1()
  234. {
  235. AType result = this.engine.Execute<AType>("(iota 2 3) / 3 4");
  236. }
  237. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  238. [ExpectedException(typeof(Error.Rank))]
  239. public void ReplicateRankError2()
  240. {
  241. AType result = this.engine.Execute<AType>("(iota 2 3) / ()");
  242. }
  243. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  244. [ExpectedException(typeof(Error.Length))]
  245. public void ReplicateLengthError1()
  246. {
  247. AType result = this.engine.Execute<AType>("2 3 4 / 6 2 1 1");
  248. }
  249. [TestCategory("DLR"), TestCategory("Dyadic"), TestCategory("Replicate"), TestMethod]
  250. [ExpectedException(typeof(Error.Length))]
  251. public void ReplicateLengthError2()
  252. {
  253. AType result = this.engine.Execute<AType>("3 5 / ()");
  254. }
  255. }
  256. }