Skip to content

Commit

Permalink
Separate out a core compatible dist bundle packaged w/ bignumber (#29)
Browse files Browse the repository at this point in the history
* Separate out a core compatible dist bundle packaged w/ bignumber

* Add minified core compatible bundle

* Flatten minor version and camelCaseIfy vars

* Updated distribution bundles

* Calculate allowed sample stopping point once

* Update readme documentation to describe the usage of planout_core_compatible

* Get tests working for default planout dist bundle only. Still need to figure out a clean way to test core compatible random ops.

* Fully instrument core compatible tests for testAssignment

* Instrument experiment enrollment unit tests for copmat mode

* Make all unit tests work w/ core compatible bundle

* Also make interpreter unit tests core compatible
  • Loading branch information
mattrheault authored and Guy Aridor committed Jul 21, 2016
1 parent 08b2bd0 commit c957bc4
Show file tree
Hide file tree
Showing 21 changed files with 7,444 additions and 5,007 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ bower install planout

PlanOut.js provides an implementation of all PlanOut features (including the
experiment class, interpreter, and namespaces). The underlying randomization ops in the JavaScript implementation return different
results for efficiency reasons. If you are using PlanOut cross-platform and want to enable compatibility mode then you can enable it by calling ```ExperimentSetup.toggleCompatibleHash(true)```.
results for efficiency reasons. If you are using PlanOut cross-platform and want to enable compatibility mode then you can enable it by utilizing the ```planout_core_compatible.js``` distribution bundle instead of the default ```planout.js``` bundle.

The ```planout_core_compatible.js``` bundle should be used only if you want your random operation results to match that of the results from other planout implementations (java, python, etc). The filesize of the ```planout_core_compatible.js``` bundle is fairly larger (by ~100kb) and random operations are processed slower.

## Usage

Expand Down
68 changes: 61 additions & 7 deletions __tests__/testAssignment.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
var Assignment = require('../es6/assignment');
var UniformChoice = require('../es6/ops/random').UniformChoice;
var ExperimentSetup = require('../es6/experimentSetup');
var Assignment = require.requireActual('../dist/planout.js').Assignment;
var UniformChoice = require.requireActual('../dist/planout.js').Ops.Random.UniformChoice;
var AssignmentCompat = require.requireActual('../dist/planout_core_compatible.js').Assignment;
var UniformChoiceCompat = require.requireActual('../dist/planout_core_compatible.js').Ops.Random.UniformChoice;

var testerUnit = '4';
var testerSalt = 'test_salt';


describe('Test the assignment module', function() {
beforeEach(() => {
ExperimentSetup.toggleCompatibleHash(true);
})
it('Should set constants correctly', function() {
var a = new Assignment(testerSalt);
a.set('foo', 12);
expect(a.get('foo')).toBe(12);
});

it('Should set constants correctly (compat)', function() {
var a = new AssignmentCompat(testerSalt);
a.set('foo', 12);
expect(a.get('foo')).toBe(12);
});

it('Should work with uniform choice', function() {
var a = new Assignment(testerSalt);
var choices = ['a', 'b'];

a.set('foo', new UniformChoice({'choices': choices, 'unit': testerUnit}));
a.set('bar', new UniformChoice({'choices': choices, 'unit': testerUnit}));
a.set('baz', new UniformChoice({'choices': choices, 'unit': testerUnit}));

expect(a.get('foo')).toEqual('a');
expect(a.get('bar')).toEqual('a');
expect(a.get('baz')).toEqual('a');
});

it('Should work with uniform choice (compat)', function() {
var a = new AssignmentCompat(testerSalt);
var choices = ['a', 'b'];

a.set('foo', new UniformChoiceCompat({'choices': choices, 'unit': testerUnit}));
a.set('bar', new UniformChoiceCompat({'choices': choices, 'unit': testerUnit}));
a.set('baz', new UniformChoiceCompat({'choices': choices, 'unit': testerUnit}));

expect(a.get('foo')).toEqual('b');
expect(a.get('bar')).toEqual('a');
expect(a.get('baz')).toEqual('a');
Expand All @@ -36,6 +55,15 @@ describe('Test the assignment module', function() {
expect(a.get('y')).toEqual(43);
});

it('Should work with overrides (compat)', function() {
var a = new AssignmentCompat(testerSalt);
a.setOverrides({'x': 42, 'y': 43});
a.set('x', 5);
a.set('y', 6);
expect(a.get('x')).toEqual(42);
expect(a.get('y')).toEqual(43);
});

it('Should work with falsy overrides', function() {
var a = new Assignment(testerSalt);
a.setOverrides({'x': 0, 'y': '', 'z': false});
Expand All @@ -47,12 +75,38 @@ describe('Test the assignment module', function() {
expect(a.get('z')).toEqual(false);
});

it('Should work with falsy overrides (compat)', function() {
var a = new AssignmentCompat(testerSalt);
a.setOverrides({'x': 0, 'y': '', 'z': false});
a.set('x', 5);
a.set('y', 6);
a.set('z', 7);
expect(a.get('x')).toEqual(0);
expect(a.get('y')).toEqual('');
expect(a.get('z')).toEqual(false);
});

it('Should work with custom salts', function() {
var a = new Assignment(testerSalt);

a.set('foo', new UniformChoice({'choices': [0, 1, 2, 3, 4, 5, 6, 7], 'unit': testerUnit }));
expect(a.get('foo')).toEqual(7);
expect(a.get('foo')).toEqual(2);

a.set('saltSeparator', ',');
a.set('foo', new UniformChoice({'choices': [0, 1, 2, 3, 4, 5, 6, 7], 'unit': testerUnit }));

expect(a.get('foo')).toEqual(7);
});

it('Should work with custom salts (compat)', function() {
var a = new AssignmentCompat(testerSalt);

a.set('foo', new UniformChoiceCompat({'choices': [0, 1, 2, 3, 4, 5, 6, 7], 'unit': testerUnit }));
expect(a.get('foo')).toEqual(7);

a.set('saltSeparator', ',');
a.set('foo', new UniformChoiceCompat({'choices': [0, 1, 2, 3, 4, 5, 6, 7], 'unit': testerUnit }));

expect(a.get('foo')).toEqual(6);
});
});
Loading

0 comments on commit c957bc4

Please sign in to comment.