7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-04 22:25:30 +00:00

QA: BOOST_CHECK to _TEST in some KiMath tests

This tells you the arguments when it fails.

BOOST_TEST is available in all our Boost.Test version.
Even if you didn't use it, these calls should have been
BOOST_TEST_EQUAL(A, B) which also tells you the
arguments on a test failure.
This commit is contained in:
John Beard 2024-10-09 05:52:10 +08:00
parent bd652fd88f
commit 55370e7520
8 changed files with 73 additions and 64 deletions

View File

@ -20,6 +20,7 @@
#ifndef VECTOR3_H_
#define VECTOR3_H_
#include <iostream>
#include <stdint.h>
#include <limits>
#include <wx/debug.h>
@ -201,6 +202,14 @@ VECTOR3<T>& VECTOR3<T>::operator/=( T aScalar )
}
template <class T>
std::ostream& operator<<( std::ostream& aStream, const VECTOR3<T>& aVector )
{
aStream << "[ " << aVector.x << " | " << aVector.y << " | " << aVector.z << " ]";
return aStream;
}
/* Default specializations */
typedef VECTOR3<double> VECTOR3D;
typedef VECTOR3<int> VECTOR3I;

View File

@ -88,13 +88,13 @@ BOOST_AUTO_TEST_CASE( ShapeCompoundCollide )
int actual;
// Check points on corners
BOOST_CHECK( compoundA->Collide( compoundB, 0, &actual ) );
BOOST_CHECK( actual == 0 );
BOOST_TEST( actual == 0 );
BOOST_CHECK( !compoundA->Collide( compoundC, 0, &actual ) );
BOOST_CHECK( actual == 0 );
BOOST_TEST( actual == 0 );
BOOST_CHECK( compoundA->Collide( compoundC, 100, &actual ) );
BOOST_CHECK( actual == 80 );
BOOST_TEST( actual == 80 );
BOOST_CHECK( shapesA[0]->Collide( compoundB, 0 ) );
BOOST_CHECK( shapesA[1]->Collide( compoundB, 0 ) );
@ -117,13 +117,13 @@ BOOST_AUTO_TEST_CASE( ShapeCompoundCollide )
BOOST_CHECK( ! compoundC->Collide( shapesA[1], 0 ) );
BOOST_CHECK( shapesC[0]->Collide( compoundA, 100, &actual ) );
BOOST_CHECK( actual == 80 );
BOOST_TEST( actual == 80 );
BOOST_CHECK( shapesC[1]->Collide( compoundA, 100, &actual ) );
BOOST_CHECK( actual == 80 );
BOOST_TEST( actual == 80 );
BOOST_CHECK( compoundA->Collide( shapesC[0], 100, &actual ) );
BOOST_CHECK( actual == 80 );
BOOST_TEST( actual == 80 );
BOOST_CHECK( compoundA->Collide( shapesC[1], 100, &actual ) );
BOOST_CHECK( actual == 80 );
BOOST_TEST( actual == 80 );
}

View File

@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE( Collide_LineToLine )
bool collided = static_cast<SHAPE*>( &lineA )->Collide( &lineB, 0, &actual, &location );
BOOST_CHECK( collided );
BOOST_CHECK( actual == 0 );
BOOST_TEST( actual == 0 );
BOOST_CHECK_MESSAGE( location == VECTOR2I( 5, 0 ), "Expected: " << VECTOR2I( 5, 0 ) << " Actual: " << location );
}
@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE( Collide_LineToArc )
bool collided = static_cast<SHAPE*>( &lineA )->Collide( &arcB, 0, &actual, &location );
BOOST_CHECK( collided );
BOOST_CHECK( actual == 0 );
BOOST_TEST( actual == 0 );
BOOST_CHECK_MESSAGE( location == VECTOR2I( 7, 0 ), "Expected: " << VECTOR2I( 7, 0 ) << " Actual: " << location );
}
@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE( Collide_ArcToArc )
bool collided = static_cast<SHAPE*>( &arcA )->Collide( &arcB, 0, &actual, &location );
BOOST_CHECK( collided );
BOOST_CHECK( actual == 0 );
BOOST_TEST( actual == 0 );
BOOST_CHECK_MESSAGE( location == VECTOR2I( 5, 5 ), "Expected: " << VECTOR2I( 5, 5 ) << " Actual: " << location );
}

View File

@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE( BasicInt )
BOOST_TEST( box.GetSize() == VECTOR2L( 3, 4 ) );
// Check the equality operator
BOOST_CHECK( box == BOX2I( VECTOR2I( 1, 2 ), VECTOR2I( 3, 4 ) ) );
BOOST_TEST( box == BOX2I( VECTOR2I( 1, 2 ), VECTOR2I( 3, 4 ) ) );
// Inflate in-place
BOX2I inflated = box;
@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE( ByCorners )
const BOX2I boxByCorners = BOX2I::ByCorners( VECTOR2I( 1, 2 ), VECTOR2I( 3, 4 ) );
const BOX2I boxByPosSize = BOX2I( VECTOR2I( 1, 2 ), VECTOR2I( 2, 2 ) );
BOOST_CHECK( boxByCorners == boxByPosSize );
BOOST_TEST( boxByCorners == boxByPosSize );
}
BOOST_AUTO_TEST_CASE( ByCentre )
@ -109,7 +109,7 @@ BOOST_AUTO_TEST_CASE( ByCentre )
const BOX2I boxByCenter = BOX2I::ByCenter( VECTOR2I( 100, 100 ), VECTOR2I( 20, 20 ) );
const BOX2I boxByPosSize = BOX2I( VECTOR2I( 90, 90 ), VECTOR2I( 20, 20 ) );
BOOST_CHECK( boxByCenter == boxByPosSize );
BOOST_TEST( boxByCenter == boxByPosSize );
}
BOOST_AUTO_TEST_CASE( test_closest_point_to, *boost::unit_test::tolerance( 0.000001 ) )
@ -119,31 +119,31 @@ BOOST_AUTO_TEST_CASE( test_closest_point_to, *boost::unit_test::tolerance( 0.000
// check all quadrants
// top left
BOOST_CHECK( box.ClosestPointTo( VECTOR2D( 0, 0 ) ) == VECTOR2D( 1, 2 ) );
BOOST_TEST( box.ClosestPointTo( VECTOR2D( 0, 0 ) ) == VECTOR2D( 1, 2 ) );
// top
BOOST_CHECK( box.ClosestPointTo( VECTOR2D( 2, 0 ) ) == VECTOR2D( 2, 2 ) );
BOOST_TEST( box.ClosestPointTo( VECTOR2D( 2, 0 ) ) == VECTOR2D( 2, 2 ) );
// top right
BOOST_CHECK( box.ClosestPointTo( VECTOR2D( 6, 0 ) ) == VECTOR2D( 4, 2 ) );
BOOST_TEST( box.ClosestPointTo( VECTOR2D( 6, 0 ) ) == VECTOR2D( 4, 2 ) );
// right
BOOST_CHECK( box.ClosestPointTo( VECTOR2D( 6, 5 ) ) == VECTOR2D( 4, 5 ) );
BOOST_TEST( box.ClosestPointTo( VECTOR2D( 6, 5 ) ) == VECTOR2D( 4, 5 ) );
// bottom right
BOOST_CHECK( box.ClosestPointTo( VECTOR2D( 6, 7 ) ) == VECTOR2D( 4, 6 ) );
BOOST_TEST( box.ClosestPointTo( VECTOR2D( 6, 7 ) ) == VECTOR2D( 4, 6 ) );
// bottom
BOOST_CHECK( box.ClosestPointTo( VECTOR2D( 3, 7 ) ) == VECTOR2D( 3, 6 ) );
BOOST_TEST( box.ClosestPointTo( VECTOR2D( 3, 7 ) ) == VECTOR2D( 3, 6 ) );
// bottom left
BOOST_CHECK( box.ClosestPointTo( VECTOR2D( 0, 7 ) ) == VECTOR2D( 1, 6 ) );
BOOST_TEST( box.ClosestPointTo( VECTOR2D( 0, 7 ) ) == VECTOR2D( 1, 6 ) );
// left
BOOST_CHECK( box.ClosestPointTo( VECTOR2D( 0, 3 ) ) == VECTOR2D( 1, 3 ) );
BOOST_TEST( box.ClosestPointTo( VECTOR2D( 0, 3 ) ) == VECTOR2D( 1, 3 ) );
// inside
BOOST_CHECK( box.ClosestPointTo( VECTOR2D( 2, 4 ) ) == VECTOR2D( 2, 4 ) );
BOOST_TEST( box.ClosestPointTo( VECTOR2D( 2, 4 ) ) == VECTOR2D( 2, 4 ) );
}
BOOST_AUTO_TEST_CASE( test_farthest_point_to, *boost::unit_test::tolerance( 0.000001 ) )
@ -155,30 +155,30 @@ BOOST_AUTO_TEST_CASE( test_farthest_point_to, *boost::unit_test::tolerance( 0.00
// outside:
// top left
BOOST_CHECK( box.FarthestPointTo( VECTOR2D( 0, 0 ) ) == VECTOR2D( 4, 6 ) );
BOOST_TEST( box.FarthestPointTo( VECTOR2D( 0, 0 ) ) == VECTOR2D( 4, 6 ) );
// top right
BOOST_CHECK( box.FarthestPointTo( VECTOR2D( 6, 0 ) ) == VECTOR2D( 1, 6 ) );
BOOST_TEST( box.FarthestPointTo( VECTOR2D( 6, 0 ) ) == VECTOR2D( 1, 6 ) );
// bottom right
BOOST_CHECK( box.FarthestPointTo( VECTOR2D( 6, 7 ) ) == VECTOR2D( 1, 2 ) );
BOOST_TEST( box.FarthestPointTo( VECTOR2D( 6, 7 ) ) == VECTOR2D( 1, 2 ) );
// bottom left
BOOST_CHECK( box.FarthestPointTo( VECTOR2D( 0, 7 ) ) == VECTOR2D( 4, 2 ) );
BOOST_TEST( box.FarthestPointTo( VECTOR2D( 0, 7 ) ) == VECTOR2D( 4, 2 ) );
// inside:
// top left
BOOST_CHECK( box.FarthestPointTo( VECTOR2D( 2, 3 ) ) == VECTOR2D( 4, 6 ) );
BOOST_TEST( box.FarthestPointTo( VECTOR2D( 2, 3 ) ) == VECTOR2D( 4, 6 ) );
// top right
BOOST_CHECK( box.FarthestPointTo( VECTOR2D( 3, 3 ) ) == VECTOR2D( 1, 6 ) );
BOOST_TEST( box.FarthestPointTo( VECTOR2D( 3, 3 ) ) == VECTOR2D( 1, 6 ) );
// bottom right
BOOST_CHECK( box.FarthestPointTo( VECTOR2D( 3, 5 ) ) == VECTOR2D( 1, 2 ) );
BOOST_TEST( box.FarthestPointTo( VECTOR2D( 3, 5 ) ) == VECTOR2D( 1, 2 ) );
// bottom left
BOOST_CHECK( box.FarthestPointTo( VECTOR2D( 2, 5 ) ) == VECTOR2D( 4, 2 ) );
BOOST_TEST( box.FarthestPointTo( VECTOR2D( 2, 5 ) ) == VECTOR2D( 4, 2 ) );
}
BOOST_AUTO_TEST_CASE( test_intersects_circle, *boost::unit_test::tolerance( 0.000001 ) )
@ -186,16 +186,16 @@ BOOST_AUTO_TEST_CASE( test_intersects_circle, *boost::unit_test::tolerance( 0.00
BOX2D box( VECTOR2D( 1, 2 ), VECTOR2D( 6, 8 ) );
// box inside circle (touching corners)
BOOST_CHECK( box.IntersectsCircle( VECTOR2D( 4, 6 ), 5 ) == true );
BOOST_TEST( box.IntersectsCircle( VECTOR2D( 4, 6 ), 5 ) == true );
// box completely inside circle
BOOST_CHECK( box.IntersectsCircle( VECTOR2D( 4, 6 ), 6 ) == true );
BOOST_TEST( box.IntersectsCircle( VECTOR2D( 4, 6 ), 6 ) == true );
// circle completely inside box
BOOST_CHECK( box.IntersectsCircle( VECTOR2D( 4, 6 ), 2 ) == true );
BOOST_TEST( box.IntersectsCircle( VECTOR2D( 4, 6 ), 2 ) == true );
// circle outside box
BOOST_CHECK( box.IntersectsCircle( VECTOR2D( 14, 6 ), 5 ) == false );
BOOST_TEST( box.IntersectsCircle( VECTOR2D( 14, 6 ), 5 ) == false );
}
BOOST_AUTO_TEST_CASE( test_intersects_circle_edge, *boost::unit_test::tolerance( 0.000001 ) )
@ -203,16 +203,16 @@ BOOST_AUTO_TEST_CASE( test_intersects_circle_edge, *boost::unit_test::tolerance(
BOX2D box( VECTOR2D( 1, 2 ), VECTOR2D( 6, 8 ) );
// box touching edge
BOOST_CHECK( box.IntersectsCircleEdge( VECTOR2D( 4, 6 ), 5, 1 ) == true );
BOOST_TEST( box.IntersectsCircleEdge( VECTOR2D( 4, 6 ), 5, 1 ) == true );
// box completely inside circle
BOOST_CHECK( box.IntersectsCircleEdge( VECTOR2D( 4, 6 ), 6, 1 ) == false );
BOOST_TEST( box.IntersectsCircleEdge( VECTOR2D( 4, 6 ), 6, 1 ) == false );
// circle completely inside box
BOOST_CHECK( box.IntersectsCircleEdge( VECTOR2D( 4, 6 ), 2, 1 ) == true );
BOOST_TEST( box.IntersectsCircleEdge( VECTOR2D( 4, 6 ), 2, 1 ) == true );
// circle outside box
BOOST_CHECK( box.IntersectsCircleEdge( VECTOR2D( 14, 6 ), 5, 1 ) == false );
BOOST_TEST( box.IntersectsCircleEdge( VECTOR2D( 14, 6 ), 5, 1 ) == false );
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -42,8 +42,8 @@ BOOST_AUTO_TEST_CASE( test_equality_ops, *boost::unit_test::tolerance( 0.000001
MATRIX3x3D m2( VECTOR3I{ 6, 6, 6 }, { 1, 1, 1 }, { 3, 3, 3 } );
MATRIX3x3D m3( VECTOR3I{ 1, 1, 1 }, { 2, 2, 2 }, { 3, 3, 3 } );
BOOST_CHECK( m1 == m3 );
BOOST_CHECK( m2 != m1 );
BOOST_TEST( m1 == m3 );
BOOST_TEST( m2 != m1 );
}
BOOST_AUTO_TEST_CASE( test_matrix_multiply_vector, *boost::unit_test::tolerance( 0.000001 ) )
@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE( test_matrix_multiply_vector, *boost::unit_test::tolerance(
VECTOR3I expected( 15, 30, 45 );
BOOST_CHECK( res == expected );
BOOST_TEST( res == expected );
}
@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE( test_matrix_multiply_scalar, *boost::unit_test::tolerance(
MATRIX3x3 expected( VECTOR3I{ 5, 5, 5 }, { 10, 10, 10 }, { 15, 15, 15 } );
BOOST_CHECK( res == expected );
BOOST_TEST( res == expected );
}

View File

@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE( test_cross_product, *boost::unit_test::tolerance( 0.000001
VECTOR2I v1(0, 1);
VECTOR2I v2(1, 0);
BOOST_CHECK( v2.Cross( v1 ) == 1 );
BOOST_TEST( v2.Cross( v1 ) == 1 );
}
BOOST_AUTO_TEST_CASE( test_dot_product, *boost::unit_test::tolerance( 0.000001 ) )
@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE( test_dot_product, *boost::unit_test::tolerance( 0.000001 )
VECTOR2I v1( 0, 1 );
VECTOR2I v2( 1, 0 );
BOOST_CHECK( v2.Dot( v1 ) == 0 );
BOOST_TEST( v2.Dot( v1 ) == 0 );
}
BOOST_AUTO_TEST_CASE( test_resize, *boost::unit_test::tolerance( 0.000001 ) )
@ -99,11 +99,11 @@ BOOST_AUTO_TEST_CASE( test_resize, *boost::unit_test::tolerance( 0.000001 ) )
VECTOR2I v4( 1, 1 );
VECTOR2I v5( -70, -70 );
BOOST_CHECK( v1.Resize( 8 ) == VECTOR2I( 6, 5 ) );
BOOST_CHECK( v2.Resize( 10 ) == VECTOR2I( 10, -2 ) );
BOOST_CHECK( v3.Resize( 4 ) == VECTOR2I( -4, 2 ) );
BOOST_CHECK( v4.Resize( 1 ) == VECTOR2I( 1, 1 ) );
BOOST_CHECK( v5.Resize( 100 ) == VECTOR2I( -71, -71 ) );
BOOST_TEST( v1.Resize( 8 ) == VECTOR2I( 6, 5 ) );
BOOST_TEST( v2.Resize( 10 ) == VECTOR2I( 10, -2 ) );
BOOST_TEST( v3.Resize( 4 ) == VECTOR2I( -4, 2 ) );
BOOST_TEST( v4.Resize( 1 ) == VECTOR2I( 1, 1 ) );
BOOST_TEST( v5.Resize( 100 ) == VECTOR2I( -71, -71 ) );
}
BOOST_AUTO_TEST_CASE( test_casting )

View File

@ -40,7 +40,7 @@ BOOST_AUTO_TEST_CASE( test_cross_product, *boost::unit_test::tolerance( 0.000001
VECTOR3I v1( 0, 1, 2 );
VECTOR3I v2( 2, 1, 0 );
BOOST_CHECK( v1.Cross( v2 ) == VECTOR3I(-2, 4 ,-2) );
BOOST_TEST( v1.Cross( v2 ) == VECTOR3I( -2, 4, -2 ) );
}
BOOST_AUTO_TEST_CASE( test_dot_product, *boost::unit_test::tolerance( 0.000001 ) )
@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE( test_dot_product, *boost::unit_test::tolerance( 0.000001 )
VECTOR3I v1( 0, 1, 2 );
VECTOR3I v2( 2, 1, 0 );
BOOST_CHECK( v1.Dot( v2 ) == 1 );
BOOST_TEST( v1.Dot( v2 ) == 1 );
}
BOOST_AUTO_TEST_CASE( test_equality_ops, *boost::unit_test::tolerance( 0.000001 ) )
@ -57,8 +57,8 @@ BOOST_AUTO_TEST_CASE( test_equality_ops, *boost::unit_test::tolerance( 0.000001
VECTOR3I v2( 2, 2, 2 );
VECTOR3I v3( 1, 1, 1 );
BOOST_CHECK( v1 == v3 );
BOOST_CHECK( v1 != v2 );
BOOST_TEST( v1 == v3 );
BOOST_TEST( v1 != v2 );
}
BOOST_AUTO_TEST_CASE( test_scalar_multiply, *boost::unit_test::tolerance( 0.000001 ) )
@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE( test_scalar_multiply, *boost::unit_test::tolerance( 0.0000
v1 *= 5;
BOOST_CHECK( v1 == VECTOR3( 5, 5, 5 ) );
BOOST_TEST( v1 == VECTOR3( 5, 5, 5 ) );
}
BOOST_AUTO_TEST_CASE( test_scalar_divide, *boost::unit_test::tolerance( 0.000001 ) )
@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE( test_scalar_divide, *boost::unit_test::tolerance( 0.000001
v1 /= 5;
BOOST_CHECK( v1 == VECTOR3( 1, 1, 1 ) );
BOOST_TEST( v1 == VECTOR3( 1, 1, 1 ) );
}

View File

@ -42,10 +42,10 @@ BOOST_AUTO_TEST_CASE( SingleLayer )
zone.SetLayer( F_Cu );
BOOST_CHECK( zone.GetLayer() == F_Cu );
BOOST_CHECK( zone.GetLayer() == zone.GetFirstLayer() );
BOOST_TEST( zone.GetLayer() == F_Cu );
BOOST_TEST( zone.GetLayer() == zone.GetFirstLayer() );
BOOST_CHECK( zone.IsOnCopperLayer() == true );
BOOST_TEST( zone.IsOnCopperLayer() == true );
}
BOOST_AUTO_TEST_CASE( MultipleLayers )
@ -55,11 +55,11 @@ BOOST_AUTO_TEST_CASE( MultipleLayers )
zone.SetLayerSet( { F_Cu, B_Cu } );
// There is no "the" layer in a multi-layer zone
BOOST_CHECK( zone.GetLayer() == UNDEFINED_LAYER );
BOOST_TEST( zone.GetLayer() == UNDEFINED_LAYER );
// ... but there is a first layer
BOOST_CHECK( zone.GetFirstLayer() == F_Cu );
BOOST_TEST( zone.GetFirstLayer() == F_Cu );
BOOST_CHECK( zone.IsOnCopperLayer() == true );
BOOST_TEST( zone.IsOnCopperLayer() == true );
}
/**
@ -74,10 +74,10 @@ BOOST_AUTO_TEST_CASE( RescuedLayers )
zone.SetLayer( Rescue );
BOOST_CHECK( zone.GetLayer() == Rescue );
BOOST_CHECK( zone.GetLayer() == zone.GetFirstLayer() );
BOOST_TEST( zone.GetLayer() == Rescue );
BOOST_TEST( zone.GetLayer() == zone.GetFirstLayer() );
BOOST_CHECK( zone.IsOnCopperLayer() == false );
BOOST_TEST( zone.IsOnCopperLayer() == false );
}
BOOST_AUTO_TEST_SUITE_END()