<commit_before>/*
 * Copyright (C) 2013 <NAME>
 *
 * 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.
 */

package com.btmura.android.reddit.util;

import android.view.Gravity;

import com.btmura.android.reddit.util.MarkdownTableScanner.OnTableScanListener;
import com.btmura.android.reddit.util.MarkdownTableScanner.OnTableScanListener.Cell;

import junit.framework.TestCase;

import java.util.ArrayList;
import java.util.List;

public class MarkdownTableScannerTest extends TestCase {

  private static final String OUTER_PIPES = "|a|b|c|\n"
      + "|:-|::|-:|\n"
      + "|d|e|f|";

  private static final String NO_OUTER_PIPES = "a|b|c\n"
      + ":-|::|-:\n"
      + "d|e|f";

  private static final String EMPTY_HEADERS = "||\n"
      + ":-|::|-:\n"
      + "a|b|c";

  private static final String MISSING_CELLS = "a||\n"
      + ":-|::|-:\n"
      + "|b|\n"
      + "||c\n"
      + "|";

  public void testScan_outerPipes() {
    Table table = scan(OUTER_PIPES);
    assertTableSize(table, 2, 3);

    assertCell(table, 0, 0, "a", Gravity.LEFT, true);
    assertCell(table, 0, 1, "b", Gravity.CENTER, true);
    assertCell(table, 0, 2, "c", Gravity.RIGHT, true);

    assertCell(table, 1, 0, "d", Gravity.LEFT, false);
    assertCell(table, 1, 1, "e", Gravity.CENTER, false);
    assertCell(table, 1, 2, "f", Gravity.RIGHT, false);
  }

  public void testScan_noOuterPipes() {
    Table table = scan(NO_OUTER_PIPES);
    assertTableSize(table, 2, 3);

    assertCell(table, 0, 0, "a", Gravity.LEFT, true);
    assertCell(table, 0, 1, "b", Gravity.CENTER, true);
    assertCell(table, 0, 2, "c", Gravity.RIGHT, true);

    assertCell(table, 1, 0, "d", Gravity.LEFT, false);
    assertCell(table, 1, 1, "e", Gravity.CENTER, false);
    assertCell(table, 1, 2, "f", Gravity.RIGHT, false);
  }

  public void testScan_emptyHeaders() {
    Table table = scan(EMPTY_HEADERS);
    assertTableSize(table, 2, 3);

    assertCell(table, 0, 0, "", Gravity.LEFT, true);
    assertCell(table, 0, 1, "", Gravity.CENTER, true);
    assertCell(table, 0, 2, "", Gravity.RIGHT, true);

    assertCell(table, 1, 0, "a", Gravity.LEFT, false);
    assertCell(table, 1, 1, "b", Gravity.CENTER, false);
    assertCell(table, 1, 2, "c", Gravity.RIGHT, false);
  }

  public void testScan_missingCells() {
    Table table = scan(MISSING_CELLS);
    assertTableSize(table, 4, 3);

    assertCell(table, 0, 0, "a", Gravity.LEFT, true);
    assertCell(table, 0, 1, "", Gravity.CENTER, true);
    assertCell(table, 0, 2, "", Gravity.RIGHT, true);

    assertCell(table, 1, 0, "", Gravity.LEFT, false);
    assertCell(table, 1, 1, "b", Gravity.CENTER, false);
    assertCell(table, 1, 2, "", Gravity.RIGHT, false);

    assertCell(table, 2, 0, "", Gravity.LEFT, false);
    assertCell(table, 2, 1, "", Gravity.CENTER, false);
    assertCell(table, 2, 2, "c", Gravity.RIGHT, false);

    assertCell(table, 3, 0, "", Gravity.LEFT, false);
    assertCell(table, 3, 1, "", Gravity.CENTER, false);
    assertCell(table, 3, 2, "", Gravity.RIGHT, false);
  }

  private static Table scan(String tableData) {
    Table table = new Table();
    MarkdownTableScanner.scan(tableData, table);
    return table;
  }

  private static void assertTableSize(
      Table table,
      int expectedRows,
      int expectedColumns) {
    assertEquals(expectedRows, table.rows.size());
    for (int i = 0; i < expectedRows; i++) {
      assertEquals("row: " + i, expectedColumns, table.rows.get(i).size());
    }
  }

  private static void assertCell(
      Table table,
      int row,
      int column,
      String expectedContent,
      int expectedGravity,
      boolean expectedIsHeader) {
    Cell cell = table.rows.get(row).get(column);
    assertEquals(expectedContent, cell.contents);
    assertEquals(expectedGravity, cell.gravity);<commit_msg>Update gravity constants in test<commit_after>/*
 * Copyright (C) 2013 <NAME>
 *
 * 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.
 */

package com.btmura.android.reddit.util;

import android.view.Gravity;

import com.btmura.android.reddit.util.MarkdownTableScanner.OnTableScanListener;
import com.btmura.android.reddit.util.MarkdownTableScanner.OnTableScanListener.Cell;

import junit.framework.TestCase;

import java.util.ArrayList;
import java.util.List;

public class MarkdownTableScannerTest extends TestCase {

  private static final String OUTER_PIPES = "|a|b|c|\n"
      + "|:-|::|-:|\n"
      + "|d|e|f|";

  private static final String NO_OUTER_PIPES = "a|b|c\n"
      + ":-|::|-:\n"
      + "d|e|f";

  private static final String EMPTY_HEADERS = "||\n"
      + ":-|::|-:\n"
      + "a|b|c";

  private static final String MISSING_CELLS = "a||\n"
      + ":-|::|-:\n"
      + "|b|\n"
      + "||c\n"
      + "|";

  public void testScan_outerPipes() {
    Table table = scan(OUTER_PIPES);
    assertTableSize(table, 2, 3);

    assertCell(table, 0, 0, "a", Gravity.START, true);
    assertCell(table, 0, 1, "b", Gravity.CENTER, true);
    assertCell(table, 0, 2, "c", Gravity.END, true);

    assertCell(table, 1, 0, "d", Gravity.START, false);
    assertCell(table, 1, 1, "e", Gravity.CENTER, false);
    assertCell(table, 1, 2, "f", Gravity.END, false);
  }

  public void testScan_noOuterPipes() {
    Table table = scan(NO_OUTER_PIPES);
    assertTableSize(table, 2, 3);

    assertCell(table, 0, 0, "a", Gravity.START, true);
    assertCell(table, 0, 1, "b", Gravity.CENTER, true);
    assertCell(table, 0, 2, "c", Gravity.END, true);

    assertCell(table, 1, 0, "d", Gravity.START, false);
    assertCell(table, 1, 1, "e", Gravity.CENTER, false);
    assertCell(table, 1, 2, "f", Gravity.END, false);
  }

  public void testScan_emptyHeaders() {
    Table table = scan(EMPTY_HEADERS);
    assertTableSize(table, 2, 3);

    assertCell(table, 0, 0, "", Gravity.START, true);
    assertCell(table, 0, 1, "", Gravity.CENTER, true);
    assertCell(table, 0, 2, "", Gravity.END, true);

    assertCell(table, 1, 0, "a", Gravity.START, false);
    assertCell(table, 1, 1, "b", Gravity.CENTER, false);
    assertCell(table, 1, 2, "c", Gravity.END, false);
  }

  public void testScan_missingCells() {
    Table table = scan(MISSING_CELLS);
    assertTableSize(table, 4, 3);

    assertCell(table, 0, 0, "a", Gravity.START, true);
    assertCell(table, 0, 1, "", Gravity.CENTER, true);
    assertCell(table, 0, 2, "", Gravity.END, true);

    assertCell(table, 1, 0, "", Gravity.START, false);
    assertCell(table, 1, 1, "b", Gravity.CENTER, false);
    assertCell(table, 1, 2, "", Gravity.END, false);

    assertCell(table, 2, 0, "", Gravity.START, false);
    assertCell(table, 2, 1, "", Gravity.CENTER, false);
    assertCell(table, 2, 2, "c", Gravity.END, false);

    assertCell(table, 3, 0, "", Gravity.START, false);
    assertCell(table, 3, 1, "", Gravity.CENTER, false);
    assertCell(table, 3, 2, "", Gravity.END, false);
  }

  private static Table scan(String tableData) {
    Table table = new Table();
    MarkdownTableScanner.scan(tableData, table);
    return table;
  }

  private static void assertTableSize(
      Table table,
      int expectedRows,
      int expectedColumns) {
    assertEquals(expectedRows, table.rows.size());
    for (int i = 0; i < expectedRows; i++) {
      assertEquals("row: " + i, expectedColumns, table.rows.get(i).size());
    }
  }

  private static void assertCell(
      Table table,
      int row,
      int column,
      String expectedContent,
      int expectedGravity,
      boolean expectedIsHeader) {
    Cell cell = table.rows.get(row).get(column);
    assertEquals(expectedContent, cell.contents);
    assertEquals(expectedGravity, cell.gravity);
{'fraction_non_alphanumeric': 0.15206573313273927, 'fraction_numerical': 0.017822011341279944, 'mean_word_length': 3.536482939632546, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6721798', 'n_tokens_mistral': 3111, 'n_tokens_neox': 2914, 'n_words': 799}