Created
June 17, 2015 22:47
-
-
Save thecaddy/beb959ccfdb5a298deae to your computer and use it in GitHub Desktop.
Dedupe Perf Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//PUT YOUR SHIT HERE | |
//var detectDupes = require('YOUR JUNK IN THE TRUNK'); | |
var chai = require('chai'); | |
var expect = chai.expect; | |
var moment = require('moment'); | |
var _ = require('lodash-node'); | |
describe('Order Dup Test', function(){ | |
var order = { | |
orderId: '23084ldskjf', | |
orderDate: moment().toISOString(), | |
shippingState: 'WA', | |
shippingZip: '98101', | |
shipping: 30.00, | |
shippingTax: 1.00 | |
} | |
it('should have no dupes', function(done) { | |
var testOrder = _.extend({}, order); | |
testOrder.shippingTax = Math.random().toString(); | |
var testOrder2 = _.extend({}, order); | |
testOrder2.orderId = Math.random().toString(); | |
var testOrder3 = _.extend({}, order); | |
testOrder3.orderId = Math.random().toString(); | |
var dupes = detectDupes([ | |
testOrder, | |
testOrder2, | |
testOrder3 | |
]); | |
expect(dupes).to.be.empty; | |
done(); | |
}); | |
it('should process duplicate orders', function(done){ | |
var testOrder = _.extend({}, order); | |
testOrder.orderId = Math.random().toString(); | |
testOrder.shippingTax = '.00'; | |
var testOrder2 = _.extend({}, order); | |
testOrder2.orderId = Math.random().toString(); | |
var testOrder3 = _.extend({}, order); | |
testOrder3.orderId = Math.random().toString(); | |
var dupes = detectDupes([testOrder, testOrder, testOrder, | |
testOrder2, testOrder2, testOrder3]); | |
expect(dupes[testOrder.orderId]).to.equal(3); | |
expect(dupes[testOrder2.orderId]).to.equal(2); | |
expect(dupes[testOrder3]).to.be.undefined; | |
done(); | |
}); | |
it('should process duplicate orders with same id', function(done){ | |
var testOrder = _.extend({}, order); | |
testOrder.shippingTax = '.00'; | |
var testOrder2 = _.extend({}, order); | |
testOrder2.shippingTax = Math.random().toString(); | |
var testOrder3 = _.extend({}, order); | |
testOrder3.shippingTax = Math.random().toString(); | |
var dupes = detectDupes([testOrder, testOrder, testOrder, | |
testOrder2, testOrder2, testOrder3]); | |
expect(dupes[testOrder.orderId]).to.equal(3); | |
done(); | |
}); | |
[1000,10000,100000,1000000].forEach(function(item, index){ | |
it('should process ' + item + ' duplicate orders', function(done) { | |
var testOrder = _.extend({}, order); | |
testOrder.orderId = Math.random().toString(); | |
var testArr = [] | |
for(var i = 0, len = item; i < len; i++){ | |
testArr.push(testOrder); | |
} | |
var start = moment(); | |
var dupes = detectDupes(testArr); | |
var ms = moment.duration(moment().diff(start)).asMilliseconds(); | |
expect(dupes[testOrder.orderId]).to.be.ok; | |
expect(dupes[testOrder.orderId]).to.equal(item); | |
console.log('TOOK: ' + ms + 'ms'); | |
done(); | |
}); | |
}) | |
}) |
It's okay you think you winnin'
wit' that icy code you spinnin'
These tests are.... ................... 😵
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|_| on chin