<commit_before>
#include <map>
#include <string>

#include <gtest/gtest.h>

#include "../lib/entity.h"
#include "../lib/units.h"

#include "../c_keyboardable.h"
#include "../s_keyboard_events.h"

using namespace std;
using namespace spacegun;

/*
TEST(Keyboardable, Constructor) {
  unsigned int expected = 1;
  map<string, unsigned int> keyMap;
  keyMap["testa"] = expected;

  Keyboardable c = Keyboardable(keyMap);

  auto actual = c.getAction("testa");

  EXPECT_EQ(expected, actual);
}

TEST(Keyboardable, getType) {
  Keyboardable c;

  auto actual = c.getType();

  EXPECT_EQ(actual, COMPONENT_TYPE_KEYBOARDABLE);
}

TEST(Keyboardable, getKeys) {
  string expectedA = "testa";
  string expectedB = "testb";
  map<string, unsigned int> keyMap;
  keyMap[expectedA] = 1;
  keyMap[expectedB] = 1;

  Keyboardable c = Keyboardable(keyMap);

  // TODO do maps in c++ guarantee an order?
  auto actualA = c.getKeys().at(0);
  auto actualB = c.getKeys().at(1);

  EXPECT_EQ(expectedA, actualA);
  EXPECT_EQ(expectedB, actualB);
}

TEST(Keyboardable, getAction) {
  unsigned int testA = 1;
  unsigned int testB = 2;
  map<string, unsigned int> expected;
  expected["testa"] = testA;
  expected["testb"] = testB;

  Keyboardable c = Keyboardable(expected);

  auto actualA = c.getAction("testa");
  auto actualB = c.getAction("testb");

  EXPECT_EQ(expected["testa"], actualA);
  EXPECT_EQ(expected["testb"], actualB);
}

TEST(KeyboardEvents, getType) {
  KeyboardEvents s;

  auto actual = s.getType();

  EXPECT_EQ(COMPONENT_TYPE_KEYBOARDABLE, actual);
}

*/
TEST(KeyboardEvents, onAddEntity) {
  const unsigned int EV_USER_MOVEMENT = 9999;
  aronnax::Vector2d up = { 0, -1 };
  aronnax::Vector2d down = { 0, 1 };
  aronnax::EvUserMovement* evUp = new aronnax::EvUserMovement(up);
  aronnax::EvUserMovement* evDown = new aronnax::EvUserMovement(down);
  map<string, aronnax::Ev*> keyMap;
  keyMap["A"] = evUp;
  keyMap["S"] = evDown;
  aronnax::EvKeyboard ev("A", aronnax::EvKeyState::STATE_UP);

  auto c = Keyboardable(EV_USER_MOVEMENT, keyMap);
  aronnax::Entity* e = new aronnax::Entity();
  e->addComponent(&c);<commit_msg>Finish tests for keyboard events<commit_after>
#include <map>
#include <string>

#include <gtest/gtest.h>

#include "../lib/entity.h"
#include "../lib/units.h"

#include "../c_keyboardable.h"
#include "../s_keyboard_events.h"

using namespace std;
using namespace spacegun;

TEST(Keyboardable, Constructor) {
  aronnax::Ev expected;
  unsigned int expectedCode = 32;
  map<string, aronnax::Ev*> keyMap;
  keyMap["testa"] = &expected;

  Keyboardable c = Keyboardable(expectedCode, keyMap);

  auto actual = c.getAction("testa");

  EXPECT_EQ(&expected, actual);
  EXPECT_EQ(c.getEventCode(), expectedCode);
}

TEST(Keyboardable, getType) {
  Keyboardable c(100);

  auto actual = c.getType();

  EXPECT_EQ(actual, COMPONENT_TYPE_KEYBOARDABLE);
}

TEST(Keyboardable, getKeys) {
  unsigned int expectedCode = 33;
  aronnax::Ev eva;
  aronnax::Ev evb;
  map<string, aronnax::Ev*> keyMap;
  string expectedA = "testa";
  string expectedB = "testb";
  keyMap[expectedA] = &eva;
  keyMap[expectedB] = &evb;

  Keyboardable c = Keyboardable(expectedCode, keyMap);

  // TODO do maps in c++ guarantee an order?
  auto actualA = c.getKeys().at(0);
  auto actualB = c.getKeys().at(1);

  EXPECT_EQ(expectedA, actualA);
  EXPECT_EQ(expectedB, actualB);
}

TEST(Keyboardable, getAction) {
  unsigned int expectedCode = 34;
  aronnax::Ev expectedA;
  aronnax::Ev expectedB;
  map<string, aronnax::Ev*> keyMap;
  keyMap["testa"] = &expectedA;
  keyMap["testb"] = &expectedB;

  Keyboardable c = Keyboardable(expectedCode, keyMap);

  auto actualA = c.getAction("testa");
  auto actualB = c.getAction("testb");

  EXPECT_EQ(&expectedA, actualA);
  EXPECT_EQ(&expectedB, actualB);
}

TEST(KeyboardEvents, getType) {
  KeyboardEvents<aronnax::Ev> s;

  auto actual = s.getType();

  EXPECT_EQ(COMPONENT_TYPE_KEYBOARDABLE, actual);
}


TEST(KeyboardEvents, onAddEntity) {
  const unsigned int EV_USER_MOVEMENT = 9999;
  aronnax::Vector2d up = { 0, -1 };
  aronnax::Vector2d down = { 0, 1 };
  aronnax::EvUserMovement* evUp = new aronnax::EvUserMovement(up);
  aronnax::EvUserMovement* evDown = new aronnax::EvUserMovement(down);
  map<string, aronnax::Ev*> keyMap;
  keyMap["A"] = evUp;
  keyMap["S"] = evDown;
  aronnax::EvKeyboard ev("A", aronnax::EvKeyState::STATE_UP);

  auto c = Keyboardable(EV_USER_MOVEMENT, keyMap);
  aronnax::Entity* e = new aronnax::Entity();
  e->addComponent(&c);
{'fraction_non_alphanumeric': 0.14971123944913373, 'fraction_numerical': 0.008440693025322079, 'mean_word_length': 4.964238410596026, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, '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': '2994734', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1688, 'n_words': 353}