<commit_before>#include <catch2/catch.hpp>

#include "orphan_key_up_events_manager.hpp"

TEST_CASE("orphan_key_up_events_manager") {
  krbn::orphan_key_up_events_manager m;

  // ----------------------------------------
  // key_down, key_up

  m.update(krbn::key_down_up_valued_event(krbn::key_code::a),
           krbn::event_type::key_down,
           krbn::absolute_time_point(1000));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  m.update(krbn::key_down_up_valued_event(krbn::key_code::a),
           krbn::event_type::key_up,
           krbn::absolute_time_point(1010));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  // ----------------------------------------
  // key_up, key_down, key_up, key_down, key_up

  m.update(krbn::key_down_up_valued_event(krbn::key_code::b),
           krbn::event_type::key_up,
           krbn::absolute_time_point(1100));
  REQUIRE(m.find_orphan_key_up_event() == krbn::key_down_up_valued_event(krbn::key_code::b));

  m.update(krbn::key_down_up_valued_event(krbn::key_code::b),
           krbn::event_type::key_down,
           krbn::absolute_time_point(1110));
  REQUIRE(m.find_orphan_key_up_event() == krbn::key_down_up_valued_event(krbn::key_code::b));

  m.update(krbn::key_down_up_valued_event(krbn::key_code::b),
           krbn::event_type::key_up,
           krbn::absolute_time_point(1120));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  m.update(krbn::key_down_up_valued_event(krbn::key_code::b),
           krbn::event_type::key_down,
           krbn::absolute_time_point(1130));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  m.update(krbn::key_down_up_valued_event(krbn::key_code::b),
           krbn::event_type::key_up,
           krbn::absolute_time_point(1140));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  // ----------------------------------------
  // ignore old event

  m.update(krbn::key_down_up_valued_event(krbn::key_code::c),
           krbn::event_type::key_up,
           krbn::absolute_time_point(900));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  m.update(krbn::key_down_up_valued_event(krbn::key_code::c),
           krbn::event_type::key_up,
           krbn::absolute_time_point(1200));
  REQUIRE(m.find_orphan_key_up_event() == krbn::key_down_up_valued_event(krbn::key_code::c));

  // ----------------------------------------
  // clear

  m.clear();
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  m.update(krbn::key_down_up_valued_event(krbn::key_code::a),
           krbn::event_type::key_up,
           krbn::absolute_time_point(500));
  REQUIRE(m.find_orphan_key_up_event() == krbn::key_down_up_valued_event(krbn::key_code::a));
}<commit_msg>update tests<commit_after>#include <catch2/catch.hpp>

#include "orphan_key_up_events_manager.hpp"

TEST_CASE("orphan_key_up_events_manager") {
  krbn::orphan_key_up_events_manager m;

  // ----------------------------------------
  // key_down, key_up

  m.update(krbn::key_down_up_valued_event(krbn::key_code::a),
           krbn::event_type::key_down,
           krbn::absolute_time_point(1000));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  m.update(krbn::key_down_up_valued_event(krbn::key_code::a),
           krbn::event_type::key_up,
           krbn::absolute_time_point(1010));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  // ----------------------------------------
  // key_up, key_down, key_up, key_down, key_up

  m.update(krbn::key_down_up_valued_event(krbn::key_code::b),
           krbn::event_type::key_up,
           krbn::absolute_time_point(1100));
  REQUIRE(m.find_orphan_key_up_event() == krbn::key_down_up_valued_event(krbn::key_code::b));

  m.update(krbn::key_down_up_valued_event(krbn::key_code::b),
           krbn::event_type::key_down,
           krbn::absolute_time_point(1110));
  REQUIRE(m.find_orphan_key_up_event() == krbn::key_down_up_valued_event(krbn::key_code::b));

  m.update(krbn::key_down_up_valued_event(krbn::key_code::b),
           krbn::event_type::key_up,
           krbn::absolute_time_point(1120));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  m.update(krbn::key_down_up_valued_event(krbn::key_code::b),
           krbn::event_type::key_down,
           krbn::absolute_time_point(1130));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  m.update(krbn::key_down_up_valued_event(krbn::key_code::b),
           krbn::event_type::key_up,
           krbn::absolute_time_point(1140));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  // ----------------------------------------
  // ignore old event

  m.update(krbn::key_down_up_valued_event(krbn::key_code::c),
           krbn::event_type::key_up,
           krbn::absolute_time_point(900));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  m.update(krbn::key_down_up_valued_event(krbn::key_code::c),
           krbn::event_type::key_up,
           krbn::absolute_time_point(1200));
  REQUIRE(m.find_orphan_key_up_event() == krbn::key_down_up_valued_event(krbn::key_code::c));

  // ----------------------------------------
  // clear

  m.clear();
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  m.update(krbn::key_down_up_valued_event(krbn::key_code::a),
           krbn::event_type::key_up,
           krbn::absolute_time_point(500));
  REQUIRE(m.find_orphan_key_up_event() == krbn::key_down_up_valued_event(krbn::key_code::a));
}

TEST_CASE("orphan_key_up_events_manager key_down is dropped") {
  krbn::orphan_key_up_events_manager m;

  // ----------------------------------------
  // key_down, key_up, key_up

  m.update(krbn::key_down_up_valued_event(krbn::key_code::a),
           krbn::event_type::key_down,
           krbn::absolute_time_point(1000));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  m.update(krbn::key_down_up_valued_event(krbn::key_code::a),
           krbn::event_type::key_up,
           krbn::absolute_time_point(1010));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);

  m.update(krbn::key_down_up_valued_event(krbn::key_code::a),
           krbn::event_type::key_up,
           krbn::absolute_time_point(1020));
  REQUIRE(m.find_orphan_key_up_event() == std::nullopt);
}
{'fraction_non_alphanumeric': 0.20398009950248755, 'fraction_numerical': 0.014443909484833895, 'mean_word_length': 3.5722670579603815, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1569028', 'n_tokens_mistral': 2551, 'n_tokens_neox': 2460, 'n_words': 167}