<commit_before>#include "SSDMetric3rdPartyComponent.h"
#include "GDOptimizer3rdPartyComponent.h"
#include "SSDMetric4thPartyComponent.h"
#include "GDOptimizer4thPartyComponent.h"

#include "gtest/gtest.h"

namespace elx {

class InterfaceTest : public ::testing::Test {
public:

  virtual void SetUp() {
    metric3p = new SSDMetric3rdPartyComponent();
    optimizer3p = new GDOptimizer3rdPartyComponent();

    metric4p = new SSDMetric4thPartyComponent();
    optimizer4p = new GDOptimizer4thPartyComponent();
  }

  virtual void TearDown() {
    delete metric3p;
    delete optimizer3p;
    delete metric4p;
    delete optimizer4p;
  }
  // types as if returned by our component factory
  ComponentBase* metric3p;
  ComponentBase* optimizer3p;
  ComponentBase* metric4p;
  ComponentBase* optimizer4p;

};

TEST_F( InterfaceTest, InterfaceNameTraits )
{
  EXPECT_STREQ(InterfaceName<MetricValueInterface>::Get(), "MetricValueInterface");
  EXPECT_STREQ(InterfaceName<InterfaceAcceptor<MetricValueInterface> >::Get(), "MetricValueInterface");
}

TEST_F( InterfaceTest, DynamicCast )
{
  int returnval;
  //metric3p should have a MetricValueInterface
  MetricValueInterface* valueIF = dynamic_cast<MetricValueInterface*> (metric3p);
  ASSERT_NE(valueIF, nullptr);
  EXPECT_NO_THROW(returnval = valueIF->GetValue());

  //metric3p should have a MetricDerivativeInterface
  MetricDerivativeInterface* derivativeIF = dynamic_cast<MetricDerivativeInterface*> (metric3p);
  ASSERT_NE(derivativeIF, nullptr);
  EXPECT_NO_THROW(returnval = derivativeIF->GetDerivative());

  //optimizer3p should have a OptimizerUpdateInterface
  OptimizerUpdateInterface* updateIF = dynamic_cast<OptimizerUpdateInterface*> (optimizer3p);
  ASSERT_NE(updateIF, nullptr);
  EXPECT_NO_THROW(returnval = updateIF->Update());

  //optimizer3p should have a InterfaceAcceptor<MetricValueInterface> 
  InterfaceAcceptor<MetricValueInterface>* valueAcceptorIF = dynamic_cast<InterfaceAcceptor<MetricValueInterface>*> (optimizer3p);
  ASSERT_NE(valueAcceptorIF, nullptr);

  //optimizer3p should have a InterfaceAcceptor<MetricDerivativeInterface> 
  InterfaceAcceptor<MetricDerivativeInterface>* derivativeAcceptorIF = dynamic_cast<InterfaceAcceptor<MetricDerivativeInterface>*> (optimizer3p);
  ASSERT_NE(derivativeAcceptorIF, nullptr);
  
}

TEST_F( InterfaceTest, ComponentConnecting )
{
  interfaceStatus IFstatus;
  EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricValueInterface", metric3p));
  EXPECT_EQ(IFstatus, interfaceStatus::success);

  EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricValueInterface", metric4p));
  EXPECT_EQ(IFstatus, interfaceStatus::success);

  EXPECT_NO_THROW(IFstatus = optimizer4p->ConnectFrom("MetricValueInterface", metric3p));
  EXPECT_EQ(IFstatus, interfaceStatus::success);

  EXPECT_NO_THROW(IFstatus = optimizer4p->ConnectFrom("MetricValueInterface", metric4p));
  EXPECT_EQ(IFstatus, interfaceStatus::success);


  EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricDerivativeInterface", metric3p));
  EXPECT_EQ(IFstatus, interfaceStatus::success);

  EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricDerivativeInterface", metric4p));
  EXPECT_EQ(IFstatus, interfaceStatus::noprovider);

  EXPECT_NO_THROW(IFstatus = optimizer4p->ConnectFrom("MetricDerivativeInterface", metric3p));
  EXPECT_EQ(IFstatus, interfaceStatus::noaccepter);

}
} // namespace elx
<commit_msg>FIX: some tests<commit_after>#include "SSDMetric3rdPartyComponent.h"
#include "GDOptimizer3rdPartyComponent.h"
#include "SSDMetric4thPartyComponent.h"
#include "GDOptimizer4thPartyComponent.h"

#include "gtest/gtest.h"

namespace elx {

class InterfaceTest : public ::testing::Test {
public:

  virtual void SetUp() {
    metric3p = new SSDMetric3rdPartyComponent();
    optimizer3p = new GDOptimizer3rdPartyComponent();

    metric4p = new SSDMetric4thPartyComponent();
    optimizer4p = new GDOptimizer4thPartyComponent();
  }

  virtual void TearDown() {
    delete metric3p;
    delete optimizer3p;
    delete metric4p;
    delete optimizer4p;
  }
  // types as if returned by our component factory
  ComponentBase* metric3p;
  ComponentBase* optimizer3p;
  ComponentBase* metric4p;
  ComponentBase* optimizer4p;

};

TEST_F( InterfaceTest, InterfaceNameTraits )
{
  EXPECT_STREQ(InterfaceName<MetricValueInterface>::Get(), "MetricValueInterface");
  EXPECT_STREQ(InterfaceName<InterfaceAcceptor<MetricValueInterface> >::Get(), "MetricValueInterface");
}

TEST_F( InterfaceTest, DynamicCast )
{
  int returnval;
  //metric3p should have a MetricValueInterface
  MetricValueInterface* valueIF = dynamic_cast<MetricValueInterface*> (metric3p);
  ASSERT_NE(valueIF, nullptr);
  EXPECT_NO_THROW(returnval = valueIF->GetValue());

  //metric3p should have a MetricDerivativeInterface
  MetricDerivativeInterface* derivativeIF = dynamic_cast<MetricDerivativeInterface*> (metric3p);
  ASSERT_NE(derivativeIF, nullptr);
  EXPECT_NO_THROW(returnval = derivativeIF->GetDerivative());

  //optimizer3p should have a OptimizerUpdateInterface
  OptimizerUpdateInterface* updateIF = dynamic_cast<OptimizerUpdateInterface*> (optimizer3p);
  ASSERT_NE(updateIF, nullptr);
  //EXPECT_NO_THROW(returnval = updateIF->Update()); // Update can only be called if metric and optimizer are connected

  //optimizer3p should have a InterfaceAcceptor<MetricValueInterface> 
  InterfaceAcceptor<MetricValueInterface>* valueAcceptorIF = dynamic_cast<InterfaceAcceptor<MetricValueInterface>*> (optimizer3p);
  ASSERT_NE(valueAcceptorIF, nullptr);

  //optimizer3p should have a InterfaceAcceptor<MetricDerivativeInterface> 
  InterfaceAcceptor<MetricDerivativeInterface>* derivativeAcceptorIF = dynamic_cast<InterfaceAcceptor<MetricDerivativeInterface>*> (optimizer3p);
  ASSERT_NE(derivativeAcceptorIF, nullptr);
  
}

TEST_F( InterfaceTest, ConnectByName )
{
  interfaceStatus IFstatus;
  EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricValueInterface", metric3p));
  EXPECT_EQ(IFstatus, interfaceStatus::success);

  EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricValueInterface", metric4p));
  EXPECT_EQ(IFstatus, interfaceStatus::success);

  EXPECT_NO_THROW(IFstatus = optimizer4p->ConnectFrom("MetricValueInterface", metric3p));
  EXPECT_EQ(IFstatus, interfaceStatus::success);

  EXPECT_NO_THROW(IFstatus = optimizer4p->ConnectFrom("MetricValueInterface", metric4p));
  EXPECT_EQ(IFstatus, interfaceStatus::success);


  EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricDerivativeInterface", metric3p));
  EXPECT_EQ(IFstatus, interfaceStatus::success);

  EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricDerivativeInterface", metric4p));
  EXPECT_EQ(IFstatus, interfaceStatus::noprovider);

  EXPECT_NO_THROW(IFstatus = optimizer4p->ConnectFrom("MetricDerivativeInterface", metric3p));
  EXPECT_EQ(IFstatus, interfaceStatus::noaccepter);

}

TEST_F(InterfaceTest, ConnectAll)
{
  int connectionCount = 0;
  EXPECT_NO_THROW(connectionCount = optimizer3p->ConnectFrom(metric3p));
  EXPECT_EQ(connectionCount, 2); // both MetricValueInterface and MetricDerivativeInterface are connected

  EXPECT_NO_THROW(connectionCount = optimizer3p->ConnectFrom(metric4p));
  EXPECT_EQ(connectionCount, 1); // only MetricValueInterface is connected

  EXPECT_NO_THROW(connectionCount = optimizer4p->ConnectFrom(metric3p));
  EXPECT_EQ(connectionCount, 1); // only MetricValueInterface is connected

  EXPECT_NO_THROW(connectionCount = optimizer4p->ConnectFrom(metric4p));
  EXPECT_EQ(connectionCount, 1); // only MetricValueInterface is connected


  EXPECT_NO_THROW(connectionCount = metric4p->ConnectFrom(optimizer4p));
  EXPECT_EQ(connectionCount, 0); // cannot connect in this direction
}

} // namespace elx

{'fraction_non_alphanumeric': 0.09914794732765299, 'fraction_numerical': 0.013426284533953009, 'mean_word_length': 7.513186813186813, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 56, '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': '4927460', 'n_tokens_mistral': 2437, 'n_tokens_neox': 2392, 'n_words': 412}