<commit_before>//---------------------------------------------------------------------------//
/*! 
 * \file tstBasicEntityPredicates.cpp
 * \author <NAME>
 * \brief BasicEntityPredicates unit tests.
 */
//---------------------------------------------------------------------------//

#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <algorithm>
#include <cassert>

#include <DTK_BasicEntityPredicates.hpp>
#include <DTK_PredicateComposition.hpp>
#include <DTK_Point.hpp>

#include <Teuchos_UnitTestHarness.hpp>
#include <Teuchos_DefaultComm.hpp>
#include <Teuchos_RCP.hpp>
#include <Teuchos_Array.hpp>
#include <Teuchos_OpaqueWrapper.hpp>
#include <Teuchos_TypeTraits.hpp>
#include <Teuchos_OrdinalTraits.hpp>
#include <Teuchos_ParameterList.hpp>

//---------------------------------------------------------------------------//
// Tests
//---------------------------------------------------------------------------//
TEUCHOS_UNIT_TEST( BlockPredicate, block_predicate_test )
{
    using namespace DataTransferKit;

    Teuchos::Array<double> coords1(1,0.0);
    Teuchos::Array<int> blocks1(1,2);
    Teuchos::Array<int> boundaries1(0);
    Entity p1 = Point( 0, 0, coords1, blocks1, boundaries1 );

    Teuchos::Array<double> coords2(2,0.0);
    Teuchos::Array<int> blocks2(1,1);
    Teuchos::Array<int> boundaries2(0);
    Entity p2 = Point( 0, 0, coords2, blocks2, boundaries2 );

    Teuchos::Array<int> pred_1(1,1);
    BlockPredicate block_pred_1( pred_1 );
    TEST_ASSERT( !block_pred_1(p1) );
    TEST_ASSERT( block_pred_1(p2) );

    Teuchos::Array<int> pred_2(1,2);
    BlockPredicate block_pred_2( pred_2 );
    TEST_ASSERT( block_pred_2(p1) );
    TEST_ASSERT( !block_pred_2(p2) );

    Teuchos::Array<int> pred_3(2);
    pred_3[0] = 1;
    pred_3[1] = 2;
    BlockPredicate block_pred_3( pred_3 );
    TEST_ASSERT( block_pred_3(p1) );
    TEST_ASSERT( block_pred_3(p2) );

    std::function<bool(Entity)> block_pred_4 =
	PredicateComposition::And( block_pred_1.getFunction(), 
				   block_pred_2.getFunction() );
    TEST_ASSERT( !block_pred_4(p1) );
    TEST_ASSERT( !block_pred_4(p2) );

    std::function<bool(Entity)> block_pred_5 =
	PredicateComposition::Or( block_pred_1.getFunction(), 
				  block_pred_2.getFunction() );
    TEST_ASSERT( block_pred_5(p1) );
    TEST_ASSERT( block_pred_5(p2) );
}

//---------------------------------------------------------------------------//
TEUCHOS_UNIT_TEST( BoundPredicate, bound_predicate_test )
{
    using namespace DataTransferKit;

    Teuchos::Array<double> coords1(1,0.0);
    Teuchos::Array<int> bounds1(0);
    Teuchos::Array<int> boundaries1(1,2);
    Entity p1 = Point( 0, 0, coords1, bounds1, boundaries1 );

    Teuchos::Array<double> coords2(2,0.0);
    Teuchos::Array<int> bounds2(0);
    Teuchos::Array<int> boundaries2(1,1);
    Entity p2 = Point( 0, 0, coords2, bounds2, boundaries2 );

    Teuchos::Array<int> pred_1(1,1);
    BoundaryPredicate bound_pred_1( pred_1 );
    TEST_ASSERT( !bound_pred_1(p1) );
    TEST_ASSERT( bound_pred_1(p2) );<commit_msg>cleaning up basic entity predicates test<commit_after>//---------------------------------------------------------------------------//
/*! 
 * \file tstBasicEntityPredicates.cpp
 * \author Stuart <NAME>
 * \brief BasicEntityPredicates unit tests.
 */
//---------------------------------------------------------------------------//

#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <algorithm>
#include <cassert>

#include <DTK_BasicEntityPredicates.hpp>
#include <DTK_PredicateComposition.hpp>
#include <DTK_Entity.hpp>
#include <DTK_EntityImpl.hpp>

#include <Teuchos_UnitTestHarness.hpp>
#include <Teuchos_DefaultComm.hpp>
#include <Teuchos_RCP.hpp>
#include <Teuchos_Array.hpp>
#include <Teuchos_OpaqueWrapper.hpp>
#include <Teuchos_TypeTraits.hpp>
#include <Teuchos_OrdinalTraits.hpp>
#include <Teuchos_ParameterList.hpp>

//---------------------------------------------------------------------------//
// Basic entity implementation
//---------------------------------------------------------------------------//
class MyEntityImpl : public DataTransferKit::EntityImpl
{
  public:
    MyEntityImpl() { /* ... */ }
    MyEntityImpl( const Teuchos::Array<int>& block_ids,
		  const Teuchos::Array<int>& boundary_ids )
	: d_block_ids( block_ids )
	, d_boundary_ids( boundary_ids )
    {
	std::sort( d_block_ids.begin(), d_block_ids.end() );
	std::sort( d_boundary_ids.begin(), d_boundary_ids.end() );
    }
    ~MyEntityImpl() { /* ... */ }
    DataTransferKit::EntityType entityType() const 
    { return DataTransferKit::ENTITY_TYPE_NODE; }
    DataTransferKit::EntityId id() const { return 0; }
    int ownerRank() const { return 0; }
    int physicalDimension() const { return 0; }
    void boundingBox( Teuchos::Tuple<double,6>& bounds ) { }
    bool inBlock( const int block_id ) const
    {
	return std::binary_search( 
	    d_block_ids.begin(), d_block_ids.end(), block_id );
    }
    bool onBoundary( const int boundary_id ) const
    {
	return std::binary_search( 
	    d_boundary_ids.begin(), d_boundary_ids.end(), boundary_id );
    }
  private:
    Teuchos::Array<int> d_block_ids;
    Teuchos::Array<int> d_boundary_ids;
};

class MyEntity : public DataTransferKit::Entity
{
  public:
    MyEntity() { /* ... */ }
    MyEntity( const Teuchos::Array<int>& block_ids = Teuchos::Array<int>(0),
	      const Teuchos::Array<int>& boundary_ids = Teuchos::Array<int>(0) )
    {
	this->b_entity_impl = 
	    Teuchos::rcp( new MyEntityImpl(block_ids,boundary_ids) );
    }
    ~MyEntity() { /* ... */ }
};

//---------------------------------------------------------------------------//
// Tests
//---------------------------------------------------------------------------//
TEUCHOS_UNIT_TEST( BlockPredicate, block_predicate_test )
{
    using namespace DataTransferKit;

    Teuchos::Array<int> blocks1(1,2);
    Teuchos::Array<int> boundaries1(0);
    Entity p1 = MyEntity( blocks1, boundaries1 );

    Teuchos::Array<int> blocks2(1,1);
    Teuchos::Array<int> boundaries2(0);
    Entity p2 = MyEntity( blocks2, boundaries2 );

    Teuchos::Array<int> pred_1(1,1);
    BlockPredicate block_pred_1( pred_1 );
    TEST_ASSERT( !block_pred_1(p1) );
    TEST_ASSERT( block_pred_1(p2) );

    Teuchos::Array<int> pred_2(1,2);
    BlockPredicate block_pred_2( pred_2 );
    TEST_ASSERT( block_pred_2(p1) );
    TEST_ASSERT( !block_pred_2(p2) );

    Teuchos::Array<int> pred_3(2);
    pred_3[0] = 1;
    pred_3[1] = 2;
    BlockPredicate block_pred_3( pred_3 );
    TEST_ASSERT( block_pred_3(p1) );
    TEST_ASSERT( block_pred_3(p2) );

    std::function<bool(Entity)> block_pred_4 =
	PredicateComposition::And( block_pred_1.getFunction(), 
				   block_pred_2.getFunction() );
    TEST_ASSERT( !block_pred_4(p1) );
    TEST_ASSERT( !block_pred_4(p2) );

    std::function<bool(Entity)> block_pred_5 =
	PredicateComposition::Or( block_pred_1.getFunction(), 
				  block_pred_2.getFunction() );
    TEST_ASSERT( block_pred_5(p1) );
    TEST_ASSERT( block_pred_5(p2) );
}

//---------------------------------------------------------------------------//
TEUCHOS_UNIT_TEST( BoundPredicate, bound_predicate_test )
{
    using namespace DataTransferKit;

    Teuchos::Array<int> bounds1(0);
    Teuchos::Array<int> boundaries1(1,2);
    Entity p1 = MyEntity( bounds1, boundaries1 );

    Teuchos::Array<int> bounds2(0);
    Teuchos::Array<int> boundaries2(1,1);
    Entity p2 = MyEntity( bounds2, boundaries2 );

    Teuchos::Array<int> pred_1(1,1);
    BoundaryPredicate bound_pred_1( pred_1 );
    TEST_ASSERT( !bound_pred_1(p1) );
    TEST_ASSERT( bound_pred_1(p2) );
{'fraction_non_alphanumeric': 0.24484502658539747, 'fraction_numerical': 0.026974452081442096, 'mean_word_length': 2.5869767441860465, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 84, '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': '5895558', 'n_tokens_mistral': 2657, 'n_tokens_neox': 2580, 'n_words': 430}