Comparing version 0.5.3 to 0.5.5
{ | ||
"name": "can-set", | ||
"version": "0.5.3", | ||
"version": "0.5.5", | ||
"description": "Set logic for CanJS", | ||
@@ -5,0 +5,0 @@ "main": "src/set.js", |
@@ -270,1 +270,24 @@ var QUnit = require("steal-qunit"); | ||
}); | ||
test('rangeInclusive with string numbers (#17)', function(){ | ||
var algebra = new set.Algebra( | ||
comparators.rangeInclusive('start','end') | ||
); | ||
ok( | ||
algebra.subset( | ||
{start: "1", end: "100"}, | ||
{start: "0", end: "100"} | ||
), | ||
".subset" ); | ||
var res = algebra.getSubset({start: "2",end: "3"},{start: "1",end: "4"},[{id: 1},{id: 2},{id: 3},{id: 4}]); | ||
deepEqual(res, [{id: 2},{id: 3}], ".getSubset"); | ||
res = algebra.getUnion( | ||
{start: "2",end: "3"}, | ||
{start: "1",end: "4"}, | ||
[{id: 2},{id: 3}], | ||
[{id: 1},{id: 2},{id: 3},{id: 4}]); | ||
deepEqual(res, [{id: 1},{id: 2},{id: 3},{id: 4}], ".getUnion"); | ||
}); |
@@ -7,2 +7,10 @@ var h = require("./helpers"); | ||
}; | ||
var numericProperties = function(setA, setB, property1, property2){ | ||
return { | ||
sAv1: +setA[property1], | ||
sAv2: +setA[property2], | ||
sBv1: +setB[property1], | ||
sBv2: +setB[property2], | ||
}; | ||
}; | ||
@@ -13,6 +21,7 @@ // diff from setA's perspective | ||
// v for value | ||
var sAv1 = setA[property1], | ||
sAv2 = setA[property2], | ||
sBv1 = setB[property1], | ||
sBv2 = setB[property2], | ||
var numProps = numericProperties(setA, setB, property1, property2); | ||
var sAv1 = numProps.sAv1, | ||
sAv2 = numProps.sAv2, | ||
sBv1 = numProps.sBv1, | ||
sBv2 = numProps.sBv2, | ||
count = sAv2 - sAv1 + 1; | ||
@@ -168,11 +177,7 @@ | ||
var res = {}; | ||
if(result.intersection) { | ||
res.intersection = result.intersection[index]; | ||
} | ||
if(result.difference){ | ||
res.difference = result.difference[index]; | ||
} | ||
if(result.union) { | ||
res.union = result.union[index]; | ||
} | ||
h.each(["intersection","difference","union"], function(prop){ | ||
if(result[prop]) { | ||
res[prop] = result[prop][index]; | ||
} | ||
}); | ||
if(result.count) { | ||
@@ -184,2 +189,4 @@ res.count = result.count; | ||
// returns the `start` properties values for different algebra methods and a | ||
// getSubset+getUnion that really dont do anything. | ||
compares[startIndexProperty] = function(vA, vB, A, B){ | ||
@@ -191,3 +198,2 @@ if(vA === undefined) { | ||
var result = makeResult(res, 0); | ||
@@ -202,2 +208,4 @@ result.getSubset = function(a, b, bItems, algebra, options){ | ||
}; | ||
// returns the `end` property values for different algebra methods and | ||
// a getSubset+getUnion that actually perform a mution on the items. | ||
compares[endIndexProperty] = function(vA, vB, A, B){ | ||
@@ -211,6 +219,7 @@ if(vA === undefined) { | ||
res.getSubset = function(a, b, bItems, algebra, options){ | ||
var aStartValue = a[startIndexProperty], | ||
aEndValue = a[endIndexProperty]; | ||
var numProps = numericProperties(a, b, startIndexProperty, endIndexProperty); | ||
var aStartValue = numProps.sAv1, | ||
aEndValue = numProps.sAv2; | ||
var bStartValue = b[startIndexProperty]; | ||
var bStartValue = numProps.sBv1; | ||
@@ -227,3 +236,3 @@ if( ! (endIndexProperty in b) || ! (endIndexProperty in a) ) { | ||
if(data.intersection) { | ||
bItems = bItems.slice( 0, data.intersection[0]-b[startIndexProperty] ); | ||
bItems = bItems.slice( 0, data.intersection[0]- (+b[startIndexProperty]) ); | ||
} | ||
@@ -234,3 +243,3 @@ return [bItems, aItems]; | ||
if(data.intersection) { | ||
aItems = aItems.slice( 0, data.intersection[0]-a[startIndexProperty] ); | ||
aItems = aItems.slice( 0, data.intersection[0]- (+a[startIndexProperty]) ); | ||
} | ||
@@ -237,0 +246,0 @@ return [aItems,bItems]; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116638
3293