• R/O
  • SSH
  • HTTPS

eirrepo: Commit


Commit MetaInfo

Revision172 (tree)
Time2018-12-25 23:30:30
Authorquiret

Log Message

- fixed some bugs with equal bounds but different included-status

Change Summary

Incremental Difference

--- common/sdk/MathSlice.h (revision 171)
+++ common/sdk/MathSlice.h (revision 172)
@@ -252,7 +252,7 @@
252252 }
253253 else if constexpr ( std::is_floating_point <numberType>::value )
254254 {
255- bool isSameIncluded = ( right.data.isIncluded );
255+ bool isSameIncluded = ( right.data.isIncluded || !left.data.isIncluded );
256256
257257 if ( isSameIncluded )
258258 {
@@ -467,7 +467,7 @@
467467 }
468468 else if constexpr ( std::is_floating_point <numberType>::value )
469469 {
470- bool isSameIncluded = ( left.data.isIncluded );
470+ bool isSameIncluded = ( left.data.isIncluded || !right.data.isIncluded );
471471
472472 if ( isSameIncluded )
473473 {
@@ -636,7 +636,25 @@
636636 }
637637 else if constexpr ( std::is_floating_point <numberType>::value )
638638 {
639- return eir::DefaultValueCompare( low.get_value(), high.get_value() );
639+ numberType lowBound = low.get_value();
640+ numberType highBound = high.get_value();
641+
642+ if ( lowBound < highBound )
643+ {
644+ return eCompResult::LEFT_LESS;
645+ }
646+ if ( lowBound > highBound )
647+ {
648+ return eCompResult::LEFT_GREATER;
649+ }
650+
651+ // Equality if the hard case.
652+ if ( low.is_included() == false || high.is_included() == false )
653+ {
654+ return eCompResult::LEFT_GREATER;
655+ }
656+
657+ return eCompResult::EQUAL;
640658 }
641659 else
642660 {
@@ -651,21 +669,9 @@
651669 template <typename numberType>
652670 AINLINE bool operator <= ( const lowerBound <numberType>& left, const upperBound <numberType>& right ) noexcept
653671 {
654- bool isSameIncluded = ( left.is_included() && right.is_included() );
655-
656672 eCompResult cmpRes = compare_bounds( left, right );
657673
658- if ( cmpRes == eCompResult::LEFT_GREATER )
659- {
660- return false;
661- }
662-
663- if ( isSameIncluded == false && cmpRes == eCompResult::EQUAL )
664- {
665- return false;
666- }
667-
668- return true;
674+ return ( cmpRes == eCompResult::LEFT_LESS || cmpRes == eCompResult::EQUAL );
669675 }
670676 template <typename numberType>
671677 AINLINE bool operator > ( const lowerBound <numberType>& left, const upperBound <numberType>& right ) noexcept
@@ -688,21 +694,9 @@
688694 template <typename numberType>
689695 AINLINE bool operator <= ( const upperBound <numberType>& left, const lowerBound <numberType>& right ) noexcept
690696 {
691- bool isSameIncluded = ( left.is_included() && right.is_included() );
692-
693697 eCompResult cmpRes = compare_bounds( right, left );
694698
695- if ( cmpRes == eCompResult::LEFT_LESS )
696- {
697- return false;
698- }
699-
700- if ( isSameIncluded == false && eCompResult::EQUAL )
701- {
702- return false;
703- }
704-
705- return true;
699+ return ( cmpRes == eCompResult::LEFT_GREATER || cmpRes == eCompResult::EQUAL );
706700 }
707701 template <typename numberType>
708702 AINLINE bool operator > ( const upperBound <numberType>& left, const lowerBound <numberType>& right ) noexcept
--- unittests/src/mathslice.cpp (revision 171)
+++ unittests/src/mathslice.cpp (revision 172)
@@ -91,6 +91,22 @@
9191 assert( excludedBound.is_bounded( 5 ) == true );
9292 assert( excludedBound.is_bounded( 3 ) == false );
9393 }
94+
95+ // Non-trivial float.
96+ {
97+ eir::lowerBound <float> included( 4, true );
98+ eir::lowerBound <float> excluded( 4, false );
99+
100+ assert( included == included );
101+ assert( included <= included );
102+ assert( included <= excluded );
103+ assert( included < excluded );
104+ assert( excluded <= excluded );
105+ assert( excluded >= excluded );
106+ assert( excluded == excluded );
107+ assert( excluded >= included );
108+ assert( excluded > included );
109+ }
94110 }
95111 printf( "ok.\n" );
96112
@@ -169,6 +185,19 @@
169185 assert( minus_one.is_included() == true );
170186 }
171187
188+ // non-trivial float.
189+ {
190+ eir::upperBound <float> included( 5, true );
191+ eir::upperBound <float> excluded( 5, false );
192+
193+ assert( included == included );
194+ assert( included <= included );
195+ assert( included >= included );
196+ assert( excluded <= included );
197+ assert( excluded < included );
198+ assert( excluded == excluded );
199+ }
200+
172201 // unsigned int
173202 {
174203 eir::upperBound <unsigned int> bound( std::numeric_limits <unsigned int>::max() );
@@ -312,6 +341,18 @@
312341 }
313342 printf( "ok.\n" );
314343
344+ printf( "testing slice emptiness..." );
345+ {
346+ // float
347+ {
348+ assert( eir::mathSlice <float>::fromOffsets( 0, 0, true, true ).IsEmpty() == false );
349+ assert( eir::mathSlice <float>::fromOffsets( 0, 0, true, false ).IsEmpty() == true );
350+ assert( eir::mathSlice <float>::fromOffsets( 0, 0, false, true ).IsEmpty() == true );
351+ assert( eir::mathSlice <float>::fromOffsets( 0, 0, false, false ).IsEmpty() == true );
352+ }
353+ }
354+ printf( "ok.\n" );
355+
315356 printf( "testing slice intersect equal..." );
316357 {
317358 // unsigned
Show on old repository browser