KiCad PCB EDA Suite
test_array_axis.cpp File Reference

Test suite for ARRAY_AXIS. More...

Go to the source code of this file.

Classes

struct  VALID_OFFSET_CASE
 Declare the test suite. More...
 
struct  ARRAY_AXIS_NAMING_PARAMS
 Data for testing a single array axis. More...
 
struct  ARRAY_AXIS_NAMING_CASE
 

Functions

 BOOST_AUTO_TEST_CASE (ValidOffsets)
 Check we can get valid (or invalid) offsets as expected. More...
 
 BOOST_AUTO_TEST_CASE (Numbering)
 Test of the naming cases. More...
 

Variables

static const std::vector< ARRAY_AXIS_NAMING_CASEaxis_name_cases
 

Detailed Description

Test suite for ARRAY_AXIS.

Definition in file test_array_axis.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( ValidOffsets  )

Check we can get valid (or invalid) offsets as expected.

Definition at line 50 of file test_array_axis.cpp.

51 {
52  // clang-format off
53  const std::vector<VALID_OFFSET_CASE> cases = {
54  {
55  ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC,
56  "0",
57  true,
58  0,
59  },
60  {
61  ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC,
62  "1",
63  true,
64  1,
65  },
66  {
67  ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC,
68  "1234",
69  true,
70  1234,
71  },
72  {
73  ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC,
74  "",
75  false,
76  0,
77  },
78  {
79  ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_NUMERIC,
80  "www",
81  false,
82  0,
83  },
84  {
85  ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_ALPHA_FULL,
86  "A",
87  true,
88  0,
89  },
90  {
91  ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_ALPHA_FULL,
92  "XY",
93  true,
94  648,
95  },
96  {
97  ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_HEX,
98  "A0",
99  true,
100  160,
101  },
102  {
103  ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_HEX,
104  "G0",
105  false,
106  0,
107  },
108  };
109  // clang-format on
110 
111  for( const auto& c : cases )
112  {
113  ARRAY_AXIS axis;
114  axis.SetAxisType( c.m_axis_type );
115 
116  bool offset_ok = axis.SetOffset( c.m_offset_str );
117 
118  BOOST_CHECK_EQUAL( offset_ok, c.m_exp_valid );
119 
120  if( c.m_exp_valid )
121  {
122  BOOST_CHECK_EQUAL( axis.GetOffset(), c.m_exp_offset );
123  }
124  }
125 }
void SetAxisType(NUMBERING_TYPE aType)
Set the axis numbering type.
Definition: array_axis.cpp:96
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
Class that contains information about a single array axis and the numbering of items along that axis.
Definition: array_axis.h:38
int GetOffset() const
Get the numbering offset for the axis.
Definition: array_axis.cpp:121

References ARRAY_AXIS::GetOffset(), ARRAY_AXIS::SetAxisType(), and ARRAY_AXIS::SetOffset().

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( Numbering  )

Test of the naming cases.

Definition at line 196 of file test_array_axis.cpp.

197 {
198  for( const auto& c : axis_name_cases )
199  {
200  BOOST_TEST_CONTEXT( c.m_case_name )
201  {
202  ARRAY_AXIS axis;
203  axis.SetAxisType( c.m_prms.m_axis_type );
204  axis.SetStep( c.m_prms.m_step );
205 
206  bool start_ok = axis.SetOffset( c.m_prms.m_start_at );
207 
208  // All these examples have valid start offsets
209  BOOST_CHECK( start_ok );
210 
211  std::vector<std::string> names;
212 
213  for( int i = 0; i < c.m_num; i++ )
214  {
215  names.push_back( axis.GetItemNumber( i ).ToStdString() );
216  }
217 
218  BOOST_CHECK_EQUAL_COLLECTIONS(
219  names.begin(), names.end(), c.m_exp_names.begin(), c.m_exp_names.end() );
220  }
221  }
222 }
wxString GetItemNumber(int n) const
Get the position number (name) for the n'th axis point.
Definition: array_axis.cpp:133
void SetAxisType(NUMBERING_TYPE aType)
Set the axis numbering type.
Definition: array_axis.cpp:96
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
BOOST_CHECK(v2.Cross(v1)==1)
void SetStep(int aStep)
Set the skip between consecutive numbers (useful when doing a partial array, e.g.
Definition: array_axis.cpp:127
static const std::vector< ARRAY_AXIS_NAMING_CASE > axis_name_cases
Class that contains information about a single array axis and the numbering of items along that axis.
Definition: array_axis.h:38
#define BOOST_TEST_CONTEXT(A)

References axis_name_cases, BOOST_CHECK(), BOOST_TEST_CONTEXT, ARRAY_AXIS::GetItemNumber(), ARRAY_AXIS::SetAxisType(), ARRAY_AXIS::SetOffset(), and ARRAY_AXIS::SetStep().

Variable Documentation

◆ axis_name_cases

const std::vector<ARRAY_AXIS_NAMING_CASE> axis_name_cases
static

Definition at line 147 of file test_array_axis.cpp.

Referenced by BOOST_AUTO_TEST_CASE().