<commit_before>package backend
package internal

import org.junit.Test

import protocol.ui.Columns
import protocol.ui.Rows
import protocol.ui.Window

class WindowTreeCreatorTest {
  import WindowTreeCreator._
  import TestUtils._

  private def dims(dim: (Int, Int, Int, Int)*): Seq[WinInfo] = {
    dim.zipWithIndex.toList map {
      case ((x, y, w, h), i) ⇒ WinInfo(i+1, x, y, w, h)
    }
  }

  @Test
  def single_window() = {
    /*
     ---
     | |
     ---
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1)))
    tree === Window("window1")
  }

  @Test
  def multiple_windows_in_a_single_row() = {
    /*
     -------
     | | | |
     -------
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1), (1, 0, 1, 1), (2, 0, 1, 1)))
    tree === Columns(Seq(Window("window1"), Window("window2"), Window("window3")))
  }

  @Test
  def multiple_windows_in_a_single_column() = {
    /*
     ---
     | |
     ---
     | |
     ---
     | |
     ---
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1), (0, 1, 1, 1), (0, 2, 1, 1)))
    tree === Rows(Seq(Window("window1"), Window("window2"), Window("window3")))
  }

  @Test
  def multiple_winodws_in_first_column_and_one_window_in_second_column() = {
    /*
     -----
     | | |
     --- |
     | | |
     -----
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1), (0, 1, 1, 1), (1, 0, 1, 2)))
    tree === Columns(Seq(
        Rows(Seq(Window("window1"), Window("window2"))),
        Window("window3")))
  }

  @Test
  def multiple_windows_in_first_row_and_one_window_in_second_row() = {
    /*
     -----
     | | |
     -----
     |   |
     -----
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1), (1, 0, 1, 1), (0, 1, 2, 1)))
    tree === Rows(Seq(
        Columns(Seq(Window("window1"), Window("window2"))),
        Window("window3")))
  }

  @Test
  def single_window_in_first_row_and_multiple_windows_in_second_row() = {
    /*
     -----
     |   |
     -----
     | | |
     -----
    */
    val tree = mkWindowTree(dims((0, 0, 2, 1), (0, 1, 1, 1), (1, 1, 1, 1)))
    tree === Rows(Seq(
        Window("window1"),
        Columns(Seq(Window("window2"), Window("window3")))))
  }

  @Test
  def multiple_windows_in_all_rows() = {
    /*
     -----
     | | |
     -----
     | | |
     -----
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1), (1, 0, 1, 1), (0, 1, 1, 1), (1, 1, 1, 1)))
    tree === Rows(Seq(
        Columns(Seq(Window("window1"), Window("window2"))),
        Columns(Seq(Window("window3"), Window("window4")))))
  }

  @Test
  def multiple_windows_nested_between_multiple_windows1() = {
    /*
     ---------
     |   |   |
     |   |   |
     |   |   |
     ---------
     |   | | |
     |   -----
     |   | | |
     ---------
    */
    val tree = mkWindowTree(dims((0, 0, 2, 2), (2, 0, 2, 2), (0, 2, 2, 2), (2, 2, 1, 1), (3, 2, 1, 1), (2, 3, 1, 1), (3, 3, 1, 1)))
    tree === Rows(Seq(
        Columns(Seq(Window("window1"), Window("window2"))),
        Columns(Seq(
            Window("window3"),
            Rows(Seq(
                Columns(Seq(Window("window4"), Window("window5"))),
                Columns(Seq(Window("window6"), Window("window7")))))))))
  }

  @Test
  def multiple_windows_nested_between_multiple_windows2() = {
    /*
     ---------
     |   |   |
     |   |   |
     |   |   |
     ---------
     | | |   |
     -----   |
     | | |   |
     ---------
    */
    val tree = mkWindowTree(dims((0, 0, 2, 2), (2, 0, 2, 2), (0, 2, 1, 1), (1, 2, 1, 1), (0, 3, 1, 1), (1, 3, 1, 1), (2, 2, 2, 2)))
    tree === Rows(Seq(
        Columns(Seq(Window("window1"), Window("window2"))),
        Columns(Seq(
            Rows(Seq(
                Columns(Seq(Window("window3"), Window("window4"))),
                Columns(Seq(Window("window5"), Window("window6"))))),
            Window("window7")))))
  }

  @Test
  def unsorted_coordinates_should_be_handled_well() = {
    /*
     -----
     | | |
     -----
     | | |
     -----
    */
    val tree = mkWindowTree(dims((0, 1, 1, 1), (1, 0, 1, 1), (1, 1, 1, 1), (0, 0, 1, 1)))
    tree === Rows(Seq(
        Columns(Seq(Window("window4"), Window("window2"))),
        Columns(Seq(Window("window1"), Window("window3")))))
  }
}<commit_msg>Add further more complex test cases<commit_after>package backend
package internal

import org.junit.Test

import protocol.ui.Columns
import protocol.ui.Rows
import protocol.ui.Window

class WindowTreeCreatorTest {
  import WindowTreeCreator._
  import TestUtils._

  /** Takes (x, y, w, h). */
  private def dims(dim: (Int, Int, Int, Int)*): Seq[WinInfo] = {
    dim.zipWithIndex.toList map {
      case ((x, y, w, h), i) ⇒ WinInfo(i+1, x, y, w, h)
    }
  }

  @Test
  def single_window() = {
    /*
     ---
     | |
     ---
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1)))
    tree === Window("window1")
  }

  @Test
  def multiple_windows_in_a_single_row() = {
    /*
     -------
     | | | |
     -------
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1), (1, 0, 1, 1), (2, 0, 1, 1)))
    tree === Columns(Seq(Window("window1"), Window("window2"), Window("window3")))
  }

  @Test
  def multiple_windows_in_a_single_column() = {
    /*
     ---
     | |
     ---
     | |
     ---
     | |
     ---
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1), (0, 1, 1, 1), (0, 2, 1, 1)))
    tree === Rows(Seq(Window("window1"), Window("window2"), Window("window3")))
  }

  @Test
  def multiple_winodws_in_first_column_and_one_window_in_second_column() = {
    /*
     -----
     | | |
     --- |
     | | |
     -----
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1), (0, 1, 1, 1), (1, 0, 1, 2)))
    tree === Columns(Seq(
        Rows(Seq(Window("window1"), Window("window2"))),
        Window("window3")))
  }

  @Test
  def multiple_windows_in_first_row_and_one_window_in_second_row() = {
    /*
     -----
     | | |
     -----
     |   |
     -----
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1), (1, 0, 1, 1), (0, 1, 2, 1)))
    tree === Rows(Seq(
        Columns(Seq(Window("window1"), Window("window2"))),
        Window("window3")))
  }

  @Test
  def single_window_in_first_row_and_multiple_windows_in_second_row() = {
    /*
     -----
     |   |
     -----
     | | |
     -----
    */
    val tree = mkWindowTree(dims((0, 0, 2, 1), (0, 1, 1, 1), (1, 1, 1, 1)))
    tree === Rows(Seq(
        Window("window1"),
        Columns(Seq(Window("window2"), Window("window3")))))
  }

  @Test
  def multiple_windows_in_all_rows() = {
    /*
     -----
     | | |
     -----
     | | |
     -----
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1), (1, 0, 1, 1), (0, 1, 1, 1), (1, 1, 1, 1)))
    tree === Rows(Seq(
        Columns(Seq(Window("window1"), Window("window2"))),
        Columns(Seq(Window("window3"), Window("window4")))))
  }

  @Test
  def multiple_windows_nested_between_multiple_windows1() = {
    /*
     ---------
     |   |   |
     |   |   |
     |   |   |
     ---------
     |   | | |
     |   -----
     |   | | |
     ---------
    */
    val tree = mkWindowTree(dims((0, 0, 2, 2), (2, 0, 2, 2), (0, 2, 2, 2), (2, 2, 1, 1), (3, 2, 1, 1), (2, 3, 1, 1), (3, 3, 1, 1)))
    tree === Rows(Seq(
        Columns(Seq(Window("window1"), Window("window2"))),
        Columns(Seq(
            Window("window3"),
            Rows(Seq(
                Columns(Seq(Window("window4"), Window("window5"))),
                Columns(Seq(Window("window6"), Window("window7")))))))))
  }

  @Test
  def multiple_windows_nested_between_multiple_windows2() = {
    /*
     ---------
     |   |   |
     |   |   |
     |   |   |
     ---------
     | | |   |
     -----   |
     | | |   |
     ---------
    */
    val tree = mkWindowTree(dims((0, 0, 2, 2), (2, 0, 2, 2), (0, 2, 1, 1), (1, 2, 1, 1), (0, 3, 1, 1), (1, 3, 1, 1), (2, 2, 2, 2)))
    tree === Rows(Seq(
        Columns(Seq(Window("window1"), Window("window2"))),
        Columns(Seq(
            Rows(Seq(
                Columns(Seq(Window("window3"), Window("window4"))),
                Columns(Seq(Window("window5"), Window("window6"))))),
            Window("window7")))))
  }

  @Test
  def multiple_windows_nested_between_multiple_windows3() = {
    /*
     ---------
     |   | | |
     |   -----
     |   | | |
     ---------
     |   |   |
     |   |   |
     |   |   |
     ---------
    */
    val tree = mkWindowTree(dims((0, 0, 2, 2), (2, 0, 1, 1), (3, 0, 1, 1), (2, 1, 1, 1), (3, 1, 1, 1), (0, 2, 2, 2), (2, 2, 2, 2)))
    tree === Rows(Seq(
        Columns(Seq(
            Window("window1"),
            Rows(Seq(
                Columns(Seq(Window("window2"), Window("window3"))),
                Columns(Seq(Window("window4"), Window("window5"))))))),
        Columns(Seq(Window("window6"), Window("window7")))))
  }

  @Test
  def multiple_windows_nested_between_multiple_windows4() = {
    /*
     ---------
     | | |   |
     -----   |
     | | |   |
     ---------
     |   |   |
     |   |   |
     |   |   |
     ---------
    */
    val tree = mkWindowTree(dims((0, 0, 1, 1), (1, 0, 1, 1), (0, 1, 1, 1), (1, 1, 1, 1), (2, 0, 2, 2), (0, 2, 2, 2), (2, 2, 2, 2)))
    tree === Rows(Seq(
        Columns(Seq(
            Rows(Seq(
                Columns(Seq(Window("window1"), Window("window2"))),
                Columns(Seq(Window("window3"), Window("window4"))),
            Window("window5"))))),
        Columns(Seq(Window("window6"), Window("window7")))))
  }

  @Test
  def multiple_windows_surrounded_by_single_windows() = {
    /*
     -------------
     |           |
     -------------
     |   | | |   |
     |   -----   |
     |   |   |   |
     -------------
     |           |
     -------------
    */
    val tree = mkWindowTree(dims((0, 0, 6, 1), (0, 1, 2, 2), (2, 1, 1, 1), (3, 1, 1, 1), (2, 2, 2, 1), (4, 1, 2, 2), (0, 3, 6, 1)))
    tree === Rows(Seq(
        Window("window1"),
        Columns(Seq(
            Window("window2"),
            Rows(Seq(
                Columns(Seq(Window("window3"), Window("window4"))),
                Window("window5"))),
            Window("window6"))),
        Window("window7")))
  }

  @Test
  def unsorted_coordinates_should_be_handled_well() = {
    /*
     -----
     | | |
     -----
     | | |
     -----
    */
    val tree = mkWindowTree(dims((0, 1, 1, 1), (1, 0, 1, 1), (1, 1, 1, 1), (0, 0, 1, 1)))
    tree === Rows(Seq(
        Columns(Seq(Window("window4"), Window("window2"))),
        Columns(Seq(Window("window1"), Window("window3")))))
  }
}
{'fraction_non_alphanumeric': 0.23789897440812804, 'fraction_numerical': 0.04725390587558708, 'mean_word_length': 1.7143600416233091, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4264557', 'n_tokens_mistral': 4215, 'n_tokens_neox': 3858, 'n_words': 744}