<commit_before>import assert from 'power-assert';
import sinon from 'sinon';
import forEach from '../lib';

/** @test {forEach} */
describe('mocha-each', () => {
  const mochaIt = it;
  let _it = null;

  beforeEach(() => {
    _it = sinon.spy();
    global.it = mochaIt;
  });

  it('uses global `it` automatically', () => {
    global.it = _it;
    forEach([0]).it('', () => {});
    assert(_it.calledOnce);
  });

  it('accepts a second argument which specifies `it` explicitly', () => {
    forEach([0], _it).it('', () => {});
    assert(_it.calledOnce);
  });

  it('binds `this` to the context of `it` (Mocha instance)', () => {
    const test = sinon.spy();
    const _this = {};
    const _it = (name, b) => body = b;
    let body;
    forEach([0], _it).it('', test);
    body.call(_this);
    assert.equal(test.thisValues[0], _this);
  });

  context('without Mocha', () => {
    it('throws an error when called', () => {
      delete global.it;
      assert.throws(() => {
        forEach([0]).it('', () => {});
      }, /it is not a function/);
    });
  });

  context('with string title', () => {
    it('defines titles using the specified one and each index', () => {
      forEach([3, 2, 1, 0], _it).it('title', () => {});
      assert.deepEqual(
        _it.args.map(a => a[0]),
        [1, 2, 3, 4].map(i => `title (case ${i})`)
      );
    });
  });

  context('with function title', () => {
    it('calls the function and defines titles using its return value', () => {
      forEach([
        4, 8, 12, 16
      ], _it)
      .it(
        p => `generated ${p / 2}`,
        () => {}
      );
      assert.deepEqual(
        _it.args.map(a => a[0]),
        [2, 4, 6, 8].map(n => `generated ${n}`)
      );
    });
  });

  context('with empty parameters', () => {
    it('defines no test cases', () => {
      forEach([], _it).it('', () => {});
      assert(! _it.calledOnce);
    });
  });

  context('with valid parameters', () => {
    it('defines the same number of test cases as the parameters', () => {
      const params = [0, 1, 2, 3, 4, 5];
      forEach(params, _it).it('', () => {});
      assert.equal(_it.callCount, params.length);
    });

    it('gives each parameter as arguments to the test function', () => {
      const params = [
        [0, 1, 2],
        [[2, 4, 6], 40.5],
        [[1, 2, 3], [4, 5, 6]],
        ['foo', 'bar'],
        ['name', { a: 1, b: 1, c: 1 }, {n: []}],
        [null, undefined, undefined, false]
      ];
      const test = sinon.spy();
      const _it = (name, body) => body();
      forEach(params, _it).it('', test);
      assert.deepEqual(test.args, params);
    });

    context('which is an array of non-array values', () => {
      it('passes each parameter as a first argument', () => {
        const params = [0, 1, 2, 3];
        const test = sinon.spy();
        const _it = (name, body) => body();
        forEach(params, _it).it('', test);
        assert.deepEqual(
          test.args,
          params.map(p => [p])
        );
      });
    });
  });

  context('for asynchronous test', () => {
    context('when the test function takes an additional argument', () => {
      it('gives a `done` callback used for asynchronous code', () => {
        let args;
        const resolve = () => {};
        forEach(
          [[1, 2]],
          (name, body) => body(resolve)
        )
        .it('', (one, two, done) => {
          args = [one, two, done];
        });
        assert.deepEqual(args, [1, 2, resolve]);
      });

      it('binds `this` to the context of `it` (Mocha instance)', () => {
        const expectedThis = {};
        let actualThis;
        let body;
        forEach(
          [0],
          (name, b) => body = b
        ).it('', function(n, done) {
          actualThis = this;
          done();
        });
        body.call(expectedThis, () => {});
        assert.equal(actualThis, expectedThis);
      });
    });

    context('when the lengths of parameters are different', () => {
      context('if any param is many more than the arguments', () => {
        it('gives a `done` callback', () => {
          let args = [];
          const resolve = () => {};
          forEach(
            [ [1, 2], [3, 4, 5], [6] ],
            (name, body) => body(resolve)
          )
          .it('', (a, b, c, done) => {
            args.push([a, b, c, done]);
          });
          assert.deepEqual(args, [
            [1, 2, resolve, undefined],
            [3, 4, 5, resolve],
            [6, resolve, undefined, undefined]
          ]);
        });
      });

      context('otherwise', () => {
        it('does not give a `done` callback', () => {
          let args = [];
          forEach(
            [ [1, 2], [3, 4, 5, 6], [7] ],
            (name, body) => body(() => {})
          )
          .it('', (a, b, c, d) => {
            args.push([a, b, c, d]);
          });
          assert.deepEqual(args, [
            [1, 2, undefined, undefined],
            [3, 4, 5, 6],
            [7, undefined, undefined, undefined]
          ]);
        });
      });
    });

    context('when the parameters are arrays of non-array values', () => {
      it('gives a `done` callback', () => {
        let args = [];
        const resolve = () => {};
        forEach(
          [0, 1, 2],
          (name, body) => body(resolve)
        )
        .it('', (n, done) => {
          args.push([n, done]);
        });
        assert.deepEqual(args, [
          [0, resolve],
          [1, resolve],
          [2, resolve]
        ]);
      });
    });
  });

  describe('.it.only()', () => {
    const mochaDescribe = describe;
    let _describe;

    beforeEach(() => {
      _describe = sinon.spy();
      _describe.only = sinon.spy();
      global.describe = _describe;
    });

    afterEach(() => {
      global.describe = mochaDescribe;
    });

    it('creates a nameless test suite', () => {
      forEach([0], _it).it.only('', () => {});
      const suiteTitle = _describe.only.args[0][0];
      assert.equal(suiteTitle, '');
    });

    it('creates a test suite using its `.only()` method', () => {
      const _descOnly = _describe.only;
      const params = [0, 1, 2, 3];
      forEach(params, _it).it.only('', () => {});

      assert.deepEqual(
        [_descOnly.callCount, _it.callCount],
        [1, 0]
      );
      assert.deepEqual(
        _descOnly.args[0].map(a => typeof a),
        ['string', 'function']
      );

      const runTestSuite = _descOnly.args[0][1];
      runTestSuite();

      assert.equal(_it.callCount, params.length);
      assert.equal(_describe.callCount, 0);
    });
  });

  describe('.it.skip()', () => {
    beforeEach(() => _it.skip = sinon.spy());
    afterEach(() => delete _it.skip);

    it('defines each test case using Mocha\'s `it.skip()` method', () => {
      const params = [3, 2, 1, 0];
      const makeTitle = p => `test for ${p}`;
      forEach(params, _it).it.skip(makeTitle, () => {});
      assert.deepEqual(
        _it.skip.args.map(a => a[0]),
        params.map(makeTitle)
      );
    });
  });
});

<commit_msg>:bug: Fix expected error message<commit_after>import assert from 'power-assert';
import sinon from 'sinon';
import forEach from '../lib';

/** @test {forEach} */
describe('mocha-each', () => {
  const mochaIt = it;
  let _it = null;

  beforeEach(() => {
    _it = sinon.spy();
    global.it = mochaIt;
  });

  it('uses global `it` automatically', () => {
    global.it = _it;
    forEach([0]).it('', () => {});
    assert(_it.calledOnce);
  });

  it('accepts a second argument which specifies `it` explicitly', () => {
    forEach([0], _it).it('', () => {});
    assert(_it.calledOnce);
  });

  it('binds `this` to the context of `it` (Mocha instance)', () => {
    const test = sinon.spy();
    const _this = {};
    const _it = (name, b) => body = b;
    let body;
    forEach([0], _it).it('', test);
    body.call(_this);
    assert.equal(test.thisValues[0], _this);
  });

  context('without Mocha', () => {
    it('throws an error when called', () => {
      delete global.it;
      assert.throws(() => {
        forEach([0]).it('', () => {});
      }, /is not a function/);
    });
  });

  context('with string title', () => {
    it('defines titles using the specified one and each index', () => {
      forEach([3, 2, 1, 0], _it).it('title', () => {});
      assert.deepEqual(
        _it.args.map(a => a[0]),
        [1, 2, 3, 4].map(i => `title (case ${i})`)
      );
    });
  });

  context('with function title', () => {
    it('calls the function and defines titles using its return value', () => {
      forEach([
        4, 8, 12, 16
      ], _it)
      .it(
        p => `generated ${p / 2}`,
        () => {}
      );
      assert.deepEqual(
        _it.args.map(a => a[0]),
        [2, 4, 6, 8].map(n => `generated ${n}`)
      );
    });
  });

  context('with empty parameters', () => {
    it('defines no test cases', () => {
      forEach([], _it).it('', () => {});
      assert(! _it.calledOnce);
    });
  });

  context('with valid parameters', () => {
    it('defines the same number of test cases as the parameters', () => {
      const params = [0, 1, 2, 3, 4, 5];
      forEach(params, _it).it('', () => {});
      assert.equal(_it.callCount, params.length);
    });

    it('gives each parameter as arguments to the test function', () => {
      const params = [
        [0, 1, 2],
        [[2, 4, 6], 40.5],
        [[1, 2, 3], [4, 5, 6]],
        ['foo', 'bar'],
        ['name', { a: 1, b: 1, c: 1 }, {n: []}],
        [null, undefined, undefined, false]
      ];
      const test = sinon.spy();
      const _it = (name, body) => body();
      forEach(params, _it).it('', test);
      assert.deepEqual(test.args, params);
    });

    context('which is an array of non-array values', () => {
      it('passes each parameter as a first argument', () => {
        const params = [0, 1, 2, 3];
        const test = sinon.spy();
        const _it = (name, body) => body();
        forEach(params, _it).it('', test);
        assert.deepEqual(
          test.args,
          params.map(p => [p])
        );
      });
    });
  });

  context('for asynchronous test', () => {
    context('when the test function takes an additional argument', () => {
      it('gives a `done` callback used for asynchronous code', () => {
        let args;
        const resolve = () => {};
        forEach(
          [[1, 2]],
          (name, body) => body(resolve)
        )
        .it('', (one, two, done) => {
          args = [one, two, done];
        });
        assert.deepEqual(args, [1, 2, resolve]);
      });

      it('binds `this` to the context of `it` (Mocha instance)', () => {
        const expectedThis = {};
        let actualThis;
        let body;
        forEach(
          [0],
          (name, b) => body = b
        ).it('', function(n, done) {
          actualThis = this;
          done();
        });
        body.call(expectedThis, () => {});
        assert.equal(actualThis, expectedThis);
      });
    });

    context('when the lengths of parameters are different', () => {
      context('if any param is many more than the arguments', () => {
        it('gives a `done` callback', () => {
          let args = [];
          const resolve = () => {};
          forEach(
            [ [1, 2], [3, 4, 5], [6] ],
            (name, body) => body(resolve)
          )
          .it('', (a, b, c, done) => {
            args.push([a, b, c, done]);
          });
          assert.deepEqual(args, [
            [1, 2, resolve, undefined],
            [3, 4, 5, resolve],
            [6, resolve, undefined, undefined]
          ]);
        });
      });

      context('otherwise', () => {
        it('does not give a `done` callback', () => {
          let args = [];
          forEach(
            [ [1, 2], [3, 4, 5, 6], [7] ],
            (name, body) => body(() => {})
          )
          .it('', (a, b, c, d) => {
            args.push([a, b, c, d]);
          });
          assert.deepEqual(args, [
            [1, 2, undefined, undefined],
            [3, 4, 5, 6],
            [7, undefined, undefined, undefined]
          ]);
        });
      });
    });

    context('when the parameters are arrays of non-array values', () => {
      it('gives a `done` callback', () => {
        let args = [];
        const resolve = () => {};
        forEach(
          [0, 1, 2],
          (name, body) => body(resolve)
        )
        .it('', (n, done) => {
          args.push([n, done]);
        });
        assert.deepEqual(args, [
          [0, resolve],
          [1, resolve],
          [2, resolve]
        ]);
      });
    });
  });

  describe('.it.only()', () => {
    const mochaDescribe = describe;
    let _describe;

    beforeEach(() => {
      _describe = sinon.spy();
      _describe.only = sinon.spy();
      global.describe = _describe;
    });

    afterEach(() => {
      global.describe = mochaDescribe;
    });

    it('creates a nameless test suite', () => {
      forEach([0], _it).it.only('', () => {});
      const suiteTitle = _describe.only.args[0][0];
      assert.equal(suiteTitle, '');
    });

    it('creates a test suite using its `.only()` method', () => {
      const _descOnly = _describe.only;
      const params = [0, 1, 2, 3];
      forEach(params, _it).it.only('', () => {});

      assert.deepEqual(
        [_descOnly.callCount, _it.callCount],
        [1, 0]
      );
      assert.deepEqual(
        _descOnly.args[0].map(a => typeof a),
        ['string', 'function']
      );

      const runTestSuite = _descOnly.args[0][1];
      runTestSuite();

      assert.equal(_it.callCount, params.length);
      assert.equal(_describe.callCount, 0);
    });
  });

  describe('.it.skip()', () => {
    beforeEach(() => _it.skip = sinon.spy());
    afterEach(() => delete _it.skip);

    it('defines each test case using Mocha\'s `it.skip()` method', () => {
      const params = [3, 2, 1, 0];
      const makeTitle = p => `test for ${p}`;
      forEach(params, _it).it.skip(makeTitle, () => {});
      assert.deepEqual(
        _it.skip.args.map(a => a[0]),
        params.map(makeTitle)
      );
    });
  });
});

<|endoftext|>


<commit_before>/*
 Copyright 2008-present Shaiksphere, Inc.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

const mindsmine = require("../../../dist/@REQUIRE_FILE@");

describe("productName", () => {
    test("should return product name", () => {
        expect(mindsmine.productName).toBe("mindsmine-js");
    });
});

describe("productVersion", () => {
    test("should return product version", () => {
        expect(mindsmine.productVersion).toBe("3.1.0");
    });
});

//_CONCATENATED_HELPER_CODE<commit_msg>Updating the version<commit_after>/*
 Copyright 2008-present Shaiksphere, Inc.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

const mindsmine = require("../../../dist/@REQUIRE_FILE@");

describe("productName", () => {
    test("should return product name", () => {
        expect(mindsmine.productName).toBe("mindsmine-js");
    });
});

describe("productVersion", () => {
    test("should return product version", () => {
        expect(mindsmine.productVersion).toBe("3.1.1");
    });
});

//_CONCATENATED_HELPER_CODE<|endoftext|>


<commit_before>'use strict';

var Bluebird  = require('bluebird');
var expect    = require('expect.js');
var helper    = require('./helper');
var Migration = require('../lib/migration');
var Umzug     = require('../index');
var sinon     = require('sinon');

describe('Umzug', function () {
  describe('constructor', function () {
    it('exposes some methods', function () {
      var umzug = new Umzug();

      expect(umzug).to.have.property('execute');
      expect(umzug).to.have.property('pending');
      expect(umzug).to.have.property('up');
      expect(umzug).to.have.property('down');
    });

    it('instantiates the default storage', function () {
      var umzug = new Umzug();
      expect(umzug).to.have.property('storage');
    });

    it('loads the specified storage module', function () {
      var umzug = new Umzug({ storage: 'moment' });
      expect(umzug).to.have.property('storage');
    });

    it('throws an error if the specified storage is neither a package nor a file', function () {
      expect(function () {
        new Umzug({ storage: 'nomnom' });
      }).to.throwError(
        Error, /Unable to resolve the storage: omnom/
      )
    });
  });
});
<commit_msg>added tests for logging parameter<commit_after>'use strict';

var Bluebird  = require('bluebird');
var expect    = require('expect.js');
var helper    = require('./helper');
var Migration = require('../lib/migration');
var Umzug     = require('../index');
var sinon     = require('sinon');

describe('Umzug', function () {
  describe('constructor', function () {
    it('exposes some methods', function () {
      var umzug = new Umzug();

      expect(umzug).to.have.property('execute');
      expect(umzug).to.have.property('pending');
      expect(umzug).to.have.property('up');
      expect(umzug).to.have.property('down');
      expect(umzug).to.have.property('log');
    });

    it('instantiates the default storage', function () {
      var umzug = new Umzug();
      expect(umzug).to.have.property('storage');
    });

    it('loads the specified storage module', function () {
      var umzug = new Umzug({ storage: 'moment' });
      expect(umzug).to.have.property('storage');
    });

    it('throws an error if the specified storage is neither a package nor a file', function () {
      expect(function () {
        new Umzug({ storage: 'nomnom' });
      }).to.throwError(
        Error, /Unable to resolve the storage: omnom/
      )
    });

    it('accepts a logging function', function () {
      var spy = sinon.spy();
      var umzug = new Umzug({ logging: spy });
      umzug.log();
      expect(spy.called).to.be(true);
    });
  });
});
<|endoftext|>


<commit_before>'use strict';
/* jshint expr: true */

const expect = require( 'chai' ).expect;

const ROOT_PATH = '../';

const MODULE_PATH = 'index';

const FULL_MODULE_PATH = ROOT_PATH + MODULE_PATH;

const subzero = require( FULL_MODULE_PATH );

const nodeVersion = Number( process.versions.node.split( '.' )[0] );

describe( MODULE_PATH, function() {

    describe( 'subzero', function() {

        describe( 'no op, return input value (non object, function, or class input)', function() {

            [

                'freeze',
                'megaFreeze'

            ].forEach( function( functionName ) {

                it( `${ functionName } with number input`, function() {

                    const controlNumber = 69;

                    expect( subzero[ functionName ]( controlNumber ) ).to.equal( controlNumber );
                });

                it( `${ functionName } with string input`, function() {

                    const controlString = 'xxx';

                    expect( subzero[ functionName ]( controlString ) ).to.equal( controlString );
                });

                it( `${ functionName } with bool input`, function() {

                    const controlBool = true;

                    expect( subzero[ functionName ]( controlBool ) ).to.equal( controlBool );
                });
            });
        });

        describe( 'freezing functions normal operation', function() {

            [
                {
                    name: 'freeze',

                    innerObjectsWillBeFrozen: false,

                    innerFunctionsAndClassesWillBeFrozen: false,

                    objectsInsideAlreadyFrozenObjectsWillBeFrozen: false,

                    objectsInsideAlreadyFrozenFunctionsWillBeFrozen: false,

                    functionsInsideAlreadyFrozenFunctionsWillBeFrozen: false,

                    functionsInsideAlreadyFrozenObjectsWillBeFrozen: false,

                    bufferWillBeSealedIfVersionIsGreaterOrEqualTo6Dot9: false
                },

                {
                    name: 'megaFreeze',

                    innerObjectsWillBeFrozen: true,

                    innerFunctionsAndClassesWillBeFrozen: true,

                    objectsInsideAlreadyFrozenObjectsWillBeFrozen: true,

                    objectsInsideAlreadyFrozenFunctionsWillBeFrozen: true,

                    functionsInsideAlreadyFrozenFunctionsWillBeFrozen: true,

                    functionsInsideAlreadyFrozenObjectsWillBeFrozen: true,

                    bufferWillBeSealedIfVersionIsGreaterOrEqualTo6Dot9: true
                }

            ].forEach( function( functionData ) {

                [
                    {
                        type: 'object',

                        getVariableToValidate: function() { return {} },

                        secondObjectName: 'a',
                    },

                    {
                        type: 'function',

                        getVariableToValidate: function() { return function() {} },

                        secondObjectName: 'prototype',
                    },

                    {
                        type: 'class',

                        getVariableToValidate: function() { return class {} },

                        secondObjectName: 'prototype',
                    }

                ].forEach( function( subzeroVariableData ) {
                    // NOTE: the subzeroVariable can be an object, a function, or a class

                    it( `${ functionData.name } freezing ${ subzeroVariableData.type }`, function() {

                        const subzeroVariableToValidate = subzeroVariableData.getVariableToValidate();

                        const InnerClass = class {};

                        InnerClass.x = {

                            y: {}
                        };

                        const controlFunction = function() {};

                        controlFunction.x = {

                            y: {}
                        };

                        const objectInsideAlreadyFrozenObject = {};

                        const functionInsideAlreadyFrozenObject = function() {};

                        const objectInsideAlreadyFrozenFunction = {};

                        const functionInsideAlreadyFrozenFunction = function() {};

                        const functionToFreeze = function() {};

                        functionToFreeze.objectInsideAlreadyFrozenFunction = objectInsideAlreadyFrozenFunction;

                        functionToFreeze.functionInsideAlreadyFrozenFunction = functionInsideAlreadyFrozenFunction;

                        const frozenFunctionWithNonFrozenObjectInside = Object.freeze( functionToFreeze );

                        const buff = new Buffer( 69 );

                        buff.x = {

                            y: {},

                            f: function(){}
                        };

                        subzeroVariableToValidate.a = {

                            b: {

                                c: {

                                    d: {

                                        InnerClass,

                                        controlFunction,

                                        buff,

                                        e: Object.freeze({

                                            objectInsideAlreadyFrozenObject,

                                            functionInsideAlreadyFrozenObject
                                        }),

                                        frozenFunctionWithNonFrozenObjectInside
                                    }
                                }
                            }
                        };

                        subzeroVariableToValidate[ subzeroVariableData.secondObjectName ].x = {

                            y: {

                                z: {}
                            },

                            w: {}
                        };

                        expect( subzero[ functionData.name ]( subzeroVariableToValidate ) ).to.equal( subzeroVariableToValidate );

                        expect( Object.isFrozen( subzeroVariableToValidate ) ).to.be.true;
                        expect( Object.isFrozen( subzeroVariableToValidate.a ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( subzeroVariableToValidate.a.b ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( subzeroVariableToValidate.a.b.c ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( subzeroVariableToValidate.a.b.c.d ) ).to.equal( functionData.innerObjectsWillBeFrozen );

                        if( !((subzeroVariableData.type === 'object') && (functionData.name === 'freeze')) ) {

                            expect( Object.isFrozen( subzeroVariableToValidate[ subzeroVariableData.secondObjectName ] ) ).to.be.true;
                        }
                        else {

                            expect( Object.isFrozen( subzeroVariableToValidate[ subzeroVariableData.secondObjectName ] ) ).to.be.false;
                        }

                        expect( Object.isFrozen( subzeroVariableToValidate[ subzeroVariableData.secondObjectName ].x ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( subzeroVariableToValidate[ subzeroVariableData.secondObjectName ].x.y ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( subzeroVariableToValidate[ subzeroVariableData.secondObjectName ].x.y.z ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( subzeroVariableToValidate[ subzeroVariableData.secondObjectName ].x.w ) ).to.equal( functionData.innerObjectsWillBeFrozen );

                        expect( Object.isFrozen( InnerClass ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( InnerClass.prototype ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( InnerClass.x ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( InnerClass.x.y ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );

                        expect( Object.isFrozen( controlFunction ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( controlFunction.prototype ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( controlFunction.x ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( controlFunction.x.y ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );

                        expect( Object.isFrozen( objectInsideAlreadyFrozenObject ) ).to.equal( functionData.objectsInsideAlreadyFrozenObjectsWillBeFrozen );
                        expect( Object.isFrozen( objectInsideAlreadyFrozenFunction ) ).to.equal( functionData.objectsInsideAlreadyFrozenFunctionsWillBeFrozen );

                        expect( Object.isFrozen( functionInsideAlreadyFrozenFunction ) ).to.equal( functionData.functionsInsideAlreadyFrozenFunctionsWillBeFrozen );
                        expect( Object.isFrozen( functionInsideAlreadyFrozenFunction.prototype ) ).to.equal( functionData.objectsInsideAlreadyFrozenFunctionsWillBeFrozen );

                        expect( Object.isFrozen( functionInsideAlreadyFrozenObject ) ).to.equal( functionData.functionsInsideAlreadyFrozenObjectsWillBeFrozen )
                        expect( Object.isFrozen( functionInsideAlreadyFrozenObject.prototype ) ).to.equal( functionData.objectsInsideAlreadyFrozenFunctionsWillBeFrozen );

                        const bufferWillBeSealed = (

                            functionData.bufferWillBeSealedIfVersionIsGreaterOrEqualTo6Dot9 &&
                            (nodeVersion >= 6)
                        );

                        expect( Object.isSealed( buff ) ).to.equal( bufferWillBeSealed );
                        expect( Object.isFrozen( buff.x ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( buff.x.y ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( buff.x.f ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( buff.x.f.prototype ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                    });
                });
            });
        });

        describe( 'other', function() {

            it( 'subzero is mega frozen itself', function() {

                expect( subzero ).to.be.frozen;
                expect( subzero.freeze ).to.be.frozen;
                expect( subzero.megaFreeze ).to.be.frozen;
                /*
                    NOTE: certain functions don't have prototypes <<e.g f in: const o = { f() {} } >>
                    subzero's functions don't have prototypes
                */
            });

            it( 'README.md megaFreeze example test', function() {

                /*
                	this example uses a function,
                    subzero.megaFreeze also works with objects and classes
                */
                function f() {}

                const InnerClass = class {};

                InnerClass.x = {

                    y: {}
                };

                const innerFunction = function() {};

                innerFunction.x = {

                    y: {}
                };

                const objectInsideAlreadyFrozenObject = {};

                const functionInsideAlreadyFrozenObject = function() {};

                const objectInsideAlreadyFrozenFunction = {};

                const functionInsideAlreadyFrozenFunction = function() {};

                const functionToFreeze = function() {};

                functionToFreeze.objectInsideAlreadyFrozenFunction = objectInsideAlreadyFrozenFunction;

                functionToFreeze.functionInsideAlreadyFrozenFunction = functionInsideAlreadyFrozenFunction;

                const frozenFunctionWithNonFrozenObjectAndFunctionInside = Object.freeze( functionToFreeze );

                const buff = new Buffer( 69 );

                buff.x = {

                    y: {},

                    f: function() {}
                };

                f.a = {

                    b: {

                        c: {

                            d: {

                                InnerClass,

                                innerFunction,

                                buff,

                                e: Object.freeze({

                                    objectInsideAlreadyFrozenObject,

                                    functionInsideAlreadyFrozenObject
                                }),

                                frozenFunctionWithNonFrozenObjectAndFunctionInside
                            }
                        }
                    }
                };

                f.prototype.x = {

                    y: {

                        z: {}
                    },

                    w: {}
                };

                /*
                    It's time to freeze your opponent for the flawless victory with fatality.

                	None of the following assertions will throw an AssertionError:
                */

                console.assert( !Object.isFrozen( f ) );
                console.assert( !Object.isFrozen( f.prototype ) );
                console.assert( !Object.isFrozen( f.a ) );
                console.assert( !Object.isFrozen( f.a.b ) );
                console.assert( !Object.isFrozen( f.a.b.c ) );
                console.assert( !Object.isFrozen( f.a.b.c.d ) );
                console.assert( !Object.isFrozen( f.prototype.x ) );
                console.assert( !Object.isFrozen( f.prototype.x.y ) );
                console.assert( !Object.isFrozen( f.prototype.x.y.z ) );
                console.assert( !Object.isFrozen( f.prototype.x.w ) );
                console.assert( !Object.isFrozen( InnerClass ) );
                console.assert( !Object.isFrozen( InnerClass.prototype ) );
                console.assert( !Object.isFrozen( InnerClass.x ) );
                console.assert( !Object.isFrozen( InnerClass.x.y ) );
                console.assert( !Object.isFrozen( innerFunction ) );
                console.assert( !Object.isFrozen( innerFunction.prototype ) );
                console.assert( !Object.isFrozen( innerFunction.x ) );
                console.assert( !Object.isFrozen( innerFunction.x.y ) );
                console.assert( !Object.isFrozen( objectInsideAlreadyFrozenObject ) );
                console.assert( !Object.isFrozen( objectInsideAlreadyFrozenFunction ) );
                console.assert( !Object.isFrozen( functionInsideAlreadyFrozenObject ) );
                console.assert( !Object.isFrozen( functionInsideAlreadyFrozenObject.prototype ) );
                console.assert( !Object.isFrozen( functionInsideAlreadyFrozenFunction ) );
                console.assert( !Object.isFrozen( functionInsideAlreadyFrozenFunction.prototype ) );
                console.assert( !Object.isSealed( buff ) ); // you cannot freeze buffers
                console.assert( !Object.isFrozen( buff.x ) );
                console.assert( !Object.isFrozen( buff.x.y ) );
                console.assert( !Object.isFrozen( buff.x.f ) );
                console.assert( !Object.isFrozen( buff.x.f.prototype ) );

                // Mega Freeze f
                const reference = subzero.megaFreeze( f );

                console.assert( ( reference === f ) );

                console.assert( Object.isFrozen( f ) );
                console.assert( Object.isFrozen( f.prototype ) );
                console.assert( Object.isFrozen( f.a ) );
                console.assert( Object.isFrozen( f.a.b ) );
                console.assert( Object.isFrozen( f.a.b.c ) );
                console.assert( Object.isFrozen( f.a.b.c.d ) );
                console.assert( Object.isFrozen( f.prototype.x ) );
                console.assert( Object.isFrozen( f.prototype.x.y ) );
                console.assert( Object.isFrozen( f.prototype.x.y.z ) );
                console.assert( Object.isFrozen( f.prototype.x.w ) );
                console.assert( Object.isFrozen( InnerClass ) );
                console.assert( Object.isFrozen( InnerClass.prototype ) );
                console.assert( Object.isFrozen( InnerClass.x ) );
                console.assert( Object.isFrozen( InnerClass.x.y ) );
                console.assert( Object.isFrozen( innerFunction ) );
                console.assert( Object.isFrozen( innerFunction.prototype ) );
                console.assert( Object.isFrozen( innerFunction.x ) );
                console.assert( Object.isFrozen( innerFunction.x.y ) );
                console.assert( Object.isFrozen( objectInsideAlreadyFrozenObject ) );
                console.assert( Object.isFrozen( objectInsideAlreadyFrozenFunction ) );
                console.assert( Object.isFrozen( functionInsideAlreadyFrozenObject ) );
                console.assert( Object.isFrozen( functionInsideAlreadyFrozenObject.prototype ) );
                console.assert( Object.isFrozen( functionInsideAlreadyFrozenFunction ) );
                console.assert( Object.isFrozen( functionInsideAlreadyFrozenFunction.prototype ) );
                const nodeVersion = Number( process.versions.node.split( '.' )[0] );
                if( nodeVersion >= 6 ) console.assert( Object.isSealed( buff ) );
                console.assert( Object.isFrozen( buff.x ) );
                console.assert( Object.isFrozen( buff.x.y ) );
                console.assert( Object.isFrozen( buff.x.f ) );
                console.assert( Object.isFrozen( buff.x.f.prototype ) );
            });
        });
    });

    after( function() {

        console.log(`

            Post-test Messages:
        `);

        (function displayMessageAboutCoverage() {

            if( nodeVersion >= 6) {

                console.log(`

                the following coverage results means the code is fully covered for

                node v6 or greater

                current version: ${ nodeVersion }

                ----
                Statements   : 100% ( 36/36 )
                Branches     : 94.44% ( 17/18 )
                Functions    : 100% ( 2/2 )
                Lines        : 100% ( 36/36 )
                ----
                `);
            }
            else {

                console.log(`

                the following coverage results means the code is fully covered for

                less than node v6

                current version: ${ nodeVersion }

                ----
                Statements   : 97.22% ( 35/36 )
                Branches     : 94.44% ( 17/18 )
                Functions    : 100% ( 2/2 )
                Lines        : 97.22% ( 35/36 )
                ----
                `);
            }
        })();
    });
});
<commit_msg>updated<commit_after>'use strict';
/* jshint expr: true */

const expect = require( 'chai' ).expect;

const ROOT_PATH = '../';

const MODULE_PATH = 'index';

const FULL_MODULE_PATH = ROOT_PATH + MODULE_PATH;

const subzero = require( FULL_MODULE_PATH );

const nodeVersion = Number( process.versions.node.split( '.' )[0] );

describe( MODULE_PATH, function() {

    describe( 'subzero', function() {

        describe( 'no op, return input value (non object, function, or class input)', function() {

            [

                'freeze',
                'megaFreeze'

            ].forEach( function( functionName ) {

                it( `${ functionName } with number input`, function() {

                    const controlNumber = 69;

                    expect( subzero[ functionName ]( controlNumber ) ).to.equal( controlNumber );
                });

                it( `${ functionName } with string input`, function() {

                    const controlString = 'xxx';

                    expect( subzero[ functionName ]( controlString ) ).to.equal( controlString );
                });

                it( `${ functionName } with bool input`, function() {

                    const controlBool = true;

                    expect( subzero[ functionName ]( controlBool ) ).to.equal( controlBool );
                });
            });
        });

        describe( 'freezing functions normal operation', function() {

            [
                {
                    name: 'freeze',

                    innerObjectsWillBeFrozen: false,

                    innerFunctionsAndClassesWillBeFrozen: false,

                    objectsInsideAlreadyFrozenObjectsWillBeFrozen: false,

                    objectsInsideAlreadyFrozenFunctionsWillBeFrozen: false,

                    functionsInsideAlreadyFrozenFunctionsWillBeFrozen: false,

                    functionsInsideAlreadyFrozenObjectsWillBeFrozen: false,

                    bufferWillBeSealedIfVersionIsGreaterOrEqualTo6Dot9: false
                },

                {
                    name: 'megaFreeze',

                    innerObjectsWillBeFrozen: true,

                    innerFunctionsAndClassesWillBeFrozen: true,

                    objectsInsideAlreadyFrozenObjectsWillBeFrozen: true,

                    objectsInsideAlreadyFrozenFunctionsWillBeFrozen: true,

                    functionsInsideAlreadyFrozenFunctionsWillBeFrozen: true,

                    functionsInsideAlreadyFrozenObjectsWillBeFrozen: true,

                    bufferWillBeSealedIfVersionIsGreaterOrEqualTo6Dot9: true
                }

            ].forEach( function( functionData ) {

                [
                    {
                        type: 'object',

                        getVariableToValidate: function() { return {} },

                        secondObjectName: 'a',
                    },

                    {
                        type: 'function',

                        getVariableToValidate: function() { return function() {} },

                        secondObjectName: 'prototype',
                    },

                    {
                        type: 'class',

                        getVariableToValidate: function() { return class {} },

                        secondObjectName: 'prototype',
                    }

                ].forEach( function( subzeroVariableData ) {
                    // NOTE: the subzeroVariable can be an object, a function, or a class

                    it( `${ functionData.name } freezing ${ subzeroVariableData.type }`, function() {

                        const subzeroVariableToValidate = subzeroVariableData.getVariableToValidate();

                        const InnerClass = class {};

                        InnerClass.x = {

                            y: {}
                        };

                        const controlFunction = function() {};

                        controlFunction.x = {

                            y: {}
                        };

                        const objectInsideAlreadyFrozenObject = {};

                        const functionInsideAlreadyFrozenObject = function() {};

                        const objectInsideAlreadyFrozenFunction = {};

                        const functionInsideAlreadyFrozenFunction = function() {};

                        const functionToFreeze = function() {};

                        functionToFreeze.objectInsideAlreadyFrozenFunction = objectInsideAlreadyFrozenFunction;

                        functionToFreeze.functionInsideAlreadyFrozenFunction = functionInsideAlreadyFrozenFunction;

                        const frozenFunctionWithNonFrozenObjectInside = Object.freeze( functionToFreeze );

                        const buff = new Buffer( 69 );

                        buff.x = {

                            y: {},

                            f: function(){}
                        };

                        subzeroVariableToValidate.a = {

                            b: {

                                c: {

                                    d: {

                                        InnerClass,

                                        controlFunction,

                                        buff,

                                        e: Object.freeze({

                                            objectInsideAlreadyFrozenObject,

                                            functionInsideAlreadyFrozenObject
                                        }),

                                        frozenFunctionWithNonFrozenObjectInside
                                    }
                                }
                            }
                        };

                        subzeroVariableToValidate[ subzeroVariableData.secondObjectName ].x = {

                            y: {

                                z: {}
                            },

                            w: {}
                        };

                        expect( subzero[ functionData.name ]( subzeroVariableToValidate ) ).to.equal( subzeroVariableToValidate );

                        expect( Object.isFrozen( subzeroVariableToValidate ) ).to.be.true;
                        expect( Object.isFrozen( subzeroVariableToValidate.a ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( subzeroVariableToValidate.a.b ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( subzeroVariableToValidate.a.b.c ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( subzeroVariableToValidate.a.b.c.d ) ).to.equal( functionData.innerObjectsWillBeFrozen );

                        if( !((subzeroVariableData.type === 'object') && (functionData.name === 'freeze')) ) {

                            expect( Object.isFrozen( subzeroVariableToValidate[ subzeroVariableData.secondObjectName ] ) ).to.be.true;
                        }
                        else {

                            expect( Object.isFrozen( subzeroVariableToValidate[ subzeroVariableData.secondObjectName ] ) ).to.be.false;
                        }

                        expect( Object.isFrozen( subzeroVariableToValidate[ subzeroVariableData.secondObjectName ].x ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( subzeroVariableToValidate[ subzeroVariableData.secondObjectName ].x.y ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( subzeroVariableToValidate[ subzeroVariableData.secondObjectName ].x.y.z ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( subzeroVariableToValidate[ subzeroVariableData.secondObjectName ].x.w ) ).to.equal( functionData.innerObjectsWillBeFrozen );

                        expect( Object.isFrozen( InnerClass ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( InnerClass.prototype ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( InnerClass.x ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( InnerClass.x.y ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );

                        expect( Object.isFrozen( controlFunction ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( controlFunction.prototype ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( controlFunction.x ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( controlFunction.x.y ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );

                        expect( Object.isFrozen( objectInsideAlreadyFrozenObject ) ).to.equal( functionData.objectsInsideAlreadyFrozenObjectsWillBeFrozen );
                        expect( Object.isFrozen( objectInsideAlreadyFrozenFunction ) ).to.equal( functionData.objectsInsideAlreadyFrozenFunctionsWillBeFrozen );

                        expect( Object.isFrozen( functionInsideAlreadyFrozenFunction ) ).to.equal( functionData.functionsInsideAlreadyFrozenFunctionsWillBeFrozen );
                        expect( Object.isFrozen( functionInsideAlreadyFrozenFunction.prototype ) ).to.equal( functionData.objectsInsideAlreadyFrozenFunctionsWillBeFrozen );

                        expect( Object.isFrozen( functionInsideAlreadyFrozenObject ) ).to.equal( functionData.functionsInsideAlreadyFrozenObjectsWillBeFrozen )
                        expect( Object.isFrozen( functionInsideAlreadyFrozenObject.prototype ) ).to.equal( functionData.objectsInsideAlreadyFrozenFunctionsWillBeFrozen );

                        const bufferWillBeSealed = (

                            functionData.bufferWillBeSealedIfVersionIsGreaterOrEqualTo6Dot9 &&
                            (nodeVersion >= 6)
                        );

                        expect( Object.isSealed( buff ) ).to.equal( bufferWillBeSealed );
                        expect( Object.isFrozen( buff.x ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( buff.x.y ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                        expect( Object.isFrozen( buff.x.f ) ).to.equal( functionData.innerFunctionsAndClassesWillBeFrozen );
                        expect( Object.isFrozen( buff.x.f.prototype ) ).to.equal( functionData.innerObjectsWillBeFrozen );
                    });
                });
            });
        });

        describe( 'other', function() {

            it( 'subzero is mega frozen itself', function() {

                expect( subzero ).to.be.frozen;
                expect( subzero.freeze ).to.be.frozen;
                expect( subzero.megaFreeze ).to.be.frozen;
                /*
                    NOTE: certain functions don't have prototypes <<e.g f in: const o = { f() {} } >>
                    subzero's functions don't have prototypes
                */
            });

            it( 'README.md megaFreeze example test', function() {

                /*
                	this example uses a function,
                    subzero.megaFreeze also works with objects and classes
                */
                function f() {}

                const InnerClass = class {};

                InnerClass.x = {

                    y: {}
                };

                const innerFunction = function() {};

                innerFunction.x = {

                    y: {}
                };

                const objectInsideAlreadyFrozenObject = {};

                const functionInsideAlreadyFrozenObject = function() {};

                const objectInsideAlreadyFrozenFunction = {};

                const functionInsideAlreadyFrozenFunction = function() {};

                const functionToFreeze = function() {};

                functionToFreeze.objectInsideAlreadyFrozenFunction = objectInsideAlreadyFrozenFunction;

                functionToFreeze.functionInsideAlreadyFrozenFunction = functionInsideAlreadyFrozenFunction;

                const frozenFunctionWithNonFrozenObjectAndFunctionInside = Object.freeze( functionToFreeze );

                const buff = new Buffer( 69 );

                buff.x = {

                    y: {},

                    f: function() {}
                };

                f.a = {

                    b: {

                        c: {

                            d: {

                                InnerClass,

                                innerFunction,

                                buff,

                                e: Object.freeze({

                                    objectInsideAlreadyFrozenObject,

                                    functionInsideAlreadyFrozenObject
                                }),

                                frozenFunctionWithNonFrozenObjectAndFunctionInside
                            }
                        }
                    }
                };

                f.prototype.x = {

                    y: {

                        z: {}
                    },

                    w: {}
                };

                /*
                    It's time to freeze your opponent for the flawless victory with fatality.

                	None of the following assertions will throw an AssertionError:
                */

                console.assert( !Object.isFrozen( f ) );
                console.assert( !Object.isFrozen( f.prototype ) );
                console.assert( !Object.isFrozen( f.a ) );
                console.assert( !Object.isFrozen( f.a.b ) );
                console.assert( !Object.isFrozen( f.a.b.c ) );
                console.assert( !Object.isFrozen( f.a.b.c.d ) );
                console.assert( !Object.isFrozen( f.prototype.x ) );
                console.assert( !Object.isFrozen( f.prototype.x.y ) );
                console.assert( !Object.isFrozen( f.prototype.x.y.z ) );
                console.assert( !Object.isFrozen( f.prototype.x.w ) );
                console.assert( !Object.isFrozen( InnerClass ) );
                console.assert( !Object.isFrozen( InnerClass.prototype ) );
                console.assert( !Object.isFrozen( InnerClass.x ) );
                console.assert( !Object.isFrozen( InnerClass.x.y ) );
                console.assert( !Object.isFrozen( innerFunction ) );
                console.assert( !Object.isFrozen( innerFunction.prototype ) );
                console.assert( !Object.isFrozen( innerFunction.x ) );
                console.assert( !Object.isFrozen( innerFunction.x.y ) );
                console.assert( !Object.isFrozen( objectInsideAlreadyFrozenObject ) );
                console.assert( !Object.isFrozen( objectInsideAlreadyFrozenFunction ) );
                console.assert( !Object.isFrozen( functionInsideAlreadyFrozenObject ) );
                console.assert( !Object.isFrozen( functionInsideAlreadyFrozenObject.prototype ) );
                console.assert( !Object.isFrozen( functionInsideAlreadyFrozenFunction ) );
                console.assert( !Object.isFrozen( functionInsideAlreadyFrozenFunction.prototype ) );
                console.assert( !Object.isSealed( buff ) ); // you cannot freeze buffers
                console.assert( !Object.isFrozen( buff.x ) );
                console.assert( !Object.isFrozen( buff.x.y ) );
                console.assert( !Object.isFrozen( buff.x.f ) );
                console.assert( !Object.isFrozen( buff.x.f.prototype ) );

                // Mega Freeze f
                const reference = subzero.megaFreeze( f );

                console.assert( ( reference === f ) );

                console.assert( Object.isFrozen( f ) );
                console.assert( Object.isFrozen( f.prototype ) );
                console.assert( Object.isFrozen( f.a ) );
                console.assert( Object.isFrozen( f.a.b ) );
                console.assert( Object.isFrozen( f.a.b.c ) );
                console.assert( Object.isFrozen( f.a.b.c.d ) );
                console.assert( Object.isFrozen( f.prototype.x ) );
                console.assert( Object.isFrozen( f.prototype.x.y ) );
                console.assert( Object.isFrozen( f.prototype.x.y.z ) );
                console.assert( Object.isFrozen( f.prototype.x.w ) );
                console.assert( Object.isFrozen( InnerClass ) );
                console.assert( Object.isFrozen( InnerClass.prototype ) );
                console.assert( Object.isFrozen( InnerClass.x ) );
                console.assert( Object.isFrozen( InnerClass.x.y ) );
                console.assert( Object.isFrozen( innerFunction ) );
                console.assert( Object.isFrozen( innerFunction.prototype ) );
                console.assert( Object.isFrozen( innerFunction.x ) );
                console.assert( Object.isFrozen( innerFunction.x.y ) );
                console.assert( Object.isFrozen( objectInsideAlreadyFrozenObject ) );
                console.assert( Object.isFrozen( objectInsideAlreadyFrozenFunction ) );
                console.assert( Object.isFrozen( functionInsideAlreadyFrozenObject ) );
                console.assert( Object.isFrozen( functionInsideAlreadyFrozenObject.prototype ) );
                console.assert( Object.isFrozen( functionInsideAlreadyFrozenFunction ) );
                console.assert( Object.isFrozen( functionInsideAlreadyFrozenFunction.prototype ) );
                const nodeVersion = Number( process.versions.node.split( '.' )[0] );
                if( nodeVersion >= 6 ) console.assert( Object.isSealed( buff ) );
                console.assert( Object.isFrozen( buff.x ) );
                console.assert( Object.isFrozen( buff.x.y ) );
                console.assert( Object.isFrozen( buff.x.f ) );
                console.assert( Object.isFrozen( buff.x.f.prototype ) );
            });
        });
    });

    after( function() {

        console.log(`

            Post-Test Messages:
        `);

        (function displayMessageAboutCoverage() {

            if( nodeVersion >= 6) {

                console.log(`

                the following coverage results means the code is fully covered for

                node v6 or greater

                current version: ${ nodeVersion }

                ----
                Statements   : 100% ( 36/36 )
                Branches     : 94.44% ( 17/18 )
                Functions    : 100% ( 2/2 )
                Lines        : 100% ( 36/36 )
                ----
                `);
            }
            else {

                console.log(`

                the following coverage results means the code is fully covered for

                less than node v6

                current version: ${ nodeVersion }

                ----
                Statements   : 97.22% ( 35/36 )
                Branches     : 94.44% ( 17/18 )
                Functions    : 100% ( 2/2 )
                Lines        : 97.22% ( 35/36 )
                ----
                `);
            }
        })();
    });
});
<|endoftext|>


<commit_before>'use strict';

const chai = require('chai');
const expect = chai.expect;

const Matrix = require('../index');

describe('Initialization a new instance with', () => {
    it('matrix "" throws exception', () => {
        expect(() => {
            const m = new Matrix();
        }).to.throw(/is not correct matrix/i);
    });

    it('matrix "someString" throws exception', () => {
        expect(() => {
            const m = new Matrix('someString');
        }).to.throw(/is not correct matrix/i);
    });

    it('matrix "[1, 2, 3]" throws exception', () => {
        expect(() => {
            const m = new Matrix([1, 2, 3]);
        }).to.throw(/is not correct matrix/i);
    });

    it('matrix "[[1, 2], [3]]" throws exception', () => {
        expect(() => {
            const m = new Matrix([1, 2, 3]);
        }).to.throw(/is not correct matrix/i);
    });

    it('matrix "[[1, 2], [3, 4]]" not throws exception', () => {
        expect(() => {
            const m = new Matrix([
                [1, 2],
                [3, 4]
            ]);
        }).to.not.throw();
    });
});

describe('Get matrix items:', () => {
    // Single row by index
    describe('getRow(number)', () => {
        const m = new Matrix([
            [1, 2],
            [3, 4]
        ]);

        it('getRow(6) returns undefined', () => {
            expect(m.getRow(6)).to.equal(undefined);
        });

        it('getRow(1) returns row with index 1 (zero-based)', () => {
            expect(m.getRow(1)).to.eql([3, 4]);
        });
    });

    // Rows by indices range
    describe('getRows(begin[, end])', () => {
        const m = new Matrix([
            [1, 2],
            [3, 4],
            [5, 6],
            [7, 8]
        ]);

        it('getRows(2) returns rows beginning from index 2 (zero-based) to the last one', () => {
            expect(m.getRows(2)).to.eql([[5, 6], [7, 8]]);
        });

        it('getRows(-3) returns rows beginning from index=(<rows amount> + begin) to the last one', () => {
            expect(m.getRows(-3)).to.eql([[3, 4], [5, 6], [7, 8]]);
        });

        it('getRows(1, 2) returns rows beginning from index 1 to index 2 (zero-based)', () => {
            expect(m.getRows(1, 2)).to.eql([[3, 4], [5, 6]]);
        });

        it('getRows(1, -2) returns rows beginning from index 1 (zero-based) to index=(<rows amount> + end)', () => {
            expect(m.getRows(1, -2)).to.eql([[3, 4], [5, 6]]);
        });
    });

    // Single column by index
    describe('getColumn(number)', () => {
        const m = new Matrix([
            [1, 2],
            [3, 4]
        ]);

        it('getColumn(6) returns undefined', () => {
            expect(m.getColumn(6)).to.equal(undefined);
        });

        it('getColumn(1) returns column with index 1 (zero-based)', () => {
            expect(m.getColumn(1)).to.eql([2, 4]);
        });
    });

    // Columns by indices range
    describe('getColumns(begin[, end])', () => {
        const m = new Matrix([
            [1, 2, 3, 4],
            [5, 6, 7, 8]
        ]);

        it('getColumns(2) returns columns beginning from index 2 (zero-based) to the last one', () => {
            expect(m.getColumns(2)).to.eql([[3, 7], [4, 8]]);
        });

        it('getColumns(-3) returns columns beginning from index=(<columns amount> + begin) to the last one', () => {
            expect(m.getColumns(-3)).to.eql([[2, 6], [3, 7], [4, 8]]);
        });

        it('getColumns(1, 2) returns columns beginning from index 1 to index 2 (zero-based)', () => {
            expect(m.getColumns(1, 2)).to.eql([[2, 6], [3, 7]]);
        });

        it('getColumns(1, -2) returns columns beginning from index 1 (zero-based) to index=(<columns amount> + end)', () => {
            expect(m.getColumns(1, -2)).to.eql([[2, 6], [3, 7]]);
        });
    });

    // Single major diagonal by index
    describe('getDiagonalMaj(number)', () => {
        const m = new Matrix([
            [1,  2,  3,  4],
            [5,  6,  7,  8],
            [9, 10, 11, 12]
        ]);

        it('getDiagonalMaj(6) returns undefined', () => {
            expect(m.getDiagonalMaj(6)).to.equal(undefined);
        });

        it('getDiagonalMaj(2) returns major diagonal with index 2 (zero-based)', () => {
            expect(m.getDiagonalMaj(2)).to.eql([2, 7, 12]);
        });

        it('getDiagonalMaj(4) returns major diagonal with index 4 (zero-based)', () => {
            expect(m.getDiagonalMaj(4)).to.eql([5, 10]);
        });
    });

    // Major diagonals by indices range
    describe('getDiagonalsMaj(begin[, end])', () => {
        const m = new Matrix([
            [1, 2],
            [3, 4],
            [5, 6],
            [7, 8]
        ]);

        it('getDiagonalsMaj(2) returns major diagonals beginning from index 2 (zero-based) to the last one', () => {
            expect(m.getDiagonalsMaj(2)).to.eql([[3, 6], [5, 8], [7]]);
        });

        it('getDiagonalsMaj(-3) returns major diagonals beginning from index=(<diagonals amount> + begin) to the last one', () => {
            expect(m.getDiagonalsMaj(-3)).to.eql([[3, 6], [5, 8], [7]]);
        });

        it('getDiagonalsMaj(1, 2) returns major diagonals beginning from index 1 to index 2 (zero-based)', () => {
            expect(m.getDiagonalsMaj(1, 2)).to.eql([[1, 4], [3, 6]]);
        });

        it('getDiagonalsMaj(1, -2) returns major diagonals beginning from index 1 (zero-based) to index=(<diagonals amount> + end)', () => {
            expect(m.getDiagonalsMaj(1, -2)).to.eql([[1, 4], [3, 6], [5, 8]]);
        });
    });

    // Single minor diagonal by index
    describe('getDiagonalMin(number)', () => {
        const m = new Matrix([
            [1, 2],
            [3, 4],
            [5, 6]
        ]);

        it('getDiagonalMin(6) returns undefined', () => {
            expect(m.getDiagonalMin(6)).to.equal(undefined);
        });

        it('getDiagonalMin(1) returns minor diagonal with index 1 (zero-based)', () => {
            expect(m.getDiagonalMin(1)).to.eql([3, 6]);
        });
    });

    // Minor diagonals by indices range
    describe('getDiagonalsMin(begin[, end])', () => {
        const m = new Matrix([
            [1, 2],
            [3, 4],
            [5, 6],
            [7, 8]
        ]);

        it('getDiagonalsMin(2) returns minor diagonals beginning from index 2 (zero-based) to the last one', () => {
            expect(m.getDiagonalsMin(2)).to.eql([[4, 5], [6, 7], [8]]);
        });

        it('getDiagonalsMin(-3) returns minor diagonals beginning from index=(<diagonals amount> + begin) to the last one', () => {
            expect(m.getDiagonalsMin(-3)).to.eql([[4, 5], [6, 7], [8]]);
        });

        it('getDiagonalsMin(1, 2) returns minor diagonals beginning from index 1 to index 2 (zero-based)', () => {
            expect(m.getDiagonalsMin(1, 2)).to.eql([[2, 3], [4, 5]]);
        });

        it('getDiagonalsMin(1, -2) returns minor diagonals beginning from index 1 (zero-based) to index=(<diagonals amount> + end)', () => {
            expect(m.getDiagonalsMin(1, -2)).to.eql([[2, 3], [4, 5], [6, 7]]);
        });
    });
});
<commit_msg>tests were updated<commit_after>'use strict';

const chai = require('chai');
const expect = chai.expect;

const Matrix = require('../index');

describe('Initialization a new instance with', () => {
    it('matrix "" throws exception', () => {
        expect(() => {
            const m = new Matrix();
        }).to.throw(/is not correct matrix/i);
    });

    it('matrix "someString" throws exception', () => {
        expect(() => {
            const m = new Matrix('someString');
        }).to.throw(/is not correct matrix/i);
    });

    it('matrix "[1, 2, 3]" throws exception', () => {
        expect(() => {
            const m = new Matrix([1, 2, 3]);
        }).to.throw(/is not correct matrix/i);
    });

    it('matrix "[[1, 2], [3]]" throws exception', () => {
        expect(() => {
            const m = new Matrix([1, 2, 3]);
        }).to.throw(/is not correct matrix/i);
    });

    it('matrix "[[1, 2], [3, 4]]" not throws exception', () => {
        expect(() => {
            const m = new Matrix([
                [1, 2],
                [3, 4]
            ]);
        }).to.not.throw();
    });
});

describe('Get matrix items:', () => {
    // Single row by index
    describe('getRow(number)', () => {
        const m = new Matrix([
            [1, 2],
            [3, 4]
        ]);

        it('getRow(6) returns undefined', () => {
            expect(m.getRow(6)).to.equal(undefined);
        });

        it('getRow(1) returns row with zero-based index 1', () => {
            expect(m.getRow(1)).to.eql([3, 4]);
        });
    });

    // Rows by indices range
    describe('getRows(begin[, end])', () => {
        const m = new Matrix([
            [1, 2],
            [3, 4],
            [5, 6],
            [7, 8]
        ]);

        it('getRows(2) returns rows beginning from zero-based index 2 to the last one', () => {
            expect(m.getRows(2)).to.eql([[5, 6], [7, 8]]);
        });

        it('getRows(-3) returns rows beginning from zero-based index=(<rows amount> + begin) to the last one', () => {
            expect(m.getRows(-3)).to.eql([[3, 4], [5, 6], [7, 8]]);
        });

        it('getRows(1, 3) returns rows beginning from zero-based index 1 to index 2', () => {
            expect(m.getRows(1, 3)).to.eql([[3, 4], [5, 6]]);
        });

        it('getRows(1, -1) returns rows beginning from zero-based index 1 to index=(<rows amount> + end)', () => {
            expect(m.getRows(1, -1)).to.eql([[3, 4], [5, 6]]);
        });
    });

    // Single column by index
    describe('getColumn(number)', () => {
        const m = new Matrix([
            [1, 2],
            [3, 4]
        ]);

        it('getColumn(6) returns undefined', () => {
            expect(m.getColumn(6)).to.equal(undefined);
        });

        it('getColumn(1) returns column with zero-based index 1', () => {
            expect(m.getColumn(1)).to.eql([2, 4]);
        });
    });

    // Columns by indices range
    describe('getColumns(begin[, end])', () => {
        const m = new Matrix([
            [1, 2, 3, 4],
            [5, 6, 7, 8]
        ]);

        it('getColumns(2) returns columns beginning from zero-based index 2 to the last one', () => {
            expect(m.getColumns(2)).to.eql([[3, 7], [4, 8]]);
        });

        it('getColumns(-3) returns columns beginning from zero-based index=(<columns amount> + begin) to the last one', () => {
            expect(m.getColumns(-3)).to.eql([[2, 6], [3, 7], [4, 8]]);
        });

        it('getColumns(1, 3) returns columns beginning from zero-based index 1 to index 3', () => {
            expect(m.getColumns(1, 3)).to.eql([[2, 6], [3, 7]]);
        });

        it('getColumns(1, -1) returns columns beginning from zero-based index 1 to index=(<columns amount> + end)', () => {
            expect(m.getColumns(1, -1)).to.eql([[2, 6], [3, 7]]);
        });
    });

    // Single major diagonal by index
    describe('getDiagonalMaj(number)', () => {
        const m = new Matrix([
            [1,  2,  3,  4],
            [5,  6,  7,  8],
            [9, 10, 11, 12]
        ]);

        it('getDiagonalMaj(6) returns undefined', () => {
            expect(m.getDiagonalMaj(6)).to.equal(undefined);
        });

        it('getDiagonalMaj(2) returns major diagonal with zero-based index 2', () => {
            expect(m.getDiagonalMaj(2)).to.eql([2, 7, 12]);
        });

        it('getDiagonalMaj(4) returns major diagonal with zero-based index 4', () => {
            expect(m.getDiagonalMaj(4)).to.eql([5, 10]);
        });
    });

    // Major diagonals by indices range
    describe('getDiagonalsMaj(begin[, end])', () => {
        const m = new Matrix([
            [1, 2],
            [3, 4],
            [5, 6],
            [7, 8]
        ]);

        it('getDiagonalsMaj(2) returns major diagonals beginning from zero-based index 2 to the last one', () => {
            expect(m.getDiagonalsMaj(2)).to.eql([[3, 6], [5, 8], [7]]);
        });

        it('getDiagonalsMaj(-3) returns major diagonals beginning from zero-based index=(<diagonals amount> + begin) to the last one', () => {
            expect(m.getDiagonalsMaj(-3)).to.eql([[3, 6], [5, 8], [7]]);
        });

        it('getDiagonalsMaj(1, 3) returns major diagonals beginning from zero-based index 1 to index 2', () => {
            expect(m.getDiagonalsMaj(1, 3)).to.eql([[1, 4], [3, 6]]);
        });

        it('getDiagonalsMaj(1, -1) returns major diagonals beginning from zero-based index 1 to index=(<diagonals amount> + end)', () => {
            expect(m.getDiagonalsMaj(1, -1)).to.eql([[1, 4], [3, 6], [5, 8]]);
        });
    });

    // Single minor diagonal by index
    describe('getDiagonalMin(number)', () => {
        const m = new Matrix([
            [1, 2],
            [3, 4],
            [5, 6]
        ]);

        it('getDiagonalMin(6) returns undefined', () => {
            expect(m.getDiagonalMin(6)).to.equal(undefined);
        });

        it('getDiagonalMin(1) returns minor diagonal with zero-based index 1', () => {
            expect(m.getDiagonalMin(1)).to.eql([3, 6]);
        });
    });

    // Minor diagonals by indices range
    describe('getDiagonalsMin(begin[, end])', () => {
        const m = new Matrix([
            [1, 2],
            [3, 4],
            [5, 6],
            [7, 8]
        ]);

        it('getDiagonalsMin(2) returns minor diagonals beginning from zero-based index 2 to the last one', () => {
            expect(m.getDiagonalsMin(2)).to.eql([[4, 5], [6, 7], [8]]);
        });

        it('getDiagonalsMin(-3) returns minor diagonals beginning from zero-based index=(<diagonals amount> + begin) to the last one', () => {
            expect(m.getDiagonalsMin(-3)).to.eql([[4, 5], [6, 7], [8]]);
        });

        it('getDiagonalsMin(1, 2) returns minor diagonals beginning from zero-based index 1 to index 2 (zero-based)', () => {
            expect(m.getDiagonalsMin(1, 2)).to.eql([[2, 3], [4, 5]]);
        });

        it('getDiagonalsMin(1, -2) returns minor diagonals beginning from zero-based index 1 to index=(<diagonals amount> + end)', () => {
            expect(m.getDiagonalsMin(1, -2)).to.eql([[2, 3], [4, 5], [6, 7]]);
        });
    });
});
<|endoftext|>


<commit_before>var expect = require('expect.js')
  , mockery = require('mockery')
  , path = require('path')
  , pmock = require('pmock')
  , Config = require('../src/config')
  , BaseBackend = require('../src/backends/base.js')
  , FeedManager = require('../src/FeedManager')
  , main = require('../src/index');

describe('StreamBackend', function () {

    it('should have right properties', function () {
        new BaseBackend().should.have.property('collectReferences');
        new BaseBackend().should.have.property('enrichActivities');
        new BaseBackend().should.have.property('enrichAggregatedActivities');
    });

    it('#collectReferences()', function () {
    });

    it('#retreiveObjects()', function () {
    });

    it('#enrichActivities()', function () {
    });

    it('#enrichAggregatedActivities()', function () {
    });

});

describe('feedManagerFactory', function() {

    it('should return a FeedManager instance', function() {
        var fm = main.feedManagerFactory({});

        expect(fm).to.be.a(FeedManager);
    });

    it('should ignore unkown settings', function() {
        var fm = main.feedManagerFactory({
            unknown: 'abcdefg'
        });

        expect(fm).to.be.a(FeedManager);
        expect(fm.settings.unknown).to.be.undefined;
    });

    it('should override known settings', function() {
        var fm = main.feedManagerFactory({
            apiKey: 'abcdefg'
        });

        expect(fm).to.be.a(FeedManager);
        expect(fm.settings.apiKey).to.be('abcdefg');
    });

});

describe('Config', function() {

    it('default config', function() {
        var settings = main.FeedManager.settings;

        var expected = require('../getstream.js').config;
        expect(settings).to.eql(expected);
    });

});

describe('Config Env Var', function() {
    var configDir = path.join(__dirname, './tmp');
    var configFile = path.join(configDir, 'getstream.js');

    before(function() {
        this.env = pmock.env({
            STREAM_NODE_CONFIG_DIR: configDir,
        });

        mockery.enable({
            warnOnUnregistered: false,
            useCleanCache: true,
        });
        mockery.registerMock('fs', { existsSync: function() {
            return true;
        }});
        mockery.registerMock(configFile, { config: { apiKey: 12345 } });
    });

    after(function() {
        mockery.disable();
        this.env.reset();
    });

    /**
     * Mockery doesn't work correctly here
     * SKip this test until we fix that
     */
    it.skip('env var config dir', function() {
        var settings = Config();

        expect(settings.apiKey).to.be(12345);
    });

});

describe('Config Default', function() {

    before(function() {
        this.cwd = pmock.cwd('/tmp');
    });

    after(function() {
        this.cwd.reset();
    });

    it('env var config dir', function() {
        var settings = Config();

        var expected = require('../src/config.default.js').config;

        expect(settings).to.eql(expected);
    });

});<commit_msg>Skip all together<commit_after>var expect = require('expect.js')
  , mockery = require('mockery')
  , path = require('path')
  , pmock = require('pmock')
  , Config = require('../src/config')
  , BaseBackend = require('../src/backends/base.js')
  , FeedManager = require('../src/FeedManager')
  , main = require('../src/index');

describe('StreamBackend', function () {

    it('should have right properties', function () {
        new BaseBackend().should.have.property('collectReferences');
        new BaseBackend().should.have.property('enrichActivities');
        new BaseBackend().should.have.property('enrichAggregatedActivities');
    });

    it('#collectReferences()', function () {
    });

    it('#retreiveObjects()', function () {
    });

    it('#enrichActivities()', function () {
    });

    it('#enrichAggregatedActivities()', function () {
    });

});

describe('feedManagerFactory', function() {

    it('should return a FeedManager instance', function() {
        var fm = main.feedManagerFactory({});

        expect(fm).to.be.a(FeedManager);
    });

    it('should ignore unkown settings', function() {
        var fm = main.feedManagerFactory({
            unknown: 'abcdefg'
        });

        expect(fm).to.be.a(FeedManager);
        expect(fm.settings.unknown).to.be.undefined;
    });

    it('should override known settings', function() {
        var fm = main.feedManagerFactory({
            apiKey: 'abcdefg'
        });

        expect(fm).to.be.a(FeedManager);
        expect(fm.settings.apiKey).to.be('abcdefg');
    });

});

describe('Config', function() {

    it('default config', function() {
        var settings = main.FeedManager.settings;

        var expected = require('../getstream.js').config;
        expect(settings).to.eql(expected);
    });

});

describe.skip('Config Env Var', function() {
    var configDir = path.join(__dirname, './tmp');
    var configFile = path.join(configDir, 'getstream.js');

    before(function() {
        this.env = pmock.env({
            STREAM_NODE_CONFIG_DIR: configDir,
        });

        mockery.enable({
            warnOnUnregistered: false,
            useCleanCache: true,
        });
        mockery.registerMock('fs', { existsSync: function() {
            return true;
        }});
        mockery.registerMock(configFile, { config: { apiKey: 12345 } });
    });

    after(function() {
        mockery.disable();
        this.env.reset();
    });

    /**
     * Mockery doesn't work correctly here
     * SKip this test until we fix that
     */
    it.skip('env var config dir', function() {
        var settings = Config();

        expect(settings.apiKey).to.be(12345);
    });

});

describe('Config Default', function() {

    before(function() {
        this.cwd = pmock.cwd('/tmp');
    });

    after(function() {
        this.cwd.reset();
    });

    it('env var config dir', function() {
        var settings = Config();

        var expected = require('../src/config.default.js').config;

        expect(settings).to.eql(expected);
    });

});<|endoftext|>


<commit_before>var chooseRandomTarget = function() {};

// Sets up the Sephiroth Object
sephiroth = new Object();
sephiroth.level = 87;
sephiroth.health = 400000;
sephiroth.magicPoints = 680;
sephiroth.attack = 246;
sephiroth.defense = 260;
sephiroth.magicAttack = 140;
sephiroth.magicDefense = 308;
sephiroth.dexterity = 160;
sephiroth.evade = 1;
sephiroth.experienceGrantableOnWin = 0;
sephiroth.abilityPointsGrantableOnWin = 0;
sephiroth.gilGrantableOnWin = 0;
sephiroth.fireAffinity = nil;
sephiroth.iceAffinity = nil;
sephiroth.lightningAffinity = nil;
sephiroth.waterAffinity = nil;
sephiroth.earthAffinity = "Immune";
sephiroth.windAffinity = nil;
sephiroth.gravityAffinity = "Immune";
sephiroth.poisonAffinity = nil;
sephiroth.holyAffinity = nil;
sephiroth.statusImmunities = ["Death","Sleep","Poison","Sadness","Fury","Confuse","Silence","Frog","Small","SlowNumber","Petrify","DeathSentence","Manipulate","Berserk","Paralyze","Slow","Stop","Darkness"];
sephiroth.slow = false;
sephiroth.attack = new Object();
sephiroth.attack.attack = function(target);
sephiroth.attack.paleHorse = function(target);
sephiroth.attack.deen = function(target);
sephiroth.attack.supernova = function(target);
sephiroth.attack.wall = function(target);
sephiroth.attack.shadowFlare = function(target);
sephiroth.attack.deSpell = function(target);
sephiroth.attack.heartlessAngel = function(target);
sephiroth.attack.breakAbility = function(target);
sephiroth.attack.flyUp = function(target);
sephiroth.attack.flyDown = function(target);
sephiroth.stageCount = 0;
sephiroth.moveSet = 0;

sephiroth.main = function() {
	sepiroth.magicPoints = 680;
	sephiroth.stageCount = sephiroth.stageCount + 1;
	if (sephiroth.stageCount == 1)  {
		if (sepiroth.slow == true) {
			sephiroth.attack.deSpell(self);
		}
		else if (sephiroth.moveSet == 1)  {
			sephiroth.attack.deSpell(party);
			sephiroth.moveSet = 0;
		}
		else {
			sephiroth.attack.wall(self);
			sephiroth.moveSet = 1
		}
	}

	else if (sephiroth.stageCount == 2) {
		if (sephiroth.moveSet == 0) {
			sephiroth.attack.deen(party);
		}
		else {
			chooseRandomTarget();
			sephiroth.attack.shadowFlare(randomTarget);
		}
	}

	else if (sephiroth.stageCount == 3) {
		var partyMemberWithHighestHealth = 0;
		for (partyMember[i] = 0; partyMember[i] < party.length; partyMember[i]++) {
			if (partyMember[i].health > partyMember[partyMemberWithHighestHealth].health) {
				partyMemberWithHighestHealth = partyMember[i];
			}
			else {
				partyMemberWithHighestHealth = partyMemberWithHighestHealth;
			}
		}
		sephiroth.attack.attack(party[partyMemberWithHighestHealth]);
	}

	else if (sephiroth.stageCount == 4) {
		sephiroth.attack.flyUp(self);
		sephiroth.stageCount = 1
		sephiroth.inPhysicalAttackRange = false;
	}

	else if (sephiroth.stageCount == 5) {
		chooseRandomTarget();
		sephiroth.attack.paleHorse(randomTarget);
	}

	else if (sephiroth.stageCount == 6) {
		sephiroth.attack.supernova(party);
	}

	else if (sephiroth.stageCount == 7) {
		if (sephiroth.health > (sephiroth.health / 4)) {
			chooseRandomTarget();
			sephiroth.attack.breakAbility(randomTarget);
		}
		else {
			chooseRandomTarget();
			sephiroth.attack.heartlessAngel(randomTarget);
		}
	}

	else {
	sephiroth.attack.flyDown(self);
	sephiroth.inPhysicalAttackRange = true;
	sephirotstageCount = 0
	}
}<commit_msg>Added Party<commit_after>// Player/Enemy Functions
var chooseRandomTarget = function() {};

// Sets up the party array
var party = [""];

// Sets up the player objects
player = new Object();
player.level = 75;
player.health = 20000;
player.magicPoints = 400;
player.attack = 123;
player.defense = 130;
player.magicAttack = 70;
player.magicDefense = 154;
player.dexterity = 80;
player.evade = 1;
player.fireAffinity = nil;
player.iceAffinity = nil;
player.lightningAffinity = nil;
player.waterAffinity = nil;
player.earthAffinity = nil;
player.windAffinity = nil;
player.gravityAffinity = nil;
player.poisonAffinity = nil;
player.holyAffinity = nil;
player.statusImmunities = [""];
player.attack = new Object();
player.attack.limitBreak = function(target);
player.attack.attack = function(target);
player.attack.supernova = function(target);

// Instantiates the party
var cloud = new player();
var tifa = new player();
var barret = new player();

// Main function for players
cloud.main = function() {
}
tifa.main = function() {
}
barret.main = function(){
}

// Sets up the Sephiroth Object
sephiroth = new Object();
sephiroth.level = 87;
sephiroth.health = 400000;
sephiroth.magicPoints = 680;
sephiroth.attack = 246;
sephiroth.defense = 260;
sephiroth.magicAttack = 140;
sephiroth.magicDefense = 308;
sephiroth.dexterity = 160;
sephiroth.evade = 1;
sephiroth.experienceGrantableOnWin = 0;
sephiroth.abilityPointsGrantableOnWin = 0;
sephiroth.gilGrantableOnWin = 0;
sephiroth.fireAffinity = nil;
sephiroth.iceAffinity = nil;
sephiroth.lightningAffinity = nil;
sephiroth.waterAffinity = nil;
sephiroth.earthAffinity = "Immune";
sephiroth.windAffinity = nil;
sephiroth.gravityAffinity = "Immune";
sephiroth.poisonAffinity = nil;
sephiroth.holyAffinity = nil;
sephiroth.statusImmunities = ["Death","Sleep","Poison","Sadness","Fury","Confuse","Silence","Frog","Small","SlowNumber","Petrify","DeathSentence","Manipulate","Berserk","Paralyze","Slow","Stop","Darkness"];
sephiroth.slow = false;
sephiroth.attack = new Object();
sephiroth.attack.attack = function(target);
sephiroth.attack.paleHorse = function(target);
sephiroth.attack.deen = function(target);
sephiroth.attack.supernova = function(target);
sephiroth.attack.wall = function(target);
sephiroth.attack.shadowFlare = function(target);
sephiroth.attack.deSpell = function(target);
sephiroth.attack.heartlessAngel = function(target);
sephiroth.attack.breakAbility = function(target);
sephiroth.attack.flyUp = function(target);
sephiroth.attack.flyDown = function(target);
sephiroth.stageCount = 0;
sephiroth.moveSet = 0;

// Sephiroths AI Routine
sephiroth.main = function() {
	sepiroth.magicPoints = 680;
	sephiroth.stageCount = sephiroth.stageCount + 1;
	if (sephiroth.stageCount == 1)  {
		if (sepiroth.slow == true) {
			sephiroth.attack.deSpell(self);
		}
		else if (sephiroth.moveSet == 1)  {
			sephiroth.attack.deSpell(party);
			sephiroth.moveSet = 0;
		}
		else {
			sephiroth.attack.wall(self);
			sephiroth.moveSet = 1
		}
	}

	else if (sephiroth.stageCount == 2) {
		if (sephiroth.moveSet == 0) {
			sephiroth.attack.deen(party);
		}
		else {
			chooseRandomTarget();
			sephiroth.attack.shadowFlare(randomTarget);
		}
	}

	else if (sephiroth.stageCount == 3) {
		var partyMemberWithHighestHealth = 0;
		for (party[i] = 0; party[i] < party.length; party[i]++) {
			if (party[i].health > party[partyMemberWithHighestHealth].health) {
				partyMemberWithHighestHealth = party[i];
			}
			else {
				partyMemberWithHighestHealth = partyMemberWithHighestHealth;
			}
		}
		sephiroth.attack.attack(party[partyMemberWithHighestHealth]);
	}

	else if (sephiroth.stageCount == 4) {
		sephiroth.attack.flyUp(self);
		sephiroth.stageCount = 1
		sephiroth.inPhysicalAttackRange = false;
	}

	else if (sephiroth.stageCount == 5) {
		chooseRandomTarget();
		sephiroth.attack.paleHorse(randomTarget);
	}

	else if (sephiroth.stageCount == 6) {
		sephiroth.attack.supernova(party);
	}

	else if (sephiroth.stageCount == 7) {
		if (sephiroth.health > (sephiroth.health / 4)) {
			chooseRandomTarget();
			sephiroth.attack.breakAbility(randomTarget);
		}
		else {
			chooseRandomTarget();
			sephiroth.attack.heartlessAngel(randomTarget);
		}
	}

	else {
	sephiroth.attack.flyDown(self);
	sephiroth.inPhysicalAttackRange = true;
	sephirotstageCount = 0
	}
}

// Turn Processing
var currentTurn = 0;
var firstTurn = sephiroth.main();
var secondTurn = cloud.main();
var thirdTurn = tifa.main();
var fourthTurn = barret.main();

var processTurn = function() {
	for (currentTurn < 4; currentTurn = 0; currentTurn++) {
		if (currentTurn = 0) {
			sephiroth.main();
		}
		else if (currentTurn = 1){
			cloud.main();
		}
		else if (currentTurn = 2){
			tifa.main();
		}
		else if (currentTurn = 3){
			currentTurn = -1;
			barret.main();
		}
	}
}

processTurn();<|endoftext|>


<commit_before>/*
 * ngAuthToken
 * (c) 2014 kukulili labs - Sebastian Mueller <smueller@kukulili-labs.com>
 * License: MIT
 */

// Karma configuration
// http://karma-runner.github.io/0.10/config/configuration-file.html

module.exports = function(config) {
  'use strict';

  var bower = 'test/lib/bower_components/';

  config.set({

    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,

    // base path, that will be used to resolve files and exclude
    basePath: '../',

    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['PhantomJS'],

    // list of files / patterns to load in the browser
    files: [
        bower + 'angular/angular.js',
        bower + 'angular-mocks/angular-mocks.js',
      'ngAuthToken.js',
      'test/spec/**/*.js'
    ],

    reporters: ['progress', 'coverage'],

    preprocessors: {
      'ngAuthToken.js': ['coverage']
    },

    coverageReporter: {
      type: 'lcov',
      dir: 'coverage/'
    },

    // testing framework to use (jasmine/mocha/qunit/...)
    frameworks: ['jasmine'],

    // level of logging
    // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
    logLevel: config.LOG_INFO,

    // web server port
    port: 8999,

    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: true
  });
};<commit_msg>Fix karma setup for codeclimate<commit_after>/*
 * ngAuthToken
 * (c) 2014 kukulili labs - Sebastian Mueller <smueller@kukulili-labs.com>
 * License: MIT
 */

// Karma configuration
// http://karma-runner.github.io/0.10/config/configuration-file.html

module.exports = function(config) {
  'use strict';

  var bower = 'test/lib/bower_components/';

  config.set({

    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,

    // base path, that will be used to resolve files and exclude
    basePath: '../',

    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['PhantomJS'],

    // list of files / patterns to load in the browser
    files: [
        bower + 'angular/angular.js',
        bower + 'angular-mocks/angular-mocks.js',
      'ngAuthToken.js',
      'test/spec/**/*.js'
    ],

    reporters: ['progress', 'coverage'],

    preprocessors: {
      'ngAuthToken.js': ['coverage']
    },

    coverageReporter: {
      type: 'lcov',
      dir: 'coverage/',
      subdir: '.'
    },

    // testing framework to use (jasmine/mocha/qunit/...)
    frameworks: ['jasmine'],

    // level of logging
    // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
    logLevel: config.LOG_INFO,

    // web server port
    port: 8999,

    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: true
  });
};<|endoftext|>


<commit_before>var pg = require('pg');
var squel = require('squel');
var moment = require('moment');

function getEvents(apiQuery, callback) {
  pg.connect(process.env.DATABASE_URL, function(err, client, done) {
    if(err) {
      console.error('Error while connecting', err);
      callback(err);
      return;
    }
    var sql = squel.select().from('event');
    if(apiQuery.firstDate) {
      sql = sql.where('start_time >= ?', apiQuery.firstDate.format('YYYY-MM-DD'));
    }
    if(apiQuery.lastDate) {
      sql = sql.where('start_time < ?', apiQuery.lastDate.add(1, 'days').format('YYYY-MM-DD'));
    }
    sql = sql.order('start_time');
    client.query(sql.toString(), sql.toParam(), function(err, result) {
      done();
      if (err) {
        callback(err);
      } else {
        callback(null, result.rows);
      }
    });
  });
}

function insertEvent(event, callback) {
  pg.connect(process.env.DATABASE_URL, function(err, client, done) {
    if(err) {
      console.error('Error while connecting', err);
      callback(err);
      return;
    }
    var sql = squel.insert()
        .into('event')
        .set('start_time', event.start_time.format('YYYY-MM-DD HH:mm'))
        .set('end_time', event.end_time.format('YYYY-MM-DD HH:mm'))
        .set('organizer', event.organizer)
        .set('address', event.address)
        .set('latitude', event.laditude || null)
        .set('longitude', event.longitude || null)
        .set('info', event.info)
        .set('url', event.url);
    console.log('Insert event:', sql.toString());
    client.query(sql.toString(), sql.toParam(), function(err, result) {
      done();
      if(err) {
        console.log('INSERT ERROR', err);
      } else {
        callback(err);
      }
    });
  });
}

var dateSchema = {
  custom: function(obj, schema, fn) {
    if(!obj) {
      fn(null, null);
      return;
    }
    var parsed = moment(obj, 'YYYY-MM-DD');
    if(!parsed.isValid()) {
      return fn(new Error('Invalid date parameter'));
    }
    fn(null, parsed);
  }
};

var timeStampSchema = {
  custom: function(obj, schema, fn) {
    if(!obj) {
      fn(null, null);
      return;
    }
    var parsed = moment(obj, 'YYYY-MM-DD HH:mm');
    if(!parsed.isValid()) {
      return fn(new Error('Invalid date parameter'));
    }
    fn(null, parsed);
  }
};

exports.eventQuerySchema = {
  'firstDate': dateSchema,
  'lastDate': dateSchema
};

exports.insertEventSchema = {
  start_time: timeStampSchema,
  end_time: timeStampSchema,
  organizer: { type: String, required: true },
  address: { type: String, required: true },
  latitude: { type: Number, required: false },
  longitude: { type: Number, required: false },
  info: { type: String, required: true },
  url: { type: String, required: true }
};

exports.getEvents = getEvents;
exports.insertEvent = insertEvent;
<commit_msg>db.js insert event typofix<commit_after>var pg = require('pg');
var squel = require('squel');
var moment = require('moment');

function getEvents(apiQuery, callback) {
  pg.connect(process.env.DATABASE_URL, function(err, client, done) {
    if(err) {
      console.error('Error while connecting', err);
      callback(err);
      return;
    }
    var sql = squel.select().from('event');
    if(apiQuery.firstDate) {
      sql = sql.where('start_time >= ?', apiQuery.firstDate.format('YYYY-MM-DD'));
    }
    if(apiQuery.lastDate) {
      sql = sql.where('start_time < ?', apiQuery.lastDate.add(1, 'days').format('YYYY-MM-DD'));
    }
    sql = sql.order('start_time');
    client.query(sql.toString(), sql.toParam(), function(err, result) {
      done();
      if (err) {
        callback(err);
      } else {
        callback(null, result.rows);
      }
    });
  });
}

function insertEvent(event, callback) {
  pg.connect(process.env.DATABASE_URL, function(err, client, done) {
    if(err) {
      console.error('Error while connecting', err);
      callback(err);
      return;
    }
    var sql = squel.insert()
        .into('event')
        .set('start_time', event.start_time.format('YYYY-MM-DD HH:mm'))
        .set('end_time', event.end_time.format('YYYY-MM-DD HH:mm'))
        .set('organizer', event.organizer)
        .set('address', event.address)
        .set('latitude', event.latitude || null)
        .set('longitude', event.longitude || null)
        .set('info', event.info)
        .set('url', event.url);
    console.log('Insert event:', sql.toString());
    client.query(sql.toString(), sql.toParam(), function(err, result) {
      done();
      if(err) {
        console.log('INSERT ERROR', err);
      } else {
        callback(err);
      }
    });
  });
}

var dateSchema = {
  custom: function(obj, schema, fn) {
    if(!obj) {
      fn(null, null);
      return;
    }
    var parsed = moment(obj, 'YYYY-MM-DD');
    if(!parsed.isValid()) {
      return fn(new Error('Invalid date parameter'));
    }
    fn(null, parsed);
  }
};

var timeStampSchema = {
  custom: function(obj, schema, fn) {
    if(!obj) {
      fn(null, null);
      return;
    }
    var parsed = moment(obj, 'YYYY-MM-DD HH:mm');
    if(!parsed.isValid()) {
      return fn(new Error('Invalid date parameter'));
    }
    fn(null, parsed);
  }
};

exports.eventQuerySchema = {
  'firstDate': dateSchema,
  'lastDate': dateSchema
};

exports.insertEventSchema = {
  start_time: timeStampSchema,
  end_time: timeStampSchema,
  organizer: { type: String, required: true },
  address: { type: String, required: true },
  latitude: { type: Number, required: false },
  longitude: { type: Number, required: false },
  info: { type: String, required: true },
  url: { type: String, required: true }
};

exports.getEvents = getEvents;
exports.insertEvent = insertEvent;
<|endoftext|>