SetOperations.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /**
  2. * Set Operations tests.
  3. *
  4. * @author d98762625
  5. *
  6. * @copyright Crown Copyright 2017
  7. * @license Apache-2.0
  8. */
  9. import TestRegister from "../../TestRegister.js";
  10. TestRegister.addTests([
  11. {
  12. name: "Set Operations: Nothing",
  13. input: "\n\n",
  14. expectedOutput: "",
  15. recipeConfig: [
  16. {
  17. op: "Set Operations",
  18. args: ["\n\n", " ", "Union"],
  19. },
  20. ],
  21. },
  22. {
  23. name: "Set Operations: Union",
  24. input: "1 2 3 4 5\n\n3 4 5 6 7",
  25. expectedOutput: "1 2 3 4 5 6 7",
  26. recipeConfig: [
  27. {
  28. op: "Set Operations",
  29. args: ["\n\n", " ", "Union"],
  30. },
  31. ],
  32. },
  33. {
  34. name: "Set Operations: Union: invalid sample number",
  35. input: "1 2 3 4 5\n\n3 4 5 6 7\n\n1",
  36. expectedOutput: "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?",
  37. recipeConfig: [
  38. {
  39. op: "Set Operations",
  40. args: ["\n\n", " ", "Union"],
  41. },
  42. ],
  43. },
  44. {
  45. name: "Set Operations: Union: item delimiter",
  46. input: "1,2,3,4,5\n\n3,4,5,6,7",
  47. expectedOutput: "1,2,3,4,5,6,7",
  48. recipeConfig: [
  49. {
  50. op: "Set Operations",
  51. args: ["\n\n", ",", "Union"],
  52. },
  53. ],
  54. },
  55. {
  56. name: "Set Operations: Union: sample delimiter",
  57. input: "1 2 3 4 5whatever3 4 5 6 7",
  58. expectedOutput: "1 2 3 4 5 6 7",
  59. recipeConfig: [
  60. {
  61. op: "Set Operations",
  62. args: ["whatever", " ", "Union"],
  63. },
  64. ],
  65. },
  66. {
  67. name: "Set Operations: Intersection",
  68. input: "1 2 3 4 5\n\n3 4 5 6 7",
  69. expectedOutput: "3 4 5",
  70. recipeConfig: [
  71. {
  72. op: "Set Operations",
  73. args: ["\n\n", " ", "Intersection"],
  74. },
  75. ],
  76. },
  77. {
  78. name: "Set Operations: Intersection: only one set",
  79. input: "1 2 3 4 5 6 7 8",
  80. expectedOutput: "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?",
  81. recipeConfig: [
  82. {
  83. op: "Set Operations",
  84. args: ["\n\n", " ", "Intersection"],
  85. },
  86. ],
  87. },
  88. {
  89. name: "Set Operations: Intersection: item delimiter",
  90. input: "1-2-3-4-5\n\n3-4-5-6-7",
  91. expectedOutput: "3-4-5",
  92. recipeConfig: [
  93. {
  94. op: "Set Operations",
  95. args: ["\n\n", "-", "Intersection"],
  96. },
  97. ],
  98. },
  99. {
  100. name: "Set Operations: Intersection: sample delimiter",
  101. input: "1-2-3-4-5z3-4-5-6-7",
  102. expectedOutput: "3-4-5",
  103. recipeConfig: [
  104. {
  105. op: "Set Operations",
  106. args: ["z", "-", "Intersection"],
  107. },
  108. ],
  109. },
  110. {
  111. name: "Set Operations: Set Difference",
  112. input: "1 2 3 4 5\n\n3 4 5 6 7",
  113. expectedOutput: "1 2",
  114. recipeConfig: [
  115. {
  116. op: "Set Operations",
  117. args: ["\n\n", " ", "Set Difference"],
  118. },
  119. ],
  120. },
  121. {
  122. name: "Set Operations: Set Difference: wrong sample count",
  123. input: "1 2 3 4 5_3_4 5 6 7",
  124. expectedOutput: "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?",
  125. recipeConfig: [
  126. {
  127. op: "Set Operations",
  128. args: [" ", "_", "Set Difference"],
  129. },
  130. ],
  131. },
  132. {
  133. name: "Set Operations: Set Difference: item delimiter",
  134. input: "1;2;3;4;5\n\n3;4;5;6;7",
  135. expectedOutput: "1;2",
  136. recipeConfig: [
  137. {
  138. op: "Set Operations",
  139. args: ["\n\n", ";", "Set Difference"],
  140. },
  141. ],
  142. },
  143. {
  144. name: "Set Operations: Set Difference: sample delimiter",
  145. input: "1;2;3;4;5===3;4;5;6;7",
  146. expectedOutput: "1;2",
  147. recipeConfig: [
  148. {
  149. op: "Set Operations",
  150. args: ["===", ";", "Set Difference"],
  151. },
  152. ],
  153. },
  154. {
  155. name: "Set Operations: Symmetric Difference",
  156. input: "1 2 3 4 5\n\n3 4 5 6 7",
  157. expectedOutput: "1 2 6 7",
  158. recipeConfig: [
  159. {
  160. op: "Set Operations",
  161. args: ["\n\n", " ", "Symmetric Difference"],
  162. },
  163. ],
  164. },
  165. {
  166. name: "Set Operations: Symmetric Difference: wrong sample count",
  167. input: "1 2\n\n3 4 5\n\n3 4 5 6 7",
  168. expectedOutput: "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?",
  169. recipeConfig: [
  170. {
  171. op: "Set Operations",
  172. args: ["\n\n", " ", "Symmetric Difference"],
  173. },
  174. ],
  175. },
  176. {
  177. name: "Set Operations: Symmetric Difference: item delimiter",
  178. input: "a_b_c_d_e\n\nc_d_e_f_g",
  179. expectedOutput: "a_b_f_g",
  180. recipeConfig: [
  181. {
  182. op: "Set Operations",
  183. args: ["\n\n", "_", "Symmetric Difference"],
  184. },
  185. ],
  186. },
  187. {
  188. name: "Set Operations: Symmetric Difference: sample delimiter",
  189. input: "a_b_c_d_eAAAAAc_d_e_f_g",
  190. expectedOutput: "a_b_f_g",
  191. recipeConfig: [
  192. {
  193. op: "Set Operations",
  194. args: ["AAAAA", "_", "Symmetric Difference"],
  195. },
  196. ],
  197. },
  198. {
  199. name: "Set Operations: Cartesian Product",
  200. input: "1 2 3 4 5\n\na b c d e",
  201. expectedOutput: "(1,a) (2,b) (3,c) (4,d) (5,e)",
  202. recipeConfig: [
  203. {
  204. op: "Set Operations",
  205. args: ["\n\n", " ", "Cartesian Product"],
  206. },
  207. ],
  208. },
  209. {
  210. name: "Set Operations: Cartesian Product: wrong sample count",
  211. input: "1 2\n\n3 4 5\n\na b c d e",
  212. expectedOutput: "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?",
  213. recipeConfig: [
  214. {
  215. op: "Set Operations",
  216. args: ["\n\n", " ", "Cartesian Product"],
  217. },
  218. ],
  219. },
  220. {
  221. name: "Set Operations: Cartesian Product: too many on left",
  222. input: "1 2 3 4 5 6\n\na b c d e",
  223. expectedOutput: "(1,a) (2,b) (3,c) (4,d) (5,e) (6,undefined)",
  224. recipeConfig: [
  225. {
  226. op: "Set Operations",
  227. args: ["\n\n", " ", "Cartesian Product"],
  228. },
  229. ],
  230. },
  231. {
  232. name: "Set Operations: Cartesian Product: too many on right",
  233. input: "1 2 3 4 5\n\na b c d e f",
  234. expectedOutput: "(1,a) (2,b) (3,c) (4,d) (5,e) (undefined,f)",
  235. recipeConfig: [
  236. {
  237. op: "Set Operations",
  238. args: ["\n\n", " ", "Cartesian Product"],
  239. },
  240. ],
  241. },
  242. {
  243. name: "Set Operations: Cartesian Product: item delimiter",
  244. input: "1-2-3-4-5\n\na-b-c-d-e",
  245. expectedOutput: "(1,a)-(2,b)-(3,c)-(4,d)-(5,e)",
  246. recipeConfig: [
  247. {
  248. op: "Set Operations",
  249. args: ["\n\n", "-", "Cartesian Product"],
  250. },
  251. ],
  252. },
  253. {
  254. name: "Set Operations: Cartesian Product: sample delimiter",
  255. input: "1 2 3 4 5_a b c d e",
  256. expectedOutput: "(1,a) (2,b) (3,c) (4,d) (5,e)",
  257. recipeConfig: [
  258. {
  259. op: "Set Operations",
  260. args: ["_", " ", "Cartesian Product"],
  261. },
  262. ],
  263. },
  264. {
  265. name: "Set Operations: Power set: nothing",
  266. input: "",
  267. expectedOutput: "",
  268. recipeConfig: [
  269. {
  270. op: "Set Operations",
  271. args: ["\n\n", " ", "Power Set"],
  272. },
  273. ],
  274. },
  275. {
  276. name: "Set Operations: Power set: Too many samples",
  277. input: "1 2 3\n\n4",
  278. expectedOutput: "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?",
  279. recipeConfig: [
  280. {
  281. op: "Set Operations",
  282. args: ["\n\n", " ", "Power Set"],
  283. },
  284. ],
  285. },
  286. {
  287. name: "Set Operations: Power set",
  288. input: "1 2 4",
  289. expectedOutput: "\n4\n2\n1\n2 4\n1 4\n1 2\n1 2 4\n",
  290. recipeConfig: [
  291. {
  292. op: "Set Operations",
  293. args: ["\n\n", " ", "Power Set"],
  294. },
  295. ],
  296. },
  297. ]);