<commit_before>describe('Game', function() {
  describe('Board', function() {
    beforeEach(module('game.board'));

    describe('Tile', function() {

      var tile;
      beforeEach(inject(function(BoardTile) {
        tile = BoardTile;
      }));

      it('should have a BoardTile', function() {
        expect(tile).toBeDefined();
      });

    });

    describe('Manager', function() {
      var board
          , Tile
          , test_tiles
          ;

      beforeEach(inject(function(BoardManager, BoardTile) {
        board = BoardManager;
        Tile = BoardTile;
        test_tiles = {
            n:  new BoardTile({ exits: [0], }),
            ne: new BoardTile({ exits: [0, 1], }),
            e:  new BoardTile({ exits: [1], }),
            se: new BoardTile({ exits: [1, 2], }),
            s:  new BoardTile({ exits: [2], }),
            sw: new BoardTile({ exits: [2, 3], }),
            w:  new BoardTile({ exits: [3], }),
            ns: new BoardTile({ exits: [0, 2], }),
            ew: new BoardTile({ exits: [1, 3], }),
            "new": new BoardTile({ exits: [0, 2, 3], }),
            nesw: new BoardTile({ exits: [0, 1, 2, 3], }),
        };
      }));

      it('should have a BoardManager', function() {
        expect(board).toBeDefined();
        expect(Tile).toBeDefined();
      });

      describe('.coord', function (){
        it('should convert a point to a string coordinate', function(){
          expect(board.coord([0, 0])).toEqual('0:0');
          expect(board.coord([14, -5])).toEqual('14:-5');
        });
      });

      describe('.point', function (){
        it('should convert a string coordinate to a point', function(){
          expect(board.point('0:0')).toEqual([0, 0]);
          expect(board.point('14:-5')).toEqual([14, -5]);
        });
      });

      describe('.place_tile', function (){
        beforeEach(function (){
          board.initalize();
        });

        it('should place the tile in the board and update surrounding tiles', function(){
          var tile = test_tiles.n;
          board.place_tile([0, 0], tile);

          expect(board.tiles['0:0']).toBe(tile);
          expect(board.tiles['0:-1']).toBe(board.placeholders.indoor);
        });

        it('should place the rotated tile in the board and update surrounding tiles', function(){
          var tile = test_tiles.n;
          tile.rotation = 1;
          board.place_tile([0, 0], tile);

          expect(board.tiles['0:0']).toBe(tile);
          expect(board.tiles['1:0']).toBe(board.placeholders.indoor);
        });

        it('should not overwrite existing tiles with placeholders', function(){
          board.place_tile([0, 0], test_tiles.n);
          expect(board.tiles['0:0']).toBe(test_tiles.n);
          expect(board.tiles['0:-1']).toBe(board.placeholders.indoor);

          board.place_tile([0, -1], test_tiles.s);
          expect(board.tiles['0:-1']).toBe(test_tiles.s);
          expect(board.tiles['0:0']).toBe(test_tiles.n);
        });

      });

      describe('.near', function (){
        it('should return true if two points are next to one another', function(){
          expect(board.near([0, 0], [0, 1])).toBe(true);
          expect(board.near([0, 0], [0, -1])).toBe(true);
          expect(board.near([-1, 0], [0, 1])).toBe(false);
          expect(board.near([-14, 7], [-13, 7])).toBe(true);
          expect(board.near([-14, 8], [13, 8])).toBe(false);
        });
      });

      describe('.walkable', function (){
        beforeEach(function (){
          board.place_tile([0,0], test_tiles.n);
          board.place_tile([0,-1], test_tiles.sw);
          board.place_tile([-1,-1], test_tiles.se);
          board.place_tile([-1,0], test_tiles.ns);
        });

        it('should return true if two tiles have exits facing each other', function(){
          expect(board.walkable([0,0], [0, -1])).toBe(true);
          expect(board.walkable([0,-1], [-1, -1])).toBe(true);
          expect(board.walkable([0,0], [-1, 0])).toBe(false);
          expect(board.walkable([-1,-1], [0, 0])).toBe(false);
          expect(board.walkable([-1,-2], [0, 0])).toBe(false);
        });
      });
    });
  });
});<commit_msg>game (tests): generate test tiles to avoid mutations when acting on tiles directly and add new tests<commit_after>describe('Game', function() {
  describe('Board', function() {
    var board
        , Tile
        , example_tiles
        , test_tiles
        ;

    beforeEach(module('game.board'));

    beforeEach(inject(function(BoardManager, BoardTile) {
      board = BoardManager;
      Tile = BoardTile;
      example_tiles = {
          n:  new Tile({ exits: [0], }),
          ne: new Tile({ exits: [0, 1], }),
          e:  new Tile({ exits: [1], }),
          se: new Tile({ exits: [1, 2], }),
          s:  new Tile({ exits: [2], }),
          sw: new Tile({ exits: [2, 3], }),
          w:  new Tile({ exits: [3], }),
          nw: new Tile({ exits: [0, 3], }),
          ns: new Tile({ exits: [0, 2], }),
          ew: new Tile({ exits: [1, 3], }),
          "new": new Tile({ exits: [0, 2, 3], }),
          nesw: new Tile({ exits: [0, 1, 2, 3], }),
        };
      this.generate_tiles = function() {
        var dirs = [
          'n', 'ne', 'e', 'se', 's', 'sw',
          'w', 'nw', 'ns', 'ew', 'new', 'nesw'
        ];
        var exits = [
          [0], [0, 1], [1], [1, 2], [2], [2, 3],
          [3], [0, 3], [0, 2], [1, 3], [0, 2, 3], [0, 1, 2, 3],
        ];
        var test_tiles = {};
        dirs.forEach(function(dir, index){
          test_tiles[dir] = new Tile({ exits: exits[index] });
        });

        return test_tiles;
      };
    }));

    it('should have a BoardManager', function() {
      expect(board).toBeDefined();
    });
    it('should have a BoardTile', function() {
      expect(Tile).toBeDefined();
    });

    describe('Tile', function() {
      beforeEach(function (){
        test_tiles = this.generate_tiles();
      });

      describe('.exits', function() {
        it('should return exits rotated by tile.rotations', function(){
          expect(new Tile({ exits: [0], rotation: 1 }).exits).toEqual([1]);
          expect(new Tile({ exits: [0, 1], rotation: 2 }).exits).toEqual([2, 3]);
          expect(new Tile({ exits: [0, 2], rotation: 3 }).exits).toEqual([1, 3]);
          expect(new Tile({ exits: [0, 3], rotation: 4 }).exits).toEqual([0, 3]);
        });

        it('should update exits when tile.rotations is assigned post-creation', function(){
          test_tiles.s.rotation = -2;
          expect(test_tiles.s.exits).toEqual([0]);

          test_tiles.nw.rotation = 3;
          expect(test_tiles.nw.exits).toEqual([2, 3]);

          test_tiles.ne.rotation = -1;
          expect(test_tiles.ne.exits).toEqual([0, 3]);

          test_tiles.ew.rotation = 1;
          expect(test_tiles.ew.exits).toEqual([0, 2]);
        });

        it('should allow nevative rotations', function(){
          expect(new Tile({ exits: [0], rotation: -1 }).exits).toEqual([3]);
          expect(new Tile({ exits: [0, 1], rotation: -2 }).exits).toEqual([2, 3]);
          expect(new Tile({ exits: [0, 2], rotation: -3 }).exits).toEqual([1, 3]);
          expect(new Tile({ exits: [0, 3], rotation: -4 }).exits).toEqual([0, 3]);
        });
      });

    });

    describe('Manager', function() {
      beforeEach(function (){
        test_tiles = this.generate_tiles();
      });

      describe('.coord', function (){
        it('should convert a point to a string coordinate', function(){
          expect(board.coord([0, 0])).toEqual('0:0');
          expect(board.coord([14, -5])).toEqual('14:-5');
        });
      });

      describe('.point', function (){
        it('should convert a string coordinate to a point', function(){
          expect(board.point('0:0')).toEqual([0, 0]);
          expect(board.point('14:-5')).toEqual([14, -5]);
        });
      });

      describe('.place_tile', function (){
        beforeEach(function (){
          board.initalize();
          test_tiles = this.generate_tiles();
        });

        it('should place the tile in the board and update surrounding tiles', function(){
          var tile = test_tiles.n;
          board.place_tile([0, 0], tile);

          expect(board.tiles['0:0']).toBe(tile);
          expect(board.tiles['0:-1']).toBe(board.placeholders.indoor);
        });

        it('should place the rotated tile in the board and update surrounding tiles', function(){
          var tile = test_tiles.n;
          tile.rotation = 1;
          board.place_tile([0, 0], tile);

          expect(board.tiles['0:0']).toBe(tile);
          expect(board.tiles['1:0']).toBe(board.placeholders.indoor);
        });

        it('should not overwrite existing tiles with placeholders', function(){
          board.place_tile([0, 0], test_tiles.n);
          expect(board.tiles['0:0']).toBe(test_tiles.n);
          expect(board.tiles['0:-1']).toBe(board.placeholders.indoor);

          board.place_tile([0, -1], test_tiles.s);
          expect(board.tiles['0:-1']).toBe(test_tiles.s);
          expect(board.tiles['0:0']).toBe(test_tiles.n);
        });

      });

      describe('.near', function (){
        it('should return true if two points are next to one another', function(){
          expect(board.near([0, 0], [0, 1])).toBe(true);
          expect(board.near([0, 0], [0, -1])).toBe(true);
          expect(board.near([-1, 0], [0, 1])).toBe(false);
          expect(board.near([-14, 7], [-13, 7])).toBe(true);
          expect(board.near([-14, 8], [13, 8])).toBe(false);
        });
      });

      describe('.walkable', function (){
        beforeEach(function (){
          board.place_tile([0,0], test_tiles.n);
          board.place_tile([0,-1], test_tiles.sw);
          board.place_tile([-1,-1], test_tiles.se);
          board.place_tile([-1,0], test_tiles.ns);
        });

        it('should return true if two tiles have exits facing each other', function(){
          expect(board.walkable([0,0], [0, -1])).toBe(true);
          expect(board.walkable([0,-1], [-1, -1])).toBe(true);
          expect(board.walkable([0,0], [-1, 0])).toBe(false);
          expect(board.walkable([-1,-1], [0, 0])).toBe(false);
          expect(board.walkable([-1,-2], [0, 0])).toBe(false);
        });
      });

      describe('.walkable /w rotation', function (){
        beforeEach(function (){
        test_tiles = this.generate_tiles();

          test_tiles.s.rotation = -2;
          board.place_tile([0,0], test_tiles.s);

          test_tiles.nw.rotation = 3;
          board.place_tile([0,-1], test_tiles.nw);

          test_tiles.ne.rotation = -1;
          board.place_tile([-1,-1], test_tiles.ne);

          test_tiles.ew.rotation = 1;
          board.place_tile([-1,0], test_tiles.ew);
        });

        it('should return true if two tiles have exits facing each other', function(){
          expect(board.walkable([0,0], [0, -1])).toBe(true);
          expect(board.walkable([0,-1], [-1, -1])).toBe(true);
          expect(board.walkable([0,0], [-1, 0])).toBe(false);
          expect(board.walkable([-1,-1], [0, 0])).toBe(false);
          expect(board.walkable([-1,-2], [0, 0])).toBe(false);
        });
      });

    });
  });
});
{'fraction_non_alphanumeric': 0.1977280795172169, 'fraction_numerical': 0.03017394391196308, 'mean_word_length': 2.2050625711035265, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4521731', 'n_tokens_mistral': 3815, 'n_tokens_neox': 3628, 'n_words': 773}