<commit_before>#include<iostream>
#include<cassert>
#include<thread>
#include<chrono>

#include "ics3/ics"

void testAngle();
void testEepParam();
void testID();
void testParameter();
void testICS3();

int main(int argc, char **argv) {
  testAngle();
  testEepParam();
  testID();
  testParameter();
  testICS3();
  return 0;
}

void testAngle() {
  std::cout << std::endl << "angle test section" << std::endl;
  // constexpr test
  constexpr auto degree1 = ics::Angle::newDegree(90);
  constexpr auto radian1 = ics::Angle::newRadian(M_PI / 2);
  static_assert(degree1.getRaw() == radian1.getRaw(), "angles 1 error");
  constexpr auto degree2 = ics::Angle::newDegree(30);
  constexpr auto radian2 = ics::Angle::newRadian(M_PI / 6);
  static_assert(degree2.getRaw() == radian2.getRaw(), "angles 2 error");
  try {
    ics::Angle::newDegree(136);
    assert(false);
  } catch (std::invalid_argument& e) {
    std::cout << e.what() << std::endl;
  }

  // runtime test
  auto degree = ics::Angle::newDegree();
  auto radian = ics::Angle::newRadian();
  assert(degree.getRaw() == radian.getRaw());
  degree.set(0);
  radian.set(0);
  assert(degree.getRaw() == radian.getRaw());
  degree.set(90);
  radian.set(M_PI / 2);
  assert(degree.getRaw() == radian.getRaw());
  degree.set(-60);
  radian.set(-M_PI / 3);
  assert(degree.getRaw() == radian.getRaw());
  try {
    degree.set(150);
    assert(false);
  } catch (std::invalid_argument& e) {
    std::cout << e.what() << std::endl;
  }
  try {
    radian.set(M_PI);
    assert(false);
  } catch (std::invalid_argument& e) {
    std::cout << e.what() << std::endl;
  }
}

void testEepParam() {
  std::cout << std::endl << "EepParam test section" << std::endl;
  // constexpr test
  constexpr auto current = ics::EepParam::current();
  static_assert(63 == current.get(), "current error");
  constexpr auto strech = ics::EepParam::strech(244);
  static_assert(244 == strech.get(), "strech error");
  try {
    ics::EepParam::flag(10);
    assert(false);
  } catch (std::invalid_argument& e) {
    std::cout << e.what() << std::endl;
  }<commit_msg>Add testcode for baudrate<commit_after>#include<iostream>
#include<cassert>
#include<thread>
#include<chrono>

#include "ics3/ics"

void testAngle();
void testBaudrate();
void testEepParam();
void testID();
void testParameter();
void testICS3();

int main(int argc, char **argv) {
  testAngle();
  testBaudrate();
  testEepParam();
  testID();
  testParameter();
  testICS3();
  return 0;
}

void testAngle() {
  std::cout << std::endl << "angle test section" << std::endl;
  // constexpr test
  constexpr auto degree1 = ics::Angle::newDegree(90);
  constexpr auto radian1 = ics::Angle::newRadian(M_PI / 2);
  static_assert(degree1.getRaw() == radian1.getRaw(), "angles 1 error");
  constexpr auto degree2 = ics::Angle::newDegree(30);
  constexpr auto radian2 = ics::Angle::newRadian(M_PI / 6);
  static_assert(degree2.getRaw() == radian2.getRaw(), "angles 2 error");
  try {
    ics::Angle::newDegree(136);
    assert(false);
  } catch (std::invalid_argument& e) {
    std::cout << e.what() << std::endl;
  }

  // runtime test
  auto degree = ics::Angle::newDegree();
  auto radian = ics::Angle::newRadian();
  assert(degree.getRaw() == radian.getRaw());
  degree.set(0);
  radian.set(0);
  assert(degree.getRaw() == radian.getRaw());
  degree.set(90);
  radian.set(M_PI / 2);
  assert(degree.getRaw() == radian.getRaw());
  degree.set(-60);
  radian.set(-M_PI / 3);
  assert(degree.getRaw() == radian.getRaw());
  try {
    degree.set(150);
    assert(false);
  } catch (std::invalid_argument& e) {
    std::cout << e.what() << std::endl;
  }
  try {
    radian.set(M_PI);
    assert(false);
  } catch (std::invalid_argument& e) {
    std::cout << e.what() << std::endl;
  }
}

void testBaudrate() {
  std::cout << std::endl << "Baudrate test section" << std::endl;
  // constexpr test
  constexpr auto baudrate115200 = ics::Baudrate::RATE115200();
  constexpr struct {
    static constexpr speed_t speed(speed_t baudrate, speed_t value) {
      return baudrate != value ? throw std::invalid_argument {"Baudrate: speed error"} : baudrate;
    }
    static constexpr uint16_t romdata(uint16_t baudrate, uint16_t value) {
      return baudrate != value ? throw std::invalid_argument {"Baudrate: romdata error"} : baudrate;
    }
  } checker;
  checker.speed(baudrate115200, B115200);
  checker.romdata(baudrate115200, 10);
  static_assert(static_cast<uint16_t>(baudrate115200) == 10, "Baudrate: not equal 10");
  static_assert(static_cast<speed_t>(baudrate115200) == B115200, "Baudrate: not equal B115200");
}

void testEepParam() {
  std::cout << std::endl << "EepParam test section" << std::endl;
  // constexpr test
  constexpr auto current = ics::EepParam::current();
  static_assert(63 == current.get(), "current error");
  constexpr auto strech = ics::EepParam::strech(244);
  static_assert(244 == strech.get(), "strech error");
  try {
    ics::EepParam::flag(10);
    assert(false);
  } catch (std::invalid_argument& e) {
    std::cout << e.what() << std::endl;
  }
{'fraction_non_alphanumeric': 0.18160284247927358, 'fraction_numerical': 0.030793525463876825, 'mean_word_length': 4.448387096774193, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 13, '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': '172377', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1834, 'n_words': 375}