2018-05-09 15:14:44 +00:00
|
|
|
( function ( M ) {
|
|
|
|
|
|
|
|
var AB = M.require( 'skins.minerva.scripts/AB' ),
|
2018-07-02 13:15:04 +00:00
|
|
|
util = M.require( 'mobile.startup/util' ),
|
|
|
|
defaultConfig = {
|
|
|
|
testName: 'WME.MinervaABTest',
|
|
|
|
samplingRate: 0.5,
|
|
|
|
sessionId: mw.user.generateRandomSessionId()
|
|
|
|
};
|
2018-05-09 15:14:44 +00:00
|
|
|
|
|
|
|
QUnit.module( 'Minerva AB-test' );
|
|
|
|
|
|
|
|
QUnit.test( 'Bucketing test', function ( assert ) {
|
|
|
|
var userBuckets = {
|
2018-10-26 00:10:06 +00:00
|
|
|
unsampled: 0,
|
2018-05-09 15:14:44 +00:00
|
|
|
control: 0,
|
2018-10-26 00:10:06 +00:00
|
|
|
treatment: 0
|
2018-05-09 15:14:44 +00:00
|
|
|
},
|
|
|
|
maxUsers = 1000,
|
|
|
|
bucketingTest,
|
2018-07-02 13:15:04 +00:00
|
|
|
config,
|
2018-05-09 15:14:44 +00:00
|
|
|
i;
|
|
|
|
|
|
|
|
for ( i = 0; i < maxUsers; i++ ) {
|
2018-09-13 15:33:20 +00:00
|
|
|
config = util.extend( {}, defaultConfig, {
|
|
|
|
sessionId: mw.user.generateRandomSessionId()
|
|
|
|
} );
|
2018-07-02 13:15:04 +00:00
|
|
|
bucketingTest = new AB( config );
|
2018-10-26 00:10:06 +00:00
|
|
|
if ( bucketingTest.isControl() ) {
|
2018-08-13 21:54:24 +00:00
|
|
|
++userBuckets.control;
|
2018-10-26 00:10:06 +00:00
|
|
|
} else if ( bucketingTest.isTreatment() ) {
|
|
|
|
++userBuckets.treatment;
|
|
|
|
} else if ( !bucketingTest.isSampled() ) {
|
|
|
|
++userBuckets.unsampled;
|
2018-08-13 21:54:24 +00:00
|
|
|
} else {
|
|
|
|
throw new Error( 'Unknown bucket!' );
|
|
|
|
}
|
2018-05-09 15:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert.strictEqual(
|
2018-10-26 00:10:06 +00:00
|
|
|
( userBuckets.unsampled / maxUsers > 0.4 ) &&
|
|
|
|
( userBuckets.unsampled / maxUsers < 0.6 ),
|
|
|
|
true, 'test unsampled group is about 50% (' + userBuckets.unsampled / 10 + '%)' );
|
2018-05-09 15:14:44 +00:00
|
|
|
|
|
|
|
assert.strictEqual(
|
2018-10-26 00:10:06 +00:00
|
|
|
( userBuckets.control / maxUsers > 0.2 ) &&
|
|
|
|
( userBuckets.control / maxUsers < 0.3 ),
|
|
|
|
true, 'test control group is about 25% (' + userBuckets.control / 10 + '%)' );
|
2018-05-09 15:14:44 +00:00
|
|
|
|
|
|
|
assert.strictEqual(
|
2018-10-26 00:10:06 +00:00
|
|
|
( userBuckets.treatment / maxUsers > 0.2 ) &&
|
|
|
|
( userBuckets.treatment / maxUsers < 0.3 ),
|
|
|
|
true, 'test new treatment group is about 25% (' + userBuckets.treatment / 10 + '%)' );
|
2018-05-09 15:14:44 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
}( mw.mobileFrontend ) );
|