2017-08-10 17:55:26 +00:00
|
|
|
import * as stubs from './stubs';
|
|
|
|
import getUserBucket from '../../src/getUserBucket';
|
|
|
|
|
|
|
|
QUnit.module( 'ext.popups#getUserBucket' );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'If no users are subject to experiment everyone is bucketed as on', ( assert ) => {
|
2018-01-18 18:48:16 +00:00
|
|
|
assert.ok(
|
|
|
|
getUserBucket( stubs.createStubExperiments( 'A' ), 0, 'a' ) === 'on' );
|
2017-08-10 17:55:26 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'Define how experiment size impacts buckets', function ( assert ) {
|
2018-03-15 16:30:11 +00:00
|
|
|
let tests = [
|
2017-08-10 17:55:26 +00:00
|
|
|
[ 1, { off: 0, control: 0.5, on: 0.5 } ],
|
|
|
|
[ 0.9, { off: 0.1, control: 0.45, on: 0.45 } ],
|
|
|
|
[ 0.3, { off: 0.7, control: 0.15, on: 0.15 } ],
|
|
|
|
[ 0.5, { off: 0.5, control: 0.25, on: 0.25 } ],
|
|
|
|
[ 0.45, { off: 0.55, control: 0.225, on: 0.225 } ],
|
|
|
|
[ 0.006, { off: 0.994, control: 0.003, on: 0.003 } ]
|
|
|
|
];
|
|
|
|
|
|
|
|
tests.forEach( ( test ) => {
|
2018-03-15 16:30:11 +00:00
|
|
|
let actualBuckets,
|
2017-08-10 17:55:26 +00:00
|
|
|
experiments = stubs.createStubExperiments( 'A' ),
|
|
|
|
spy = this.sandbox.spy( experiments, 'getBucket' ),
|
|
|
|
expectedBuckets = test[ 1 ];
|
|
|
|
|
|
|
|
getUserBucket( experiments, test[ 0 ], 'a' );
|
|
|
|
|
|
|
|
actualBuckets = spy.getCall( 0 ).args[ 0 ].buckets;
|
2018-01-18 18:48:16 +00:00
|
|
|
// To avoid precision issues we'll need to test them all individually
|
|
|
|
// rather than check use calledWith. Otherwise we'll get some false
|
|
|
|
// positives.
|
|
|
|
assert.ok(
|
|
|
|
actualBuckets.off.toFixed( 2 ) === expectedBuckets.off.toFixed( 2 ) );
|
|
|
|
assert.ok(
|
|
|
|
actualBuckets.on.toFixed( 2 ) === expectedBuckets.on.toFixed( 2 ) );
|
|
|
|
assert.ok(
|
|
|
|
actualBuckets.control.toFixed( 2 ) ===
|
|
|
|
expectedBuckets.control.toFixed( 2 )
|
|
|
|
);
|
2017-08-10 17:55:26 +00:00
|
|
|
} );
|
|
|
|
} );
|