actually commit new digit header and tests
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/***
|
||||
|
||||
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/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef DIGIT_H
|
||||
#define DIGIT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace olive {
|
||||
|
||||
inline int64_t GetDigitCount(int64_t input)
|
||||
{
|
||||
input = std::abs(input);
|
||||
|
||||
int64_t lim = 10;
|
||||
int64_t digit = 1;
|
||||
|
||||
while (input >= lim) {
|
||||
lim *= 10;
|
||||
digit++;
|
||||
}
|
||||
|
||||
return digit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // DIGIT_H
|
||||
@@ -23,7 +23,7 @@ function(olive_add_test GROUP NAME SOURCE)
|
||||
foreach (TEST_FUNC ${TEST_FUNCTIONS})
|
||||
string(REPLACE "OLIVE_ADD_TEST(" "" TEST_FUNC "${TEST_FUNC}")
|
||||
string(APPEND TEST_BODY " std::cout << \"[${TEST_INDEX}/${TEST_COUNT}] ${GROUP} - ${TEST_FUNC}\";\n")
|
||||
string(APPEND TEST_BODY " if (olive::Test${TEST_FUNC}()) {std::cout << \" - PASSED\" << std::endl;}else{std::cout << \" - FAILED\" << std::endl;return 1;\n}\n")
|
||||
string(APPEND TEST_BODY " if (olive::Test${TEST_FUNC}()) {std::cout << \" - PASSED\" << std::endl;}else{std::cout << \" - FAILED\" << std::endl;return 1;}\n")
|
||||
MATH(EXPR TEST_INDEX "${TEST_INDEX}+1")
|
||||
endforeach()
|
||||
string(APPEND TEST_BODY " return 0;\n}")
|
||||
|
||||
@@ -14,4 +14,5 @@
|
||||
# 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 common-tests common-tests.cpp)
|
||||
olive_add_test(General rational-tests rational-tests.cpp)
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/***
|
||||
|
||||
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/digit.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
OLIVE_ADD_TEST(DigitTest)
|
||||
{
|
||||
OLIVE_ASSERT(GetDigitCount(1) == 1);
|
||||
OLIVE_ASSERT(GetDigitCount(69) == 2);
|
||||
OLIVE_ASSERT(GetDigitCount(420) == 3);
|
||||
OLIVE_ASSERT(GetDigitCount(1337) == 4);
|
||||
OLIVE_ASSERT(GetDigitCount(80085) == 5);
|
||||
OLIVE_ASSERT(GetDigitCount(555555) == 6);
|
||||
OLIVE_ASSERT(GetDigitCount(8675309) == 7);
|
||||
OLIVE_ASSERT(GetDigitCount(78956423) == 8);
|
||||
OLIVE_ASSERT(GetDigitCount(148497523) == 9);
|
||||
OLIVE_ASSERT(GetDigitCount(4845821233) == 10);
|
||||
OLIVE_ASSERT(GetDigitCount(18002738255) == 11);
|
||||
OLIVE_ASSERT(GetDigitCount(180027382556) == 12);
|
||||
OLIVE_ASSERT(GetDigitCount(1800273825568) == 13);
|
||||
OLIVE_ASSERT(GetDigitCount(18002738255685) == 14);
|
||||
OLIVE_ASSERT(GetDigitCount(180027382556857) == 15);
|
||||
OLIVE_ASSERT(GetDigitCount(1800273825564857) == 16);
|
||||
|
||||
OLIVE_TEST_END;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define OLIVE_ASSERT(x) if (!(x)) return false
|
||||
#define OLIVE_TEST_END return true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user