<commit_before>describe('When components and systems are defined', () => {
  const Ecs = require('../../Ecs');
  let ecs;
  let systems = {};
  let moveSystemPreMock;
  let renderSystemPreMock;
  let noopSystemPreMock;
  let moveSystemForEachMock;

  beforeEach(() => {
    ecs = new Ecs();
    moveSystemPreMock = jest.fn();
    renderSystemPreMock = jest.fn();
    noopSystemPreMock = jest.fn();
    moveSystemForEachMock = jest.fn();

    ecs.registerComponent('position', function(x = 0, y = 0) {
      this.x = x;
      this.y = y;
    });

    ecs.registerComponent('velocity', function(x = 0, y = 0) {
      this.x = x;
      this.y = y;
    });

    ecs.registerComponent('sprite', function(src) {
      this.src = src;
    });

    ecs.registerComponent('hidden');

    ecs.registerComponent('stunned');

    systems.render = ecs.registerSystem({
      pre(globalArg) {
        renderSystemPreMock(globalArg);
      },
      has: ['sprite', 'position'],
      not: ['hidden'],
      forEach(entity, globalArg) {

      },
      group: 'misc'
    });

    systems.move = ecs.registerSystem({
      has: ['position', 'velocity'],
      not: ['stunned'],
      pre(globalArg) {
        moveSystemPreMock(globalArg);
      },
      forEach(entity, globalArg) {
        const { position, velocity } = entity;
        position.x += velocity.x;
        position.y += velocity.y;
        moveSystemForEachMock(entity, globalArg);
      },
      group: 'model'
    });

    systems.noop = ecs.registerSystem({
      pre(globalArg) {
        noopSystemPreMock(globalArg);
      },
      forEach(entity, globalArg) {},
      group: 'misc'
    });
  });

  it('all systems should run when ecs.run is called', () => {
    ecs.run();
    expect(moveSystemPreMock.mock.calls.length).toEqual(1);
    expect(noopSystemPreMock.mock.calls.length).toEqual(1);
    expect(renderSystemPreMock.mock.calls.length).toEqual(1);
  });

  it('systems should forward global argument', () => {
    const argument = 'test argument';
    ecs.run(argument);
    expect(moveSystemPreMock.mock.calls[0][0]).toEqual(argument);
    expect(noopSystemPreMock.mock.calls[0][0]).toEqual(argument);
    expect(renderSystemPreMock.mock.calls[0][0]).toEqual(argument);
  });

  describe('and entity is created', () => {
    let entity;

    beforeEach(() => {
      entity = ecs.createEntity();
    });

    it('should have id', () => {
      expect(entity.id).toBeDefined();
    });

    it('should be able to enroll to matching systems', () => {
      ecs.run();
      expect(systems.noop.entities.includes(entity)).toEqual(true);
      expect(systems.move.entities.includes(entity)).toEqual(false);
      expect(systems.render.entities.includes(entity)).toEqual(false);
    });

    describe('and component is added to an entity', () => {
      beforeEach(() => {
        entity.add('position', 5, 5);
      });

      it('should be able to know if the component exists', () => {
        expect(entity.has('position')).toEqual(true);
        expect(entity.has('nonExistentComponent')).toEqual(false);
      });

      it('should store the component data', () => {
        expect(entity.position).toBeDefined();
        expect(entity.position.x).toEqual(5);
        expect(entity.position.y).toEqual(5);<commit_msg>Add test for entity addMultiple method<commit_after>describe('When components and systems are defined', () => {
  const Ecs = require('../../Ecs');
  let ecs;
  let systems = {};
  let moveSystemPreMock;
  let renderSystemPreMock;
  let noopSystemPreMock;
  let moveSystemForEachMock;

  beforeEach(() => {
    ecs = new Ecs();
    moveSystemPreMock = jest.fn();
    renderSystemPreMock = jest.fn();
    noopSystemPreMock = jest.fn();
    moveSystemForEachMock = jest.fn();

    ecs.registerComponent('position', function(x = 0, y = 0) {
      this.x = x;
      this.y = y;
    });

    ecs.registerComponent('velocity', function(x = 0, y = 0) {
      this.x = x;
      this.y = y;
    });

    ecs.registerComponent('sprite', function(src) {
      this.src = src;
    });

    ecs.registerComponent('hidden');

    ecs.registerComponent('stunned');

    systems.render = ecs.registerSystem({
      pre(globalArg) {
        renderSystemPreMock(globalArg);
      },
      has: ['sprite', 'position'],
      not: ['hidden'],
      forEach(entity, globalArg) {

      },
      group: 'misc'
    });

    systems.move = ecs.registerSystem({
      has: ['position', 'velocity'],
      not: ['stunned'],
      pre(globalArg) {
        moveSystemPreMock(globalArg);
      },
      forEach(entity, globalArg) {
        const { position, velocity } = entity;
        position.x += velocity.x;
        position.y += velocity.y;
        moveSystemForEachMock(entity, globalArg);
      },
      group: 'model'
    });

    systems.noop = ecs.registerSystem({
      pre(globalArg) {
        noopSystemPreMock(globalArg);
      },
      forEach(entity, globalArg) {},
      group: 'misc'
    });
  });

  it('all systems should run when ecs.run is called', () => {
    ecs.run();
    expect(moveSystemPreMock.mock.calls.length).toEqual(1);
    expect(noopSystemPreMock.mock.calls.length).toEqual(1);
    expect(renderSystemPreMock.mock.calls.length).toEqual(1);
  });

  it('systems should forward global argument', () => {
    const argument = 'test argument';
    ecs.run(argument);
    expect(moveSystemPreMock.mock.calls[0][0]).toEqual(argument);
    expect(noopSystemPreMock.mock.calls[0][0]).toEqual(argument);
    expect(renderSystemPreMock.mock.calls[0][0]).toEqual(argument);
  });

  describe('and entity is created', () => {
    let entity;

    beforeEach(() => {
      entity = ecs.createEntity();
    });

    it('should have id', () => {
      expect(entity.id).toBeDefined();
    });

    it('should be able to receive multiple components', () => {
      entity.addMultiple(
        ['position', 5, 5],
        ['velocity', 3, 3],
        ['stunned'],
        ['hidden']
      );
      expect(entity.has('position')).toEqual(true);
      expect(entity.has('velocity')).toEqual(true);
      expect(entity.has('stunned')).toEqual(true);
      expect(entity.has('hidden')).toEqual(true);
    });

    it('should be able to enroll to matching systems', () => {
      ecs.run();
      expect(systems.noop.entities.includes(entity)).toEqual(true);
      expect(systems.move.entities.includes(entity)).toEqual(false);
      expect(systems.render.entities.includes(entity)).toEqual(false);
    });

    describe('and component is added to an entity', () => {
      beforeEach(() => {
        entity.add('position', 5, 5);
      });

      it('should be able to know if the component exists', () => {
        expect(entity.has('position')).toEqual(true);
        expect(entity.has('nonExistentComponent')).toEqual(false);
      });

      it('should store the component data', () => {
        expect(entity.position).toBeDefined();
        expect(entity.position.x).toEqual(5);
        expect(entity.position.y).toEqual(5);
{'fraction_non_alphanumeric': 0.16619034009717062, 'fraction_numerical': 0.0054301228922549296, 'mean_word_length': 2.851953769950468, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '879913', 'n_tokens_mistral': 2180, 'n_tokens_neox': 2140, 'n_words': 386}