/
spivag
/
command_occ
Обзор
Документация
Войти
/
spivag
/
command_occ
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
initial
tests/gtest_r1.cpp
280 строк
7 KB
Spivakov
Initial
10 апр 2026, 13:45
10 апр 2026, 13:45
b2ad868
Код
Авторство
О чём код?
/// @file gtest_r1.cpp /// @brief R1 primitives tests /// @project gtests /// /// (c) Alexander Spivakov on 02.09.2025. /// #include <geometry_types.h> #include <gtest/gtest.h> #include <cmath> #ifdef WIN32 #define M_PI 3.141592653589793238462643383279502884 #endif // MSVC TEST( R1, AngleEpsilon ) { ASSERT_GT( R1::Angle::Epsilon(), 0.0 ); } TEST( R1_Angle, DefaultConstructor ) { R1::Angle a{}; ASSERT_NEAR( a.m_angle, 0.0, R1::Angle::Epsilon() ); } TEST( R1_Angle, Constructor ) { for ( double angle = -10.0; angle <= 10.0; angle += 15.0 ) { R1::Angle a{ angle }; ASSERT_NEAR( a.m_angle, angle, R1::Angle::Epsilon() ); } } TEST( R1_Angle, DegreesDefaultConstructor ) { R1::Angle::Degrees degrees{}; ASSERT_NEAR( degrees.m_degrees, 0.0, R1::Angle::Epsilon() ); } TEST( R1_Angle, DegreesConstructor ) { for ( double degrees = -380.0; degrees <= 380.0; degrees += 15.0 ) { R1::Angle::Degrees d{ degrees }; ASSERT_NEAR( d.m_degrees, degrees, R1::Angle::Epsilon() ); } } TEST( R1_Angle, ConstructorFromDegrees ) { for ( double degrees = -380.0; degrees <= 380.0; degrees += 15.0 ) { R1::Angle a{ R1::Angle::Degrees{ degrees } }; ASSERT_NEAR( a.m_angle, degrees * M_PI / 180.0, R1::Angle::Epsilon() ); } } TEST( R1_Angle_02pi, DefaultConstructor ) { R1::Angle02pi a{}; ASSERT_NEAR( a.m_angle.m_angle, 0.0, R1::Angle::Epsilon() ); ASSERT_TRUE( a.IsValid() ); } TEST( R1_Angle_02pi, Constructor ) { for ( double angle = 0.0; angle <= 360; angle += 15.0 ) { R1::Angle02pi a{ R1::Angle::Degrees{ angle } }; ASSERT_NEAR( a.m_angle.m_angle, angle * M_PI / 180., R1::Angle::Epsilon() ); ASSERT_TRUE( a.IsValid() ); } R1::Angle02pi a1{ R1::Angle::Degrees{ -10.0 } }; ASSERT_FALSE( a1.IsValid() ); R1::Angle02pi a2{ R1::Angle::Degrees{ 380.0 } }; ASSERT_FALSE( a2.IsValid() ); } TEST( R1_Angle_ModPi, DefaultConstructor ) { R1::AngleModPi a{}; ASSERT_NEAR( a.m_angle.m_angle, 0., R1::Angle::Epsilon() ); ASSERT_TRUE( a.IsValid() ); } TEST( R1_Angle_ModPi, Constructor ) { for ( double angle = -M_PI; angle <= M_PI; angle += M_PI / 3.0 ) { R1::AngleModPi a{ angle }; ASSERT_NEAR( a.m_angle.m_angle, angle, R1::Angle::Epsilon() ); ASSERT_TRUE( a.IsValid() ); } R1::AngleModPi a1{ R1::Angle::Degrees{ -200.0 } }; ASSERT_FALSE( a1.IsValid() ); R1::AngleModPi a2{ R1::Angle::Degrees{ 200.0 } }; ASSERT_FALSE( a2.IsValid() ); } TEST( R1_Angle_0Pi2, DefaultConstructor ) { R1::Angle0Pi2 a{}; ASSERT_NEAR( a.m_angle.m_angle, 0., R1::Angle::Epsilon() ); ASSERT_TRUE( a.IsValid() ); } TEST( R1_Angle_0Pi2, Constructor ) { for ( double angle = 0.; angle <= M_PI * 0.5; angle += M_PI / 3.0 ) { R1::Angle0Pi2 a{ angle }; ASSERT_NEAR( a.m_angle.m_angle, angle, R1::Angle::Epsilon() ); ASSERT_TRUE( a.IsValid() ); } R1::Angle0Pi2 a1{ R1::Angle::Degrees{ -20.0 } }; ASSERT_FALSE( a1.IsValid() ); R1::Angle0Pi2 a2{ R1::Angle::Degrees{ 100.0 } }; ASSERT_FALSE( a2.IsValid() ); } TEST( R1_Angle_0Pi, DefaultConstructor ) { R1::Angle0Pi a{}; ASSERT_NEAR( a.m_angle.m_angle, 0., R1::Angle::Epsilon() ); ASSERT_TRUE( a.IsValid() ); } TEST( R1_Angle_0Pi, Constructor ) { for ( double angle = 0.; angle <= M_PI; angle += M_PI / 3.0 ) { R1::Angle0Pi a{ angle }; ASSERT_NEAR( a.m_angle.m_angle, angle, R1::Angle::Epsilon() ); ASSERT_TRUE( a.IsValid() ); } R1::Angle0Pi a1{ R1::Angle::Degrees{ -20.0 } }; ASSERT_FALSE( a1.IsValid() ); R1::Angle0Pi a2{ R1::Angle::Degrees{ 185.0 } }; ASSERT_FALSE( a2.IsValid() ); } TEST( R1_Distance, Epsilon ) { ASSERT_GT( R1::Distance::Epsilon(), 0.0 ); } TEST( R1_Distance, DefaultConstructor ) { R1::Distance d{}; ASSERT_NEAR( d.m_distance, 0.0, R1::Distance::Epsilon() ); ASSERT_TRUE( d.IsValid() ); } TEST( R1_Distance, Constructor ) { for ( double distance = 0.; distance <= 10.0; distance += 5.0 ) { R1::Distance d{ distance }; ASSERT_NEAR( d.m_distance, distance, R1::Distance::Epsilon() ); ASSERT_TRUE( d.IsValid() ); } } TEST( R1_Distance, NegativeSide ) { for ( double distance = 0.0; distance <= 10.0; distance += 5.0 ) { R1::BackwardDistance d{ distance }; ASSERT_NEAR( d.m_distance.m_distance, distance, R1::Distance::Epsilon() ); ASSERT_TRUE( d.IsValid() ); } } TEST( R1_Distance, PositiveSide ) { for ( double distance = 0.0; distance <= 10.0; distance += 5.0 ) { R1::ForwardDistance d{ distance }; ASSERT_NEAR( d.m_distance.m_distance, distance, R1::Distance::Epsilon() ); ASSERT_TRUE( d.IsValid() ); } } TEST( R1_Range, DefaultConstructor ) { R1::Range r{}; ASSERT_TRUE( r.IsEmpty() ); ASSERT_FALSE( r.Contains( 0. ) ); } TEST( R1_Range, ConstructorOneValue ) { for ( double value = -10.; value <= 10.0; value += 5.0 ) { R1::Range r{ value }; ASSERT_TRUE( r.Contains( value ) ); ASSERT_FALSE( r.Contains( value + R1::Distance::Epsilon() ) ); ASSERT_FALSE( r.Contains( value - R1::Distance::Epsilon() ) ); ASSERT_FALSE( r.IsEmpty() ); } } TEST( R1_Range, ConstructorTwoValuesAscending ) { R1::Range r{ 0., 10. }; ASSERT_TRUE( r.Contains( 3. ) ); ASSERT_FALSE( r.Contains( 12. ) ); ASSERT_FALSE( r.Contains( -120. ) ); ASSERT_FALSE( r.IsEmpty() ); } TEST( R1_Range, ConstructorTwoValuesDescending ) { R1::Range r{ 10., 3. }; ASSERT_TRUE( r.Contains( 3. ) ); ASSERT_FALSE( r.Contains( 12. ) ); ASSERT_FALSE( r.Contains( -120. ) ); ASSERT_FALSE( r.IsEmpty() ); } TEST(R1_Range, Empty) { R1::Range r; ASSERT_TRUE( r.IsEmpty() ); r.Append( 3. ); ASSERT_FALSE( r.IsEmpty() ); r.SetEmpty(); ASSERT_TRUE( r.IsEmpty() ); } TEST(R1_Range, InterpositionNotAppliable) { const R1::Range r1{}, r2{ 0. }; ASSERT_EQ( Interposition::notAppliable, r1.InterpositionWith( r2 ) ); ASSERT_EQ( Interposition::notAppliable, r2.InterpositionWith( r1 ) ); ASSERT_EQ( Interposition::notAppliable, r1.InterpositionWith( r1 ) ); ASSERT_NE( Interposition::notAppliable, r2.InterpositionWith( r2 ) ); } TEST( R1_Range, InterpositionSame ) { const R1::Range r1{0., 0.}, r2{ 0. }; ASSERT_EQ( Interposition::same, r1.InterpositionWith( r2 ) ); ASSERT_EQ( Interposition::same, r2.InterpositionWith( r1 ) ); } TEST( R1_Range, InterpositionConainsIncluded ) { const R1::Range r1{ -10., 10. }, r2{ 0., 1. }; ASSERT_EQ( Interposition::contains, r1.InterpositionWith( r2 ) ); ASSERT_EQ( Interposition::included, r2.InterpositionWith( r1 ) ); } TEST( R1_Range, InterpositionIntersect ) { const R1::Range r1{ -10., 10. }, r2{ 0., 18. }; ASSERT_EQ( Interposition::intersected, r1.InterpositionWith( r2 ) ); ASSERT_EQ( Interposition::intersected, r2.InterpositionWith( r1 ) ); } TEST( R1_Range, InterpositionIsolated ) { const R1::Range r1{ -10., 10. }, r2{ 20., 18. }; ASSERT_EQ( Interposition::isolated, r1.InterpositionWith( r2 ) ); ASSERT_EQ( Interposition::isolated, r2.InterpositionWith( r1 ) ); }