<commit_before>use patterns::Patterns;

fn construct_patterns(s: &str) -> Patterns {
  let mut pattern_s = String::new();
  for line in s.split('\n').map(|line| line.trim_matches(' ')).filter(|line| !line.is_empty()) {
    pattern_s.push_str(line);
    pattern_s.push('\n');
  }
  let mut p = Patterns::empty();
  p.add_str(pattern_s.as_str());
  p
}

#[test]
#[should_panic]
fn pattern_moves_discrepancy() {
  construct_patterns(
    "
    4 4 1.0
    ....
    .RB.
    .BR.
    ..+.
    3 3 1.0
    "
  );
}<commit_msg>Add patterns tests.<commit_after>use player::Player;
use patterns::Patterns;
use construct_field::construct_field;

fn construct_patterns(strings: &[&str]) -> Patterns {
  let mut pattern_s = String::new();
  let mut p = Patterns::empty();
  for s in strings {
    pattern_s.clear();
    for line in s.split('\n').map(|line| line.trim_matches(' ')).filter(|line| !line.is_empty()) {
      pattern_s.push_str(line);
      pattern_s.push('\n');
    }
    p.add_str(pattern_s.as_str());
  }
  p
}

#[test]
#[should_panic]
fn pattern_moves_discrepancy() {
  construct_patterns(&[
    "
    4 4 1.0
    ....
    .RB.
    .BR.
    ..+.
    3 3 1.0
    "
  ]);
}

#[test]
#[should_panic]
fn pattern_without_moves_on_image() {
  construct_patterns(&[
    "
    4 4 1.0
    ....
    .RB.
    .BR.
    ....
    3 3 1.0
    "
  ]);
}

#[test]
fn pattern_borders_matches() {
  let p = construct_patterns(&[
    "
    4 4 1.0
    #...
    #RB.
    #BR.
    #..+
    3 3 1.0
    "
  ]);
  let field = construct_field(
    "
    ...
    aA.
    Aa.
    ...
    "
  );
  assert_eq!(p.find(&field, Player::Red, false), vec![(field.to_pos(2, 3), 1f64)]);
}

#[test]
fn pattern_borders_doesnt_match() {
  let p = construct_patterns(&[
    "
    4 4 1.0
    #...
    #RB.
    #BR.
    #..+
    3 3 1.0
    "
  ]);
  let field = construct_field(
    "
    ....
    .aA.
    .Aa.
    ....
    "
  );
  assert!(p.find(&field, Player::Red, false).is_empty());
}
{'fraction_non_alphanumeric': 0.19458631256384065, 'fraction_numerical': 0.022982635342185902, 'mean_word_length': 2.139423076923077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6846968', 'n_tokens_mistral': 824, 'n_tokens_neox': 806, 'n_words': 147}