rational: fixed NaN

Also added tests to ensure rational NaN behavior is tested.
This commit is contained in:
itsmattkc
2021-04-23 14:48:22 +10:00
parent ed542f0842
commit 7f93ed7fc0
5 changed files with 98 additions and 13 deletions
+1
View File
@@ -66,4 +66,5 @@ function(olive_add_test GROUP NAME SOURCE)
endfunction()
add_subdirectory(compositing)
add_subdirectory(general)
add_subdirectory(timeline)
+17
View File
@@ -0,0 +1,17 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2021 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
olive_add_test(General rational-tests rational-tests.cpp)
+64
View File
@@ -0,0 +1,64 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2021 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "testutil.h"
#include "common/rational.h"
namespace olive {
OLIVE_ADD_TEST(RationalDefaults)
{
// By default, rationals are valid 0/1
rational basic_constructor;
OLIVE_ASSERT(basic_constructor.isNull());
OLIVE_ASSERT(!basic_constructor.isNaN());
OLIVE_TEST_END;
}
OLIVE_ADD_TEST(RationalNaN)
{
// Create a NaN with a 0 denominator
rational nan = rational(0, 0);
OLIVE_ASSERT(nan.isNaN());
OLIVE_ASSERT(nan.isNull());
// Create a non-NaN with a zero numerator
rational zero_nonnan(0, 999);
OLIVE_ASSERT(zero_nonnan.isNull());
OLIVE_ASSERT(!zero_nonnan.isNaN());
// Create a non-NaN with a non-zero numerator
rational nonzer_nonnan(1, 30);
OLIVE_ASSERT(!nonzer_nonnan.isNull());
OLIVE_ASSERT(!nonzer_nonnan.isNaN());
OLIVE_TEST_END;
}
OLIVE_ADD_TEST(RationalNaNConstant)
{
OLIVE_ASSERT(rational::NaN.isNaN());
OLIVE_TEST_END;
}
}