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 = {
|
|
|
|
control: 0,
|
|
|
|
A: 0,
|
|
|
|
B: 0
|
|
|
|
},
|
|
|
|
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-07-02 13:15:04 +00:00
|
|
|
config = util.extend( {}, defaultConfig, { sessionId: mw.user.generateRandomSessionId() } );
|
|
|
|
bucketingTest = new AB( config );
|
2018-08-13 21:54:24 +00:00
|
|
|
if ( bucketingTest.isA() ) {
|
|
|
|
++userBuckets.A;
|
|
|
|
} else if ( bucketingTest.isB() ) {
|
|
|
|
++userBuckets.B;
|
|
|
|
} else if ( !bucketingTest.isEnabled() ) {
|
|
|
|
++userBuckets.control;
|
|
|
|
} else {
|
|
|
|
throw new Error( 'Unknown bucket!' );
|
|
|
|
}
|
2018-05-09 15:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
( userBuckets.control / maxUsers > 0.4 ) &&
|
|
|
|
( userBuckets.control / maxUsers < 0.6 ),
|
|
|
|
true, 'test control group is about 50% (' + userBuckets.control / 10 + '%)' );
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
( userBuckets.A / maxUsers > 0.2 ) &&
|
|
|
|
( userBuckets.A / maxUsers < 0.3 ),
|
|
|
|
true, 'test group A is about 25% (' + userBuckets.A / 10 + '%)' );
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
( userBuckets.B / maxUsers > 0.2 ) &&
|
|
|
|
( userBuckets.B / maxUsers < 0.3 ),
|
|
|
|
true, 'test group B is about 25% (' + userBuckets.B / 10 + '%)' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
}( mw.mobileFrontend ) );
|