<commit_before>'use strict'

import test from 'tape'
import Grid from '../../'

const WIDTH = 1600
const HEIGHT = 900

function StubWindow (id, width, height) {
  this.id = id
  this.width = width,
  this.height = height
}

test('can add windows to grid', t => {
  t.plan(4)
  try {
    const grid = new Grid(WIDTH, HEIGHT)
    const stubWindow1 = new StubWindow(1, 400, 600)
    const stubWindow2 = new StubWindow(2, 400, 600)
    grid.add(stubWindow1)
    t.equals(grid.windows.length, 1, 'grid has one window')
    t.deepEquals(grid.getWindow(1), Object.assign({}, stubWindow1, {
      x: 0,
      y: 0
    }), 'window added in default location')
    grid.add(stubWindow2, 950, 0)
    t.equals(grid.windows.length, 2, 'grid has two windows')
    t.deepEquals(grid.getWindow(2), Object.assign({}, stubWindow2, {
      x: 950,
      y: 0
    }), 'window added in custom location')
  } catch (e) {
    t.fail(e.toString())
  }
})

test('windows should not be created over each other', t => {
  t.plan(5)
  try {
    const grid = new Grid(WIDTH, HEIGHT)
    const stubWindow1 = new StubWindow(1, 200, 100)
    const stubWindow2 = new StubWindow(2, 200, 100)
    grid.add(stubWindow1)
    t.throws(
      () => grid.add(stubWindow2, 199, 0),
      Error,
      'window cannot be created over existing window on x axis'
    )
    t.throws(
      () => grid.add(stubWindow2, 0, 99),
      Error,
      'window cannot be created over existing window on y axis'
    )
    t.throws(
      () => grid.add(stubWindow2, 199, 99),
      Error,
      'window cannot be created over existing window on multiple axes'
    )
    t.equals(grid.windows.length, 1, 'grid still has one window')
    t.deepEquals(grid.getWindow(1), Object.assign({}, stubWindow1, {
      x: 0,
      y: 0
    }), 'first window still present')
  } catch (e) {
    t.fail(e.toString())
    t.end()
  }
})<commit_msg>added tests for window creation out of bounds<commit_after>'use strict'

import test from 'tape'
import Grid from '../../'

const WIDTH = 1600
const HEIGHT = 900

function StubWindow (id, width, height) {
  this.id = id
  this.width = width,
  this.height = height
}

test('can add windows to grid', t => {
  t.plan(4)
  try {
    const grid = new Grid(WIDTH, HEIGHT)
    const stubWindow1 = new StubWindow(1, 400, 600)
    const stubWindow2 = new StubWindow(2, 400, 600)
    grid.add(stubWindow1)
    t.equals(grid.windows.length, 1, 'grid has one window')
    t.deepEquals(grid.getWindow(1), Object.assign({}, stubWindow1, {
      x: 0,
      y: 0
    }), 'window added in default location')
    grid.add(stubWindow2, 950, 0)
    t.equals(grid.windows.length, 2, 'grid has two windows')
    t.deepEquals(grid.getWindow(2), Object.assign({}, stubWindow2, {
      x: 950,
      y: 0
    }), 'window added in custom location')
  } catch (e) {
    t.fail(e.toString())
  }
})

test('windows should not be created over each other', t => {
  t.plan(7)
  try {
    const grid = new Grid(WIDTH, HEIGHT)
    const stubWindow1 = new StubWindow(1, 200, 100)
    const stubWindow2 = new StubWindow(2, 200, 100)
    grid.add(stubWindow1)
    t.throws(
      () => grid.add(stubWindow2, 199, 0),
      Error,
      'window cannot be created over existing window on x axis'
    )
    t.throws(
      () => grid.add(stubWindow2, 0, 99),
      Error,
      'window cannot be created over existing window on y axis'
    )
    t.throws(
      () => grid.add(stubWindow2, 199, 99),
      Error,
      'window cannot be created over existing window on multiple axes'
    )
    t.throws(
      () => grid.add(stubWindow2, 1401, 0),
      Error,
      'window cannot exceed grid horizontal bounds'
    )
    t.throws(
      () => grid.add(stubWindow2, 0, 801),
      Error,
      'window canonot exceed grid vertical bounds'
    )
    t.equals(grid.windows.length, 1, 'grid still has one window')
    t.deepEquals(grid.getWindow(1), Object.assign({}, stubWindow1, {
      x: 0,
      y: 0
    }), 'first window still present')
  } catch (e) {
    t.fail(e.toString())
    t.end()
  }
})
{'fraction_non_alphanumeric': 0.13706086095992084, 'fraction_numerical': 0.04230578921326076, 'mean_word_length': 2.7023809523809526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3499599', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1379, 'n_words': 416}