| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- "use strict";
- var assert = require("assert"),
- SetIntersectionExpression = require("../../../../lib/pipeline/expressions/SetIntersectionExpression"),
- ExpectedResultBase = require("./SetExpectedResultBase");
- // Mocha one-liner to make these tests self-hosted
- 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));
- exports.SetIntersectionExpression = {
- "constructor()": {
- "should not throw Error when constructing without args": function() {
- assert.doesNotThrow(function() {
- new SetIntersectionExpression();
- });
- },
- "should throw Error when constructing with args": function() {
- assert.throws(function() {
- new SetIntersectionExpression("someArg");
- });
- },
- },
- "#getOpName()": {
- "should return the correct op name; $setIntersection": function() {
- assert.equal(new SetIntersectionExpression().getOpName(), "$setIntersection");
- }
- },
- "#evaluate()": {
- "should handle when sets are the same": function Same(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 2], [1, 2]],
- expected: {
- // $setIsSubset: true,
- // $setEquals: true,
- $setIntersection: [1, 2],
- // $setUnion: [1, 2],
- // $setDifference: [],
- },
- },
- }).run();
- },
- "should handle when the 2nd set has redundant items": function Redundant(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 2], [1, 2, 2]],
- expected: {
- // $setIsSubset: true,
- // $setEquals: true,
- $setIntersection: [1, 2],
- // $setUnion: [1, 2],
- // $setDifference: [],
- },
- },
- }).run();
- },
- "should handle when the both sets have redundant items": function DoubleRedundant(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 1, 2], [1, 2, 2]],
- expected: {
- // $setIsSubset: true,
- // $setEquals: true,
- $setIntersection: [1, 2],
- // $setUnion: [1, 2],
- // $setDifference: [],
- },
- },
- }).run();
- },
- "should handle when the 1st set is a superset": function Super(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 2], [1]],
- expected: {
- // $setIsSubset: false,
- // $setEquals: false,
- $setIntersection: [1],
- // $setUnion: [1, 2],
- // $setDifference: [2],
- },
- },
- }).run();
- },
- "should handle when the 2nd set is a superset and has redundant items": function SuperWithRedundant(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 2, 2], [1]],
- expected: {
- // $setIsSubset: false,
- // $setEquals: false,
- $setIntersection: [1],
- // $setUnion: [1, 2],
- // $setDifference: [2],
- },
- },
- }).run();
- },
- "should handle when the 1st set is a subset": function Sub(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1], [1, 2]],
- expected: {
- // $setIsSubset: true,
- // $setEquals: false,
- $setIntersection: [1],
- // $setUnion: [1, 2],
- // $setDifference: [],
- },
- },
- }).run();
- },
- "should handle when the sets are the same but backwards": function SameBackwards(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 2], [2, 1]],
- expected: {
- // $setIsSubset: true,
- // $setEquals: true,
- $setIntersection: [1, 2],
- // $setUnion: [1, 2],
- // $setDifference: [],
- },
- },
- }).run();
- },
- "should handle when the sets do not overlap": function NoOverlap(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 2], [8, 4]],
- expected: {
- // $setIsSubset: false,
- // $setEquals: false,
- $setIntersection: [],
- // $setUnion: [1, 2, 4, 8],
- // $setDifference: [1, 2],
- },
- },
- }).run();
- },
- "should handle when the sets do overlap": function Overlap(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 2], [8, 2, 4]],
- expected: {
- // $setIsSubset: false,
- // $setEquals: false,
- $setIntersection: [2],
- // $setUnion: [1, 2, 4, 8],
- // $setDifference: [1],
- },
- },
- }).run();
- },
- "should handle when the 2nd set is null": function LastNull(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 2], null],
- expected: {
- $setIntersection: null,
- // $setUnion: null,
- // $setDifference: null,
- },
- error: [
- // "$setEquals"
- // "$setIsSubset"
- ],
- },
- }).run();
- },
- "should handle when the 1st set is null": function FirstNull(){
- new ExpectedResultBase({
- getSpec: {
- input: [null, [1, 2]],
- expected: {
- $setIntersection: null,
- // $setUnion: null,
- // $setDifference: null,
- },
- error: [
- // "$setEquals"
- // "$setIsSubset"
- ],
- },
- }).run();
- },
- "should handle when the input has no args": function NoArg(){
- new ExpectedResultBase({
- getSpec: {
- input: [],
- expected: {
- $setIntersection: [],
- // $setUnion: [],
- },
- error: [
- // "$setEquals"
- // "$setIsSubset"
- // "$setDifference"
- ],
- },
- }).run();
- },
- "should handle when the input has one arg": function OneArg(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 2]],
- expected: {
- $setIntersection: [1, 2],
- // $setUnion: [1, 2],
- },
- error: [
- // "$setEquals"
- // "$setIsSubset"
- // "$setDifference"
- ],
- },
- }).run();
- },
- "should handle when the input has empty arg": function EmptyArg(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 2]],
- expected: {
- $setIntersection: [1, 2],
- // $setUnion: [1, 2],
- },
- error: [
- // "$setEquals"
- // "$setIsSubset"
- // "$setDifference"
- ],
- },
- }).run();
- },
- "should handle when the input has empty left arg": function LeftArgEmpty(){
- new ExpectedResultBase({
- getSpec: {
- input: [[]],
- expected: {
- $setIntersection: [],
- // $setUnion: [],
- },
- error: [
- // "$setEquals"
- // "$setIsSubset"
- // "$setDifference"
- ],
- },
- }).run();
- },
- "should handle when the input has empty right arg": function RightArgEmpty(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 2], []],
- expected: {
- $setIntersection: [],
- // $setUnion: [1, 2],
- // $setIsSubset: false,
- // $setEquals: false,
- // $setDifference: [1, 2],
- },
- },
- }).run();
- },
- "should handle when the input has many args": function ManyArgs(){
- new ExpectedResultBase({
- getSpec: {
- input: [[8, 3], ["asdf", "foo"], [80.3, 34], [], [80.3, "foo", 11, "yay"]],
- expected: {
- $setIntersection: [],
- // $setEquals: false,
- // $setUnion: [3, 8, 11, 34, 80.3, "asdf", "foo", "yay"],
- },
- error: [
- // "$setIsSubset",
- // "$setDifference",
- ],
- },
- }).run();
- },
- "should handle when the input has many args that are equal sets": function ManyArgsEqual(){
- new ExpectedResultBase({
- getSpec: {
- input: [[1, 2, 4], [1, 2, 2, 4], [4, 1, 2], [2, 1, 1, 4]],
- expected: {
- $setIntersection: [1, 2, 4],
- // $setEquals: true,
- // $setUnion: [1, 2, 4],
- },
- error: [
- // "$setIsSubset",
- // "$setDifference",
- ],
- },
- }).run();
- },
- },
- };
|