<commit_before>/*

    Copyright <NAME> and <NAME>, 2011, 2012, 2013

    This file is part of Lasercake.

    Lasercake is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Lasercake is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Lasercake.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "test_header.hpp"

#include "../units.hpp"

#include <iostream>

typedef UNITS(meters) meter;
constexpr auto kilograms = kilo*grams;

typedef typename units_prod<kilo_t, grams_t>::type kilograms_t;
typedef typename units_prod<kilograms_t, meters_t,
  typename seconds_t::units_pow<-2>::type>::type newtons_t_A;
typedef typename units_prod<kilograms_t, meters_t, seconds_t::units_pow<-2>
  >::type newtons_t_B;

typedef typename units_prod<kilo_t, meters_t>::type kilometers_t;
typedef typename kilometers_t::units_pow<6>::type kilometers6_t;
typedef typename kilometers6_t::units_pow<-2, 3>::type inverse_kilometers4_t;
typedef typename meters_t::units_pow<-4>::type inverse_meters4_t;

constexpr auto kilometers = kilometers_t();

BOOST_AUTO_TEST_CASE( unitses ) {
  const unit<int32_t, meter> foo = 1 * meter();
  const unit<int64_t, meter> foo64 = foo;
  const unit<int32_t, meter> foo3 = 3 * meter();
  const unit<int32_t, meter> foo5 = 5 * meters;
  foo + foo;
  auto bfoo = foo * foo;
  bfoo = bfoo * 3;

  foo64 + foo;

  // TODO consider whether to relax bounds_checked_int to make this work,
  // or provide conversion functions, or such.
  // const unit<double, meter> foofloating = foo;
  // Also this doesn't work because unit<> tries to wrap
  // its data type in a bounds checked int, heh.  That'd
  // be fairly easy to fix for floating point.
  // const unit<double, meter> foofloating = 1.0*meters;

  // Deliberately avoid get_primitive_int() to make sure
  // that it is returning the correct type in both cases.
#if USE_BOUNDS_CHECKED_INTS
  int yay = (bfoo / foo / foo).get();
#else
  int yay = (bfoo / foo / foo);
#endif
  const typename lasercake_int<int32_t>::type okayy1 = get(bfoo, meters*meters);
  const typename lasercake_int<int32_t>::type okayy2 = bfoo.get(meters*meters);
  BOOST_CHECK_EQUAL(okayy1, okayy2);

  meters*meters;
  units<dim::meter<2>> foofoo = meters*meters;
  meters/seconds;
  units<> dimless = meters/meters;
  2*dimless;
  2*(meters/meters);
  2*(meters*meters);
  ((2*meters)*meters) + (2*(meters*meters));

  1*meters*meters + 1*meters.pow<2>();

  // 1000*1000*1000*1000 doesn't fit into 32 bits, so this identity()
  // returns a 64 bit quantity.
  const unit<int64_t, inverse_kilometers4_t> invfoo4 = 1/foo/foo/foo/foo
    * identity(inverse_kilometers4_t() / inverse_meters4_t());
  // This fits within fewer bits:
  const unit<int32_t, meters_t> thirtytwobits = 1 * kilometers * identity(meters / kilometers);

  const unit<int, newtons_t_A> newtonz = 7 * kilograms * meters / seconds / seconds;
  newtonz + 1*newtons_t_B();

  auto scalar = 4*meters;
  auto pseudoscalar = scalar*pseudo;
  scalar = pseudoscalar * pseudo;
  scalar = pseudoscalar / pseudo;
  pseudoscalar = scalar * pseudo;
  pseudoscalar = scalar / pseudo;
  pseudoscalar = pseudoscalar + pseudoscalar;

  1*pseudo + sign(pseudoscalar);
  1 + sign(scalar);

  scalar = imbue_sign(scalar, scalar);
  pseudoscalar = imbue_sign(scalar, pseudoscalar);
  pseudoscalar = imbue_sign(pseudoscalar, scalar);
  scalar = imbue_sign(pseudoscalar, pseudoscalar);

  std::cerr << (yay * foofoo * invfoo4 * thirtytwobits) << '\n';

  BOOST_CHECK_EQUAL(foo5 + foo3, 8*meters);<commit_msg>units: fix unused result warning in tests<commit_after>/*

    Copyright <NAME> and <NAME>, 2011, 2012, 2013

    This file is part of Lasercake.

    Lasercake is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Lasercake is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Lasercake.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "test_header.hpp"

#include "../units.hpp"

#include <iostream>

typedef UNITS(meters) meter;
constexpr auto kilograms = kilo*grams;

typedef typename units_prod<kilo_t, grams_t>::type kilograms_t;
typedef typename units_prod<kilograms_t, meters_t,
  typename seconds_t::units_pow<-2>::type>::type newtons_t_A;
typedef typename units_prod<kilograms_t, meters_t, seconds_t::units_pow<-2>
  >::type newtons_t_B;

typedef typename units_prod<kilo_t, meters_t>::type kilometers_t;
typedef typename kilometers_t::units_pow<6>::type kilometers6_t;
typedef typename kilometers6_t::units_pow<-2, 3>::type inverse_kilometers4_t;
typedef typename meters_t::units_pow<-4>::type inverse_meters4_t;

constexpr auto kilometers = kilometers_t();

BOOST_AUTO_TEST_CASE( unitses ) {
  const unit<int32_t, meter> foo = 1 * meter();
  const unit<int64_t, meter> foo64 = foo;
  const unit<int32_t, meter> foo3 = 3 * meter();
  const unit<int32_t, meter> foo5 = 5 * meters;
  foo + foo;
  auto bfoo = foo * foo;
  bfoo = bfoo * 3;

  foo64 + foo;

  // TODO consider whether to relax bounds_checked_int to make this work,
  // or provide conversion functions, or such.
  // const unit<double, meter> foofloating = foo;
  // Also this doesn't work because unit<> tries to wrap
  // its data type in a bounds checked int, heh.  That'd
  // be fairly easy to fix for floating point.
  // const unit<double, meter> foofloating = 1.0*meters;

  // Deliberately avoid get_primitive_int() to make sure
  // that it is returning the correct type in both cases.
#if USE_BOUNDS_CHECKED_INTS
  int yay = (bfoo / foo / foo).get();
#else
  int yay = (bfoo / foo / foo);
#endif
  const typename lasercake_int<int32_t>::type okayy1 = get(bfoo, meters*meters);
  const typename lasercake_int<int32_t>::type okayy2 = bfoo.get(meters*meters);
  BOOST_CHECK_EQUAL(okayy1, okayy2);

  meters*meters;
  units<dim::meter<2>> foofoo = meters*meters;
  meters/seconds;
  units<> dimless = meters/meters;
  2*dimless;
  2*(meters/meters);
  2*(meters*meters);
  ((2*meters)*meters) + (2*(meters*meters));

  1*meters*meters + 1*meters.pow<2>();

  // 1000*1000*1000*1000 doesn't fit into 32 bits, so this identity()
  // returns a 64 bit quantity.
  const unit<int64_t, inverse_kilometers4_t> invfoo4 = 1/foo/foo/foo/foo
    * identity(inverse_kilometers4_t() / inverse_meters4_t());
  // This fits within fewer bits:
  const unit<int32_t, meters_t> thirtytwobits = 1 * kilometers * identity(meters / kilometers);

  const unit<int, newtons_t_A> newtonz = 7 * kilograms * meters / seconds / seconds;
  newtonz + 1*newtons_t_B();

  auto scalar = 4*meters;
  auto pseudoscalar = scalar*pseudo;
  scalar = pseudoscalar * pseudo;
  scalar = pseudoscalar / pseudo;
  pseudoscalar = scalar * pseudo;
  pseudoscalar = scalar / pseudo;
  pseudoscalar = pseudoscalar + pseudoscalar;

  1*pseudo + sign(pseudoscalar);
  auto useded = 1 + sign(scalar);

  scalar = imbue_sign(scalar, scalar);
  pseudoscalar = imbue_sign(scalar, pseudoscalar);
  pseudoscalar = imbue_sign(pseudoscalar, scalar);
  scalar = imbue_sign(pseudoscalar, pseudoscalar);

  std::cerr << (yay * foofoo * invfoo4 * thirtytwobits * useded) << '\n';

  BOOST_CHECK_EQUAL(foo5 + foo3, 8*meters);
{'fraction_non_alphanumeric': 0.10821316614420062, 'fraction_numerical': 0.02482758620689655, 'mean_word_length': 4.289124668435013, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5135316', 'n_tokens_mistral': 2934, 'n_tokens_neox': 2642, 'n_words': 812}