fredrick / gauss

JavaScript statistics, analytics, and data library - Node.js and web browser ready
https://npmjs.org/package/gauss
Other
433 stars 29 forks source link

.findOne on Vector returns an array containing a single element instead of just a single element. #20

Closed jetpad closed 10 years ago

jetpad commented 10 years ago

I noticed that .findOne on a Vector returns an array of one element which is different than .findOne on a Collection. I looked at it but couldn't determine why there was a difference. I guess you'd want then both to return just the element. Here's a test that shows the problem.

/**

var vows = require('vows'), assert = require('assert');

var Collection = require('../lib/gauss').Collection;

var Vector = require('../lib/gauss').Vector;

var collectionThings = new Collection( { type: 1, age: 1 }, { type: 2, age: 2 }, { type: 1, age: 3 }, { type: 2, age: 4 });

var vectorThings = new Vector( { type: 1, age: 1 }, { type: 2, age: 2 }, { type: 1, age: 3 }, { type: 2, age: 4 });

vows.describe('Collection vs Vector').addBatch({

'Find One in collection': {
'(Predicate)': {
  topic: collectionThings.findOne(function(e) { return e.type === 1 }),
  'Condition by function': function(topic) {
    assert.deepEqual(topic, { type: 1, age: 1 } );
  }
}

},

'Find One in collection': {
'(Condition by Object key)': {
  topic: collectionThings.findOne( { type: 1 } ),
  'Condition by function': function(topic) {
    assert.deepEqual(topic, { type: 1, age: 1 } );
  }
}

},

'Find One in vector': {
'(Predicate)': {
  topic: vectorThings.findOne(function(e) { return e.type === 1 }),
  'Condition by function': function(topic) {
    assert.deepEqual(topic, { type: 1, age: 1 } ); 
  }
}

},

'Find One in vector': {
'(Condition by Object key)': {
  topic: vectorThings.findOne( { type: 1 } ),
  'Condition by function': function(topic) {
    assert.deepEqual(topic, { type: 1, age: 1 } );  
  }
}

} }).export(module);

fredrick commented 10 years ago

Thanks for bug report, I will be rolling this into 0.2.10 shortly.

fredrick commented 10 years ago

0.2.11 has been released, thanks again!