SetIntersectionExpression_test.js 7.2 KB

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