KiCad PCB EDA Suite
test_array_options.cpp File Reference

Test suite for ARRAY_OPTIONS. More...

Go to the source code of this file.

Classes

struct  GRID_ARRAY_GEOM_PARAMS
 Declare the test suite. More...
 
struct  GRID_ARRAY_TEST_CASE
 
struct  CIRC_ARRAY_GEOM_PARAMS
 
struct  CIRC_ARRAY_TEST_CASE
 
struct  GRID_ARRAY_NAMING_PARAMS
 
struct  GRID_ARRAY_NAMING_CASE
 

Functions

std::ostream & operator<< (std::ostream &os, const ARRAY_OPTIONS::TRANSFORM &aObj)
 Define a stream function for logging this type. More...
 
bool TransformIsClose (const ARRAY_OPTIONS::TRANSFORM &aL, const ARRAY_OPTIONS::TRANSFORM &aR)
 Predicate to see if a ARRAY_OPTIONS::TRANSFORM is equal or nearly equal. More...
 
void CheckArrayTransforms (const ARRAY_OPTIONS &aOpts, const VECTOR2I &aPos, const std::vector< ARRAY_OPTIONS::TRANSFORM > &aExp)
 Generate all array transforms for an array descriptor and compare against a list of expected transforms. More...
 
 BOOST_AUTO_TEST_CASE (GridGeometry)
 Test of grid array geometry. More...
 
 BOOST_AUTO_TEST_CASE (CircularGeometry)
 Test of circular array geometry. More...
 
void CheckArrayNumbering (const ARRAY_OPTIONS &aOpts, const std::vector< std::string > &aExp)
 Generate all array names and check against expected. More...
 
 BOOST_AUTO_TEST_CASE (GridNaming)
 Test of grid array geometry. More...
 

Variables

static const std::vector< GRID_ARRAY_TEST_CASEgrid_geom_cases
 
static const std::vector< CIRC_ARRAY_TEST_CASEcirc_geom_cases
 
static const std::vector< GRID_ARRAY_NAMING_CASEgrid_name_cases
 

Detailed Description

Test suite for ARRAY_OPTIONS.

Definition in file test_array_options.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( GridGeometry  )

Test of grid array geometry.

Definition at line 260 of file test_array_options.cpp.

261 {
262  for( const auto& c : grid_geom_cases )
263  {
264  BOOST_TEST_CONTEXT( c.m_case_name )
265  {
266  ARRAY_GRID_OPTIONS grid_opts;
267 
268  grid_opts.m_nx = c.m_geom.m_nx;
269  grid_opts.m_ny = c.m_geom.m_ny;
270  grid_opts.m_delta = (wxPoint) c.m_geom.m_delta;
271  grid_opts.m_offset = (wxPoint) c.m_geom.m_offset;
272  grid_opts.m_stagger = c.m_geom.m_stagger;
273  grid_opts.m_stagger_rows = c.m_geom.m_stagger_by_row;
274  grid_opts.m_reverseNumberingAlternate = c.m_geom.m_alternate_numbers;
275  grid_opts.m_horizontalThenVertical = c.m_geom.m_h_then_v;
276 
277  CheckArrayTransforms( grid_opts, c.m_item_pos, c.m_exp_transforms );
278  }
279  }
280 }
static const std::vector< GRID_ARRAY_TEST_CASE > grid_geom_cases
bool m_reverseNumberingAlternate
#define BOOST_TEST_CONTEXT(A)
void CheckArrayTransforms(const ARRAY_OPTIONS &aOpts, const VECTOR2I &aPos, const std::vector< ARRAY_OPTIONS::TRANSFORM > &aExp)
Generate all array transforms for an array descriptor and compare against a list of expected transfor...

References BOOST_TEST_CONTEXT, CheckArrayTransforms(), grid_geom_cases, ARRAY_GRID_OPTIONS::m_delta, ARRAY_GRID_OPTIONS::m_horizontalThenVertical, ARRAY_GRID_OPTIONS::m_nx, ARRAY_GRID_OPTIONS::m_ny, ARRAY_GRID_OPTIONS::m_offset, ARRAY_GRID_OPTIONS::m_reverseNumberingAlternate, ARRAY_GRID_OPTIONS::m_stagger, and ARRAY_GRID_OPTIONS::m_stagger_rows.

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( CircularGeometry  )

Test of circular array geometry.

Definition at line 357 of file test_array_options.cpp.

358 {
359  for( const auto& c : circ_geom_cases )
360  {
361  BOOST_TEST_CONTEXT( c.m_case_name )
362  {
363  ARRAY_CIRCULAR_OPTIONS grid_opts;
364 
365  grid_opts.m_nPts = c.m_geom.n;
366  grid_opts.m_angle = 10 * c.m_geom.angle_offset;
367  grid_opts.m_centre = c.m_geom.centre;
368  grid_opts.m_rotateItems = c.m_geom.rotate;
369 
370  CheckArrayTransforms( grid_opts, c.m_item_pos, c.m_exp_transforms );
371  }
372  }
373 }
static const std::vector< CIRC_ARRAY_TEST_CASE > circ_geom_cases
long m_nPts
number of point in the array
#define BOOST_TEST_CONTEXT(A)
void CheckArrayTransforms(const ARRAY_OPTIONS &aOpts, const VECTOR2I &aPos, const std::vector< ARRAY_OPTIONS::TRANSFORM > &aExp)
Generate all array transforms for an array descriptor and compare against a list of expected transfor...
double m_angle
angle between points, or 0 for each point separated by this value (decideg)

References BOOST_TEST_CONTEXT, CheckArrayTransforms(), circ_geom_cases, ARRAY_CIRCULAR_OPTIONS::m_angle, ARRAY_CIRCULAR_OPTIONS::m_centre, ARRAY_CIRCULAR_OPTIONS::m_nPts, and ARRAY_CIRCULAR_OPTIONS::m_rotateItems.

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( GridNaming  )

Test of grid array geometry.

Definition at line 484 of file test_array_options.cpp.

485 {
486  for( const auto& c : grid_name_cases )
487  {
488  BOOST_TEST_CONTEXT( c.m_case_name )
489  {
490  ARRAY_GRID_OPTIONS grid_opts;
491 
492  grid_opts.m_nx = c.m_prms.m_nx;
493  grid_opts.m_ny = c.m_prms.m_ny;
494 
495  grid_opts.m_horizontalThenVertical = c.m_prms.m_h_then_v;
496 
497  grid_opts.m_pri_axis.SetAxisType( c.m_prms.m_pri_type );
498  grid_opts.m_sec_axis.SetAxisType( c.m_prms.m_sec_type );
499 
500  grid_opts.m_pri_axis.SetOffset( c.m_prms.m_start_at_x );
501  grid_opts.m_sec_axis.SetOffset( c.m_prms.m_start_at_y );
502 
503  grid_opts.m_2dArrayNumbering = c.m_prms.m_2d_numbering;
504 
505  // other grid settings (geom) can be defaulted, as they don't affect numbering
506 
507  CheckArrayNumbering( grid_opts, c.m_exp_names );
508  }
509  }
510 }
ARRAY_AXIS m_pri_axis
void CheckArrayNumbering(const ARRAY_OPTIONS &aOpts, const std::vector< std::string > &aExp)
Generate all array names and check against expected.
void SetAxisType(NUMBERING_TYPE aType)
Set the axis numbering type.
Definition: array_axis.cpp:96
static const std::vector< GRID_ARRAY_NAMING_CASE > grid_name_cases
bool SetOffset(const wxString &aOffsetName)
Set the axis start (as a string, which should decode to a valid index in the alphabet)
Definition: array_axis.cpp:102
#define BOOST_TEST_CONTEXT(A)
ARRAY_AXIS m_sec_axis

References BOOST_TEST_CONTEXT, CheckArrayNumbering(), grid_name_cases, ARRAY_GRID_OPTIONS::m_2dArrayNumbering, ARRAY_GRID_OPTIONS::m_horizontalThenVertical, ARRAY_GRID_OPTIONS::m_nx, ARRAY_GRID_OPTIONS::m_ny, ARRAY_GRID_OPTIONS::m_pri_axis, ARRAY_GRID_OPTIONS::m_sec_axis, ARRAY_AXIS::SetAxisType(), and ARRAY_AXIS::SetOffset().

◆ CheckArrayNumbering()

void CheckArrayNumbering ( const ARRAY_OPTIONS aOpts,
const std::vector< std::string > &  aExp 
)

Generate all array names and check against expected.

Parameters
aOptsthe array descriptor
aExpexpected name list

Definition at line 380 of file test_array_options.cpp.

381 {
382  std::vector<std::string> names;
383 
384  for( int i = 0; i < aOpts.GetArraySize(); ++i )
385  {
386  names.push_back( aOpts.GetItemNumber( i ).ToStdString() );
387  }
388 
389  BOOST_CHECK_EQUAL_COLLECTIONS( names.begin(), names.end(), aExp.begin(), aExp.end() );
390 }
virtual int GetArraySize() const =0
The number of points in this array.
virtual wxString GetItemNumber(int n) const =0
Get the position number (name) for the n'th array point.

References ARRAY_OPTIONS::GetArraySize(), and ARRAY_OPTIONS::GetItemNumber().

Referenced by BOOST_AUTO_TEST_CASE().

◆ CheckArrayTransforms()

void CheckArrayTransforms ( const ARRAY_OPTIONS aOpts,
const VECTOR2I aPos,
const std::vector< ARRAY_OPTIONS::TRANSFORM > &  aExp 
)

Generate all array transforms for an array descriptor and compare against a list of expected transforms.

Parameters
aOptsthe array descriptor
aPosthe position of the reference item
aExpexpected transform list

Definition at line 67 of file test_array_options.cpp.

69 {
70  std::vector<ARRAY_OPTIONS::TRANSFORM> transforms;
71 
72  for( int i = 0; i < aOpts.GetArraySize(); ++i )
73  {
74  transforms.push_back( aOpts.GetTransform( i, aPos ) );
75  }
76 
77  BOOST_CHECK_EQUAL( transforms.size(), aExp.size() );
78 
79  for( unsigned i = 0; i < std::min( transforms.size(), aExp.size() ); ++i )
80  {
81  BOOST_TEST_CONTEXT( "Index " << i )
82  {
83  BOOST_CHECK_PREDICATE( TransformIsClose, ( transforms[i] )( aExp[i] ) );
84  }
85  }
86 }
virtual int GetArraySize() const =0
The number of points in this array.
#define BOOST_TEST_CONTEXT(A)
virtual TRANSFORM GetTransform(int aN, const VECTOR2I &aPos) const =0
Get the transform of the n-th point in the array.
bool TransformIsClose(const ARRAY_OPTIONS::TRANSFORM &aL, const ARRAY_OPTIONS::TRANSFORM &aR)
Predicate to see if a ARRAY_OPTIONS::TRANSFORM is equal or nearly equal.

References BOOST_TEST_CONTEXT, ARRAY_OPTIONS::GetArraySize(), ARRAY_OPTIONS::GetTransform(), and TransformIsClose().

Referenced by BOOST_AUTO_TEST_CASE().

◆ operator<<()

std::ostream& operator<< ( std::ostream &  os,
const ARRAY_OPTIONS::TRANSFORM aObj 
)

Define a stream function for logging this type.

TODO: convert to boost_test_print_type when Boost minver > 1.64

Definition at line 42 of file test_array_options.cpp.

43 {
44  os << "TRANSFORM[ " << aObj.m_offset << " r " << aObj.m_rotation << "deg"
45  << " ]";
46  return os;
47 }

References ARRAY_OPTIONS::TRANSFORM::m_offset, and ARRAY_OPTIONS::TRANSFORM::m_rotation.

◆ TransformIsClose()

bool TransformIsClose ( const ARRAY_OPTIONS::TRANSFORM aL,
const ARRAY_OPTIONS::TRANSFORM aR 
)

Predicate to see if a ARRAY_OPTIONS::TRANSFORM is equal or nearly equal.

Definition at line 53 of file test_array_options.cpp.

54 {
55  return KI_TEST::IsVecWithinTol<VECTOR2I>( aL.m_offset, aR.m_offset, 1 )
56  && KI_TEST::IsWithin<double>( aL.m_rotation, aR.m_rotation, 0.001 );
57 }

References ARRAY_OPTIONS::TRANSFORM::m_offset, and ARRAY_OPTIONS::TRANSFORM::m_rotation.

Referenced by CheckArrayTransforms().

Variable Documentation

◆ circ_geom_cases

const std::vector<CIRC_ARRAY_TEST_CASE> circ_geom_cases
static

Definition at line 301 of file test_array_options.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ grid_geom_cases

const std::vector<GRID_ARRAY_TEST_CASE> grid_geom_cases
static

Definition at line 117 of file test_array_options.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ grid_name_cases

const std::vector<GRID_ARRAY_NAMING_CASE> grid_name_cases
static

Definition at line 415 of file test_array_options.cpp.

Referenced by BOOST_AUTO_TEST_CASE().