test('where', function() { var list = [{a: 1, b: 2}, {a: 2, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}]; var result = _.where(list, {a: 1}); equal(result.length, 3); equal(result[result.length - 1].b, 4); result = _.where(list, {b: 2}); equal(result.length, 2); equal(result[0].a, 1); result = _.where(list, {a: 1}, true); equal(result.b, 2, "Only get the first object matched.") result = _.where(list, {a: 1}, false); equal(result.length, 3); });
it('should handle cache properly', () => { const test1 = rewiremock.proxy('./lib/cache/requireA', r => { rewiremock(() => require('./lib/cache/a')).with(42).toBeUsed(); }); expect(test1.b).to.be.equal(42); const fileA = Module._resolveFilename('./lib/cache/a', module); expect(require.cache[fileA]).to.be.equal(undefined); let test2; expect(() => { test2 = rewiremock.proxy('./lib/cache/requireA', r => { rewiremock(() => require('./lib/cache/a')).with(42).toBeUsed(); }) }).not.to.throw(); expect(require.cache[fileA]).to.be.equal(undefined); expect(test2.b).to.be.equal(42); expect(test1.a).not.to.be.equal(test2.a); });
function drawPoint(entity, data) { var geometry, material, point; geometry = new THREE.Geometry(); geometry.vertices.push(new THREE.Vector3(entity.position.x, entity.position.y, entity.position.z)); // TODO: could be more efficient. PointCloud per layer? var numPoints = 1; var color = getColor(entity, data); var colors = new Float32Array( numPoints*3 ); colors[0] = color.r; colors[1] = color.g; colors[2] = color.b; geometry.colors = colors; geometry.computeBoundingBox(); material = new THREE.PointsMaterial( { size: 0.05, vertexColors: THREE.VertexColors } ); point = new THREE.Points(geometry, material); scene.add(point); }
@computed get rowSums() { // total of deeply observable JSON values var res=[]; // automatically updated when nested data values change for (var rctr = 0; rctr < this.data.rows.length; rctr++) { var rowView = this.data.rows[rctr]; var count=0, sum=0; if (Number(this.data.rows[rctr].a) >= 0) { count++; sum += Number(this.data.rows[rctr].a);} if (Number(this.data.rows[rctr].b) >= 0) { count++; sum += Number(this.data.rows[rctr].b); } if (Number(this.data.rows[rctr].c) >= 0) { count++; sum += Number(this.data.rows[rctr].c); } if (Number(this.data.rows[rctr].d) >= 0) { count++; sum += Number(this.data.rows[rctr].d); } rowView['sum'] = sum; rowView['count'] = count; rowView['avg'] = sum/count; res.push(rowView); } return res; }
QUnit.test('should match `undefined` values on primitives', function(assert) { assert.expect(2); numberProto.a = 1; numberProto.b = undefined; try { var matches = _.matchesProperty('b', undefined); assert.strictEqual(matches(1), true); } catch (e) { assert.ok(false, e.message); } numberProto.a = { 'b': 1, 'c': undefined }; try { matches = _.matchesProperty('a', { 'c': undefined }); assert.strictEqual(matches(1), true); } catch (e) { assert.ok(false, e.message); } delete numberProto.a; delete numberProto.b; });
QUnit.test('`_.' + methodName + '` should match `undefined` values on primitives', function(assert) { assert.expect(3); numberProto.a = 1; numberProto.b = undefined; try { var par = matches({ 'b': undefined }); assert.strictEqual(par(1), true); } catch (e) { assert.ok(false, e.message); } try { par = matches({ 'a': 1, 'b': undefined }); assert.strictEqual(par(1), true); } catch (e) { assert.ok(false, e.message); } numberProto.a = { 'b': 1, 'c': undefined }; try { par = matches({ 'a': { 'c': undefined } }); assert.strictEqual(par(1), true); } catch (e) { assert.ok(false, e.message); } delete numberProto.a; delete numberProto.b; });