<commit_before>﻿#include "stdafx.hpp"

#include <CppUnitTest.h>
#include <functional>

#include "Geometry/Grassmann.hpp"
#include "Geometry/R3Element.hpp"
#include "Quantities/Astronomy.hpp"
#include "Quantities/BIPM.hpp"
#include "Quantities/Constants.hpp"
#include "Quantities/Dimensionless.hpp"
#include "Quantities/ElementaryFunctions.hpp"
#include "Quantities/Quantities.hpp"
#include "Quantities/SI.hpp"
#include "Quantities/UK.hpp"
#include "TestUtilities/Algebra.hpp"
#include "TestUtilities/GeometryComparisons.hpp"
#include "TestUtilities/QuantityComparisons.hpp"
#include "TestUtilities/TestUtilities.hpp"

namespace principia {
namespace geometry {

using namespace astronomy;
using namespace bipm;
using namespace constants;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace quantities;
using namespace si;
using namespace test_utilities;
using namespace uk;

TEST_CLASS(GrassmannTests) {
 public:
  struct World;
  TEST_METHOD(SpecialOrthogonalLieAlgebra) {
    R3Element<Dimensionless> u(3, -42, 0);
    R3Element<Dimensionless> v(-π, -e, -1);
    R3Element<Dimensionless> w(2, 2, 2);
    R3Element<Dimensionless> a(1.2, 2.3, 3.4);
    TestLieBracket(Commutator<Dimensionless, Dimensionless, World>,
                   Bivector<Dimensionless, World>(u),
                   Bivector<Dimensionless, World>(v),
                   Bivector<Dimensionless, World>(w),
                   Bivector<Dimensionless, World>(a), Dimensionless(0.42));
  }

  TEST_METHOD(VectorSpaces) {
    R3Element<Length> nullDisplacement(0 * Metre, 0 * Metre, 0 * Metre);
    R3Element<Length> u(3 * Metre, -42 * Metre, 0 * Metre);
    R3Element<Length> v(-π * Metre, -e * Metre, -1 * Metre);
    R3Element<Length> w(2 * Metre, 2 * Metre, 2 * Metre);
    R3Element<Length> a(1 * Inch, 2 * Foot, 3 * admiralty::Fathom);
    {
      std::function<Area(Vector<Length, World>,
                         Vector<Length, World>)> vectorInnerProduct =
      [](Vector<Length, World> a, Vector<Length, World> b) {
        return InnerProduct(a, b);
      };
      std::function<Area(Bivector<Length, World>,
                         Bivector<Length, World>)> bivectorInnerProduct =
      [](Bivector<Length, World> a, Bivector<Length, World> b) {
        return InnerProduct(a, b);
      };
      std::function<Area(Trivector<Length, World>,
                         Trivector<Length, World>)> trivectorInnerProduct =
      [](Trivector<Length, World> a, Trivector<Length, World> b) {
        return InnerProduct(a, b);
      };
      TestInnerProductSpace(vectorInnerProduct,
                            Vector<Length, World>(nullDisplacement),
                            Vector<Length, World>(u), Vector<Length, World>(v),
                            Vector<Length, World>(w), Vector<Length, World>(a),
                            Dimensionless(0), Dimensionless(1), Sqrt(163),
                            -Sqrt(2));<commit_msg>Start testing mixed scalar multiplication of multivectors.<commit_after>﻿#include "stdafx.hpp"

#include <CppUnitTest.h>
#include <functional>

#include "Geometry/Grassmann.hpp"
#include "Geometry/R3Element.hpp"
#include "Quantities/Astronomy.hpp"
#include "Quantities/BIPM.hpp"
#include "Quantities/Constants.hpp"
#include "Quantities/Dimensionless.hpp"
#include "Quantities/ElementaryFunctions.hpp"
#include "Quantities/Quantities.hpp"
#include "Quantities/SI.hpp"
#include "Quantities/UK.hpp"
#include "TestUtilities/Algebra.hpp"
#include "TestUtilities/GeometryComparisons.hpp"
#include "TestUtilities/QuantityComparisons.hpp"
#include "TestUtilities/TestUtilities.hpp"

namespace principia {
namespace geometry {

using namespace astronomy;
using namespace bipm;
using namespace constants;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace quantities;
using namespace si;
using namespace test_utilities;
using namespace uk;

TEST_CLASS(GrassmannTests) {
 public:
  struct World;
  TEST_METHOD(SpecialOrthogonalLieAlgebra) {
    R3Element<Dimensionless> u(3, -42, 0);
    R3Element<Dimensionless> v(-π, -e, -1);
    R3Element<Dimensionless> w(2, 2, 2);
    R3Element<Dimensionless> a(1.2, 2.3, 3.4);
    TestLieBracket(Commutator<Dimensionless, Dimensionless, World>,
                   Bivector<Dimensionless, World>(u),
                   Bivector<Dimensionless, World>(v),
                   Bivector<Dimensionless, World>(w),
                   Bivector<Dimensionless, World>(a), Dimensionless(0.42));
  }

  TEST_METHOD(MixedScalarMultiplication) {
     R3Element<Speed> nullVector(0 * Metre / Second,
                                 0 * Metre / Second,
                                 0 * Metre / Second);
     R3Element<Speed> u(1 * Metre / Second,
                        120 * Kilo(Metre) / Hour,
                        -SpeedOfLight);
     R3Element<Speed> v(-20 * Knot,
                        2 * π * AstronomicalUnit / JulianYear,
                        1 * admiralty::NauticalMile / Hour);
     R3Element<Speed> w(-1 * Mile / Hour, -2 * Foot / Second, -3 * Knot);
     R3Element<Speed> a(88 * Mile / Hour, 300 * Metre / Second, 46 * Knot);

     auto vectorLeftTimeMultiplication = [](Time left,
                                            Vector<Speed, World> right) {
       return left * right;
     };
     auto vectorRightTimeMultiplication = [](Vector<Speed, World> left,
                                             Time right) {
       return left * right;
     };
     auto bivectorLeftTimeMultiplication = [](Time left,
                                              Bivector<Speed, World> right) {
       return left * right;
     };
     auto bivectorRightTimeMultiplication = [](Bivector<Speed, World> left,
                                               Time right) {
       return left * right;
     };
     auto trivectorLeftTimeMultiplication = [](Time left,
                                               Trivector<Speed, World> right) {
       return left * right;
     };
     auto trivectorRightTimeMultiplication = [](Trivector<Speed, World> left,
                                                Time right) {
       return left * right;
     };

     TestBilinearMap(vectorLeftTimeMultiplication, 1 * Second, 1 * JulianYear,
                     Vector<Speed, World>(u), Vector<Speed, World>(v),
                     Dimensionless(42));
     TestBilinearMap(vectorRightTimeMultiplication, Vector<Speed, World>(w),
                     Vector<Speed, World>(a), -1 * Day,
                     1 * Parsec / SpeedOfLight, Dimensionless(-π));
     Time t = -3 * Second;
     AssertEqual(t * Vector<Speed, World>(u), Vector<Speed, World>(u) * t);
     AssertEqual((Vector<Speed, World>(u) * t) / t, Vector<Speed, World>(u));
  }

  TEST_METHOD(VectorSpaces) {
    R3Element<Length> nullDisplacement(0 * Metre, 0 * Metre, 0 * Metre);
    R3Element<Length> u(3 * Metre, -42 * Metre, 0 * Metre);
    R3Element<Length> v(-π * Metre, -e * Metre, -1 * Metre);
    R3Element<Length> w(2 * Metre, 2 * Metre, 2 * Metre);
    R3Element<Length> a(1 * Inch, 2 * Foot, 3 * admiralty::Fathom);
    {
      std::function<Area(Vector<Length, World>,
                         Vector<Length, World>)> vectorInnerProduct =
      [](Vector<Length, World> a, Vector<Length, World> b) {
        return InnerProduct(a, b);
      };
      std::function<Area(Bivector<Length, World>,
                         Bivector<Length, World>)> bivectorInnerProduct =
      [](Bivector<Length, World> a, Bivector<Length, World> b) {
        return InnerProduct(a, b);
      };
      std::function<Area(Trivector<Length, World>,
                         Trivector<Length, World>)> trivectorInnerProduct =
      [](Trivector<Length, World> a, Trivector<Length, World> b) {
        return InnerProduct(a, b);
      };
      TestInnerProductSpace(vectorInnerProduct,
                            Vector<Length, World>(nullDisplacement),
                            Vector<Length, World>(u), Vector<Length, World>(v),
                            Vector<Length, World>(w), Vector<Length, World>(a),
                            Dimensionless(0), Dimensionless(1), Sqrt(163),
                            -Sqrt(2));
{'fraction_non_alphanumeric': 0.12279843444227005, 'fraction_numerical': 0.015533268101761252, 'mean_word_length': 2.542894280762565, 'pattern_counts': {'":': 0, '<': 94, '<?xml version=': 0, '>': 94, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4205600', 'n_tokens_mistral': 2507, 'n_tokens_neox': 2425, 'n_words': 525}