<commit_before>package fitnesse.testsystems.slim.tables;

import fitnesse.testsystems.ExecutionResult;
import fitnesse.testsystems.slim.SlimTestContext;
import fitnesse.testsystems.slim.Table;
import fitnesse.testsystems.slim.results.SlimTestResult;

import java.util.List;

public class OrderedQueryTable extends QueryTable {
  private int lastMatchedRow = -1;

  public OrderedQueryTable(Table table, String tableId, SlimTestContext slimTestContext) {
    super(table, tableId, slimTestContext);
  }

  @Override
  protected ExecutionResult markRows(QueryResults queryResults, Iterable<MatchedResult> potentialMatchesByScore) {
    int rowCount = table.getRowCount();
    List<Integer> unmatchedResultRows = unmatchedRows(queryResults.getRows().size());

    for (int tableRow = 2; tableRow < rowCount; tableRow++) {
      MatchedResult bestMatch = takeBestMatch(potentialMatchesByScore, tableRow);
      if (bestMatch == null) {
        markMissingRow(tableRow);
      } else {
        markFieldsInMatchedRow(bestMatch.tableRow, bestMatch.resultRow, queryResults);
        lastMatchedRow = bestMatch.resultRow;
        unmatchedResultRows.remove(bestMatch.resultRow);
      }
    }

    return markSurplusRows(queryResults, unmatchedResultRows);
  }

  private MatchedResult takeBestMatch(Iterable<MatchedResult> potentialMatchesByScore, int tableRow) {
    for (MatchedResult bestResult : potentialMatchesByScore) {
      if (bestResult.tableRow == tableRow) {
        removeOtherwiseMatchedResults(potentialMatchesByScore, bestResult);
        return bestResult;
      }
    }
    return null;
  }

  @Override
  protected SlimTestResult markMatch(int tableRow, int matchedRow, int col, String message) {
    SlimTestResult testResult;
    if (col == 0 && matchedRow <= lastMatchedRow) {
      testResult = SlimTestResult.fail(null, message, "out of order: row " + (matchedRow + 1));
    } else {
      testResult = SlimTestResult.pass(message);
    }
    return testResult;
  }
}<commit_msg>fixes 575: When using a Query decission table, not all wrongs are reported in the JUnitRunNotifierResultsListener<commit_after>package fitnesse.testsystems.slim.tables;

import fitnesse.testsystems.ExecutionResult;
import fitnesse.testsystems.slim.SlimTestContext;
import fitnesse.testsystems.slim.Table;
import fitnesse.testsystems.slim.results.SlimTestResult;

import java.util.List;

public class OrderedQueryTable extends QueryTable {
  private int lastMatchedRow = -1;

  public OrderedQueryTable(Table table, String tableId, SlimTestContext slimTestContext) {
    super(table, tableId, slimTestContext);
  }

  @Override
  protected ExecutionResult markRows(QueryResults queryResults, Iterable<MatchedResult> potentialMatchesByScore) {
    int rowCount = table.getRowCount();
    List<Integer> unmatchedResultRows = unmatchedRows(queryResults.getRows().size());

    for (int tableRow = 2; tableRow < rowCount; tableRow++) {
      MatchedResult bestMatch = takeBestMatch(potentialMatchesByScore, tableRow);
      if (bestMatch == null) {
        markMissingRow(tableRow);
      } else {
        markFieldsInMatchedRow(bestMatch.tableRow, bestMatch.resultRow, queryResults);
        lastMatchedRow = bestMatch.resultRow;
        unmatchedResultRows.remove(bestMatch.resultRow);
      }
    }

    markSurplusRows(queryResults, unmatchedResultRows);

    return unmatchedResultRows.size() > 0 ? ExecutionResult.FAIL : ExecutionResult.PASS;
  }

  private MatchedResult takeBestMatch(Iterable<MatchedResult> potentialMatchesByScore, int tableRow) {
    for (MatchedResult bestResult : potentialMatchesByScore) {
      if (bestResult.tableRow == tableRow) {
        removeOtherwiseMatchedResults(potentialMatchesByScore, bestResult);
        return bestResult;
      }
    }
    return null;
  }

  @Override
  protected SlimTestResult markMatch(int tableRow, int matchedRow, int col, String message) {
    SlimTestResult testResult;
    if (col == 0 && matchedRow <= lastMatchedRow) {
      testResult = SlimTestResult.fail(null, message, "out of order: row " + (matchedRow + 1));
    } else {
      testResult = SlimTestResult.pass(message);
    }
    return testResult;
  }
}
{'fraction_non_alphanumeric': 0.08786210198707206, 'fraction_numerical': 0.0028728752693320567, 'mean_word_length': 4.377091377091377, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 10, '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': '5561427', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1209, 'n_words': 259}