SetEqualsExpression_test.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. "use strict";
  2. if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
  3. var assert = require("assert"),
  4. SetEqualsExpression = require("../../../../lib/pipeline/expressions/SetEqualsExpression"),
  5. ExpectedResultBase = require("./SetExpectedResultBase");
  6. exports.SetEqualsExpression = {
  7. "constructor()": {
  8. "should not throw Error when constructing without args": function() {
  9. assert.doesNotThrow(function() {
  10. new SetEqualsExpression();
  11. });
  12. },
  13. "should throw Error when constructing with args": function() {
  14. assert.throws(function() {
  15. new SetEqualsExpression("someArg");
  16. });
  17. },
  18. },
  19. "#getOpName()": {
  20. "should return the correct op name; $setEquals": function() {
  21. assert.equal(new SetEqualsExpression().getOpName(), "$setEquals");
  22. },
  23. },
  24. "#evaluate()": {
  25. "should handle when sets are the same": function Same(){
  26. new ExpectedResultBase({
  27. getSpec: {
  28. input: [[1, 2], [1, 2]],
  29. expected: {
  30. // $setIsSubset: true,
  31. $setEquals: true,
  32. // $setIntersection: [1, 2],
  33. // $setUnion: [1, 2],
  34. // $setDifference: [],
  35. },
  36. },
  37. }).run();
  38. },
  39. "should handle when the 2nd set has redundant items": function Redundant(){
  40. new ExpectedResultBase({
  41. getSpec: {
  42. input: [[1, 2], [1, 2, 2]],
  43. expected: {
  44. // $setIsSubset: true,
  45. $setEquals: true,
  46. // $setIntersection: [1, 2],
  47. // $setUnion: [1, 2],
  48. // $setDifference: [],
  49. },
  50. },
  51. }).run();
  52. },
  53. "should handle when the both sets have redundant items": function DoubleRedundant(){
  54. new ExpectedResultBase({
  55. getSpec: {
  56. input: [[1, 1, 2], [1, 2, 2]],
  57. expected: {
  58. // $setIsSubset: true,
  59. $setEquals: true,
  60. // $setIntersection: [1, 2],
  61. // $setUnion: [1, 2],
  62. // $setDifference: [],
  63. },
  64. },
  65. }).run();
  66. },
  67. "should handle when the 1st set is a superset": function Super(){
  68. new ExpectedResultBase({
  69. getSpec: {
  70. input: [[1, 2], [1]],
  71. expected: {
  72. // $setIsSubset: false,
  73. $setEquals: false,
  74. // $setIntersection: [1],
  75. // $setUnion: [1, 2],
  76. // $setDifference: [2],
  77. },
  78. },
  79. }).run();
  80. },
  81. "should handle when the 2nd set is a superset and has redundant items": function SuperWithRedundant(){
  82. new ExpectedResultBase({
  83. getSpec: {
  84. input: [[1, 2, 2], [1]],
  85. expected: {
  86. // $setIsSubset: false,
  87. $setEquals: false,
  88. // $setIntersection: [1],
  89. // $setUnion: [1, 2],
  90. // $setDifference: [2],
  91. },
  92. },
  93. }).run();
  94. },
  95. "should handle when the 1st set is a subset": function Sub(){
  96. new ExpectedResultBase({
  97. getSpec: {
  98. input: [[1], [1, 2]],
  99. expected: {
  100. // $setIsSubset: true,
  101. $setEquals: false,
  102. // $setIntersection: [1],
  103. // $setUnion: [1, 2],
  104. // $setDifference: [],
  105. },
  106. },
  107. }).run();
  108. },
  109. "should handle when the sets are the same but backwards": function SameBackwards(){
  110. new ExpectedResultBase({
  111. getSpec: {
  112. input: [[1, 2], [2, 1]],
  113. expected: {
  114. // $setIsSubset: true,
  115. $setEquals: true,
  116. // $setIntersection: [1, 2],
  117. // $setUnion: [1, 2],
  118. // $setDifference: [],
  119. },
  120. },
  121. }).run();
  122. },
  123. "should handle when the sets do not overlap": function NoOverlap(){
  124. new ExpectedResultBase({
  125. getSpec: {
  126. input: [[1, 2], [8, 4]],
  127. expected: {
  128. // $setIsSubset: false,
  129. $setEquals: false,
  130. // $setIntersection: [],
  131. // $setUnion: [1, 2, 4, 8],
  132. // $setDifference: [1, 2],
  133. },
  134. },
  135. }).run();
  136. },
  137. "should handle when the sets do overlap": function Overlap(){
  138. new ExpectedResultBase({
  139. getSpec: {
  140. input: [[1, 2], [8, 2, 4]],
  141. expected: {
  142. // $setIsSubset: false,
  143. $setEquals: false,
  144. // $setIntersection: [2],
  145. // $setUnion: [1, 2, 4, 8],
  146. // $setDifference: [1],
  147. },
  148. },
  149. }).run();
  150. },
  151. "should handle when the 2nd set is null": function LastNull(){
  152. new ExpectedResultBase({
  153. getSpec: {
  154. input: [[1, 2], null],
  155. expected: {
  156. // $setIntersection: null,
  157. // $setUnion: null,
  158. // $setDifference: null,
  159. },
  160. error: [
  161. "$setEquals"
  162. // "$setIsSubset"
  163. ],
  164. },
  165. }).run();
  166. },
  167. "should handle when the 1st set is null": function FirstNull(){
  168. new ExpectedResultBase({
  169. getSpec: {
  170. input: [null, [1, 2]],
  171. expected: {
  172. // $setIntersection: null,
  173. // $setUnion: null,
  174. // $setDifference: null,
  175. },
  176. error: [
  177. "$setEquals"
  178. // "$setIsSubset"
  179. ],
  180. },
  181. }).run();
  182. },
  183. "should handle when the input has no args": function NoArg(){
  184. new ExpectedResultBase({
  185. getSpec: {
  186. input: [],
  187. expected: {
  188. // $setIntersection: [],
  189. // $setUnion: [],
  190. },
  191. error: [
  192. "$setEquals"
  193. // "$setIsSubset"
  194. // "$setDifference"
  195. ],
  196. },
  197. }).run();
  198. },
  199. "should handle when the input has one arg": function OneArg(){
  200. new ExpectedResultBase({
  201. getSpec: {
  202. input: [[1, 2]],
  203. expected: {
  204. // $setIntersection: [1, 2],
  205. // $setUnion: [1, 2],
  206. },
  207. error: [
  208. "$setEquals"
  209. // "$setIsSubset"
  210. // "$setDifference"
  211. ],
  212. },
  213. }).run();
  214. },
  215. "should handle when the input has empty arg": function EmptyArg(){
  216. new ExpectedResultBase({
  217. getSpec: {
  218. input: [[1, 2]],
  219. expected: {
  220. // $setIntersection: [1, 2],
  221. // $setUnion: [1, 2],
  222. },
  223. error: [
  224. "$setEquals"
  225. // "$setIsSubset"
  226. // "$setDifference"
  227. ],
  228. },
  229. }).run();
  230. },
  231. "should handle when the input has empty left arg": function LeftArgEmpty(){
  232. new ExpectedResultBase({
  233. getSpec: {
  234. input: [[]],
  235. expected: {
  236. // $setIntersection: [],
  237. // $setUnion: [],
  238. },
  239. error: [
  240. "$setEquals"
  241. // "$setIsSubset"
  242. // "$setDifference"
  243. ],
  244. },
  245. }).run();
  246. },
  247. "should handle when the input has empty right arg": function RightArgEmpty(){
  248. new ExpectedResultBase({
  249. getSpec: {
  250. input: [[1, 2], []],
  251. expected: {
  252. // $setIntersection: [],
  253. // $setUnion: [1, 2],
  254. // $setIsSubset: false,
  255. $setEquals: false,
  256. // $setDifference: [1, 2],
  257. },
  258. },
  259. }).run();
  260. },
  261. "should handle when the input has many args": function ManyArgs(){
  262. new ExpectedResultBase({
  263. getSpec: {
  264. input: [[8, 3], ["asdf", "foo"], [80.3, 34], [], [80.3, "foo", 11, "yay"]],
  265. expected: {
  266. // $setIntersection: [],
  267. $setEquals: false,
  268. // $setUnion: [3, 8, 11, 34, 80.3, "asdf", "foo", "yay"],
  269. },
  270. error: [
  271. // "$setIsSubset",
  272. // "$setDifference",
  273. ],
  274. },
  275. }).run();
  276. },
  277. "should handle when the input has many args that are equal sets": function ManyArgsEqual(){
  278. new ExpectedResultBase({
  279. getSpec: {
  280. input: [[1, 2, 4], [1, 2, 2, 4], [4, 1, 2], [2, 1, 1, 4]],
  281. expected: {
  282. // $setIntersection: [1, 2, 4],
  283. $setEquals: true,
  284. // $setUnion: [1, 2, 4],
  285. },
  286. error: [
  287. // "$setIsSubset",
  288. // "$setDifference",
  289. ],
  290. },
  291. }).run();
  292. },
  293. },
  294. };