/* global browser, it, describe, beforeEach */
describe('Immutable data structure', function () {
  'use strict';

  var runner;
  var benchpress;

  function benchmark(dataSize, bindingsCount, done) {
    //Tells protractor this isn't an Angular 1 application
    browser.ignoreSynchronization = true;
    //Load the benchmark, with a tree depth of 9
    browser
    .get('http://localhost:8080/#/?bindingsCount=' +
      bindingsCount + '&dataSize=' + dataSize);
    /*
     * Tell benchpress to click the buttons to destroy and
     * re-create the tree for each sample.
     * Benchpress will log the collected metrics after each
     * sample is collected, and will stop
     * sampling as soon as the calculated regression slope
     * for last 20 samples is stable.
     */
    runner.sample({
      id: 'immutable-test',
      execute: function () {
        /*
         * Will call querySelector in the browser, but
         * benchpress is smart enough to ignore injected
         * script.
         */
        $('#immutable-btn').click();
        $('#clear-btn').click();
      }
    }).then(function (res) {
      console.log('hereee', res.validSample);
      done();
    }, done.fail);
  }

  beforeEach(function () {
    benchpress = require('benchpress');
    runner = new benchpress.Runner([
      benchpress.MultiReporter.createBindings([
        benchpress.ConsoleReporter,
        benchpress.JsonFileReporter
      ]),
      benchpress.JsonFileReporter.BINDINGS,
      benchpress.bind(benchpress.JsonFileReporter.PATH).toValue('./log/'),
      //use protractor as Webdriver client
      benchpress.SeleniumWebDriverAdapter.PROTRACTOR_BINDINGS,
      //use RegressionSlopeValidator to validate samples
      benchpress.Validator.bindTo(benchpress.RegressionSlopeValidator),
      //use 20 samples to calculate slope regression
      benchpress.bind(benchpress.RegressionSlopeValidator.SAMPLE_SIZE)
        .toValue(20),
//      //use the script metric to calculate slope regression
//      benchpress.bind(benchpress.RegressionSlopeValidator.METRIC)
//        .toValue('script'),
      benchpress.bind(benchpress.Options.FORCE_GC).toValue(true)
    ]);
  });

  var dataSizes = [5, 10, 20, 50];//, 100, 500, 1000, 2000, 5000, 10000, 100000];
  var bindingsCount = [5, 10, 20, 40, 50];

  var product = [];
  for (var s = 0; s < dataSizes.length; s += 1) {
    for (var c = 0; c < bindingsCount.length; c += 1) {
      product.push({
        dataSize: dataSizes[s],
        bindingsCount: bindingsCount[c]
      });
    }
  }

  product.forEach(function (b) {
    it('runs with ' + b.dataSize + ' data size, ' +
      b.bindingsCount + ' bindings',
      function (done) {
        benchmark(b.dataSize, b.bindingsCount, done);
      });
  });
});

@@ -152,17 +152,29 @@
 unction 
-b
+runImmutableB
 enchmark
@@ -831,13 +831,42 @@
 ble-
-test'
+' + dataSize + '-' + bindingsCount
 ,%0A  
@@ -1140,90 +1140,1028 @@
 hen(
-function (res) %7B%0A      console.log('hereee', res.validSample);%0A      done();%0A    %7D
+done, done.fail);%0A  %7D%0A%0A  function runStandardBenchmark(dataSize, bindingsCount, done) %7B%0A    //Tells protractor this isn't an Angular 1 application%0A    browser.ignoreSynchronization = true;%0A    //Load the benchmark, with a tree depth of 9%0A    browser%0A    .get('http://localhost:8080/#/?bindingsCount=' +%0A      bindingsCount + '&dataSize=' + dataSize);%0A    /*%0A     * Tell benchpress to click the buttons to destroy and%0A     * re-create the tree for each sample.%0A     * Benchpress will log the collected metrics after each%0A     * sample is collected, and will stop%0A     * sampling as soon as the calculated regression slope%0A     * for last 20 samples is stable.%0A     */%0A    runner.sample(%7B%0A      id: 'immutable-' + dataSize + '-' + bindingsCount,%0A      execute: function () %7B%0A        /*%0A         * Will call querySelector in the browser, but%0A         * benchpress is smart enough to ignore injected%0A         * script.%0A         */%0A        $('#standard-btn').click();%0A        $('#clear-btn').click();%0A      %7D%0A    %7D).then(done
 , do
@@ -2909,18 +2909,16 @@
 ue(20),%0A
-//
       //
@@ -3183,12 +3183,8 @@
 , 50
-%5D;//
 , 10
@@ -3659,25 +3659,37 @@
 ) %7B%0A        
-b
+runImmutableB
 enchmark(b.d
@@ -3737,12 +3737,241 @@
 ;%0A  %7D);%0A
+%0A  product.forEach(function (b) %7B%0A    it('runs with ' + b.dataSize + ' data size, ' +%0A      b.bindingsCount + ' bindings',%0A      function (done) %7B%0A        runStandardBenchmark(b.dataSize, b.bindingsCount, done);%0A      %7D);%0A  %7D);%0A%0A
 %7D);%0A

Add benchmarks for the standard data structures