Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shippableでDxLib非依存部分のCIとTestをやる作業 #86

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b321e8b
add iutest as submodule
yumetodo Aug 6, 2016
0d2118d
add testcase(initial)
yumetodo Aug 6, 2016
8b932f1
add test case : point_c class operator-, operator-=
yumetodo Aug 6, 2016
842eb44
型付けテストに書き換え
yumetodo Aug 7, 2016
46ece80
fix typo
yumetodo Aug 7, 2016
3bf46d2
delim char should be written by variable-template-like template function
yumetodo Aug 7, 2016
a7bf11b
write istream/ostream operator test
yumetodo Aug 7, 2016
410967d
write mul operators test
yumetodo Aug 7, 2016
5887649
fix macro name
yumetodo Aug 7, 2016
f711d69
test_point_c_test : add test for div operators
yumetodo Aug 7, 2016
4862b51
test_point_c_test : add test for abs free function without for unsign…
yumetodo Aug 7, 2016
1f11f38
test_point_c_test : add testcase for dot product function
yumetodo Aug 8, 2016
354aab8
Merge branch 'master' into use_iutest
yumetodo Aug 8, 2016
0101daf
fix compile error on VS2013
yumetodo Aug 8, 2016
460ed72
test_point_c_test : fix compile error on VS2013
yumetodo Aug 8, 2016
cb5fef6
Merge branch 'master' into use_iutest
yumetodo Aug 8, 2016
e073b80
test_point_c_test : add test for abs free function whitch takes unsig…
yumetodo Aug 8, 2016
3f35e8c
Merged branch master into use_iutest
yumetodo Nov 26, 2016
032de7e
project setting: support vs2017
yumetodo Nov 26, 2016
70384fb
update gitignore for VS2017 and test
yumetodo Nov 26, 2016
ed073ba
remove dead file from project
yumetodo Nov 26, 2016
9dc93c9
remove trailing space
yumetodo Nov 26, 2016
df9f9f9
use function-pointer as seed source (expect ASLR)
yumetodo Nov 26, 2016
2dfa583
add macro DXLE_UNUSED
yumetodo Nov 27, 2016
01133ca
use DXLE_UNUSED
yumetodo Nov 27, 2016
5414376
fix compile error
yumetodo Nov 27, 2016
5c6eecd
change file path
yumetodo Nov 27, 2016
467db6a
specify inline
yumetodo Nov 27, 2016
8866c92
add testcase for size_c
yumetodo Nov 27, 2016
10aec5a
見た目の修正
yumetodo Nov 27, 2016
8d9d446
fix compile error
yumetodo Nov 27, 2016
21ffdb2
add testcase for point3d
yumetodo Nov 27, 2016
18c825c
point3d: fix operator==(nullptr_t, this)
yumetodo Nov 27, 2016
ce7685c
fix testcase
yumetodo Nov 27, 2016
f96267c
point3d: fix operator*(T1, this)
yumetodo Nov 27, 2016
92dc867
project setting: support vs2017 Clang CodeGen
yumetodo Nov 27, 2016
10e9183
project setting: more support vs2017 Clang CodeGen
yumetodo Nov 27, 2016
d209cd6
point3d_c: dot: add testcase
yumetodo Nov 27, 2016
287d874
point3d_c: cross: add testcase
yumetodo Nov 27, 2016
1651c24
point_c/point3d_c: distance: add testcase
yumetodo Nov 28, 2016
7e09192
update iutest
yumetodo Dec 7, 2016
91390a7
Merged branch master into use_iutest
yumetodo Dec 15, 2016
5c4b771
Merge branch 'master'
yumetodo Jan 1, 2017
f6677d1
A HAPPY NEW YEAR!
yumetodo Jan 1, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "3rd_party/iutest"]
path = 3rd_party/iutest
url = https://github.com/srz-zumix/iutest.git
1 change: 1 addition & 0 deletions 3rd_party/iutest
Submodule iutest added at 8ebf87
2 changes: 1 addition & 1 deletion dxlibex/basic_types/distance_result_type_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace dxle {
template<typename T>
struct distance_result_type_impl<T, false, true> {
typedef T type;
};
};
template<typename T>
struct distance_result_type_impl<T, true, false> {
typedef double type;//If any argument has integral type, it is cast to double.
Expand Down
4 changes: 2 additions & 2 deletions dxlibex/basic_types/point2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ namespace dxle {
\~english @return Computed result.
*/
template<typename T1, typename T2>
DXLE_CONSTEXPR double cross(const point_c<T1>& p1, const point_c<T2>& p2)
DXLE_CONSTEXPR double cross(const point_c<T1>& p1, const point_c<T2>& p2)
DXLE_NOEXCEPT_IF_EXPR((
static_cast_if<T1, double, !std::is_floating_point<T1>::value>(std::declval<T1>()) * std::declval<T2>()
+ static_cast_if<T1, double, !std::is_floating_point<T1>::value>(std::declval<T1>()) * std::declval<T2>()
Expand All @@ -657,7 +657,7 @@ namespace dxle {
\~english @return Computed result.
*/
template<typename T1, typename T2>
distance_result_type_t<T1, T2> distance(const point_c<T1>& p1, const point_c<T2>& p2)
distance_result_type_t<T1, T2> distance(const point_c<T1>& p1, const point_c<T2>& p2)
DXLE_NOEXCEPT_IF_EXPR(hypot(safe_dist(std::declval<T1>(), std::declval<T2>()), safe_dist(std::declval<T1>(), std::declval<T2>())))
{
return hypot(safe_dist(p1.x, p2.x), safe_dist(p1.y, p2.y));
Expand Down
4 changes: 2 additions & 2 deletions dxlibex/basic_types/point3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ namespace dxle {
//!1. operator bool
//!2. operator != (nullptr)
//!3. default constector + operator !=
DXLE_CONSTEXPR explicit operator bool()
DXLE_CONSTEXPR explicit operator bool()
const DXLE_NOEXCEPT_IF_EXPR((dxle::detail::operator_bool_helper(std::declval<value_type>(), std::declval<value_type>(), std::declval<value_type>())))
{
return dxle::detail::operator_bool_helper(this->x, this->y, this->z);
Expand Down Expand Up @@ -640,7 +640,7 @@ namespace dxle {
\~japanese @return 計算結果。
\~english @return Computed result.
*/
template<typename T1, typename T2>
template<typename T1, typename T2>
distance_result_type_t<T1, T2> distance(const point3d_c<T1>& p1, const point3d_c<T2>& p2)
DXLE_NOEXCEPT_IF_EXPR(hypot(safe_dist(std::declval<T1>(), std::declval<T2>()), safe_dist(std::declval<T1>(), std::declval<T2>())))
{
Expand Down
51 changes: 51 additions & 0 deletions tests/include/math.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*=============================================================================
Copyright (C) 2015-2017 DxLibEx project
https://github.com/Nagarei/DxLibEx/

Distributed under the Boost Software License, Version 1.0.
(See http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef DXLE_TESTS_INCLUDE_MATH_HPP_
#define DXLE_TESTS_INCLUDE_MATH_HPP_
namespace detail {
template<typename T, bool is_unsigned = std::is_unsigned<T>::value>
struct inferior_sqrt_helper {
T operator()(T x) { return static_cast<T>(::std::sqrt(x)); }
};
template<typename T>
struct inferior_sqrt_helper<T, false> {
T operator()(T x) { return (x < 0) ? 0 : static_cast<T>(::std::sqrt(x)); }
};
}
template<typename T>
T inferior_sqrt(T x) { return detail::inferior_sqrt_helper<T>()(x); }
inline std::uint64_t inferior_sqrt(const std::uint64_t x)
{
if (x < static_cast<std::uint64_t>(std::numeric_limits<double>::max())) return static_cast<std::uint64_t>(::std::sqrt(x));
std::uint64_t s = 1U;
auto t = x;
while (s < t) { s <<= 1; t >>= 1; }
do {
t = s;
s = (x / s + s) >> 1;
} while (s < t);
return t;
}
inline std::int64_t inferior_sqrt(const std::int64_t x)
{
return (x < 0) ? 0 : x < static_cast<std::int64_t>(std::numeric_limits<double>::max()) ? static_cast<std::int64_t>(::std::sqrt(x))
: static_cast<std::int64_t>(inferior_sqrt(static_cast<std::uint64_t>(x)));
}
namespace detail {
template<typename T, bool is_unsigned = std::is_unsigned<T>::value>
struct inferior_sqrt2_helper {
T operator()(T x) { return inferior_sqrt(x); }
};
template<typename T>
struct inferior_sqrt2_helper<T, false> {
T operator()(T x) { return (x < 0) ? -inferior_sqrt(-x) : inferior_sqrt(x); }
};
}
template<typename T>
T inferior_sqrt2(T x) { return detail::inferior_sqrt2_helper<T>()(x); }
#endif //DXLE_TESTS_INCLUDE_MATH_HPP_
241 changes: 241 additions & 0 deletions tests/include/random.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
/*=============================================================================
Copyright (C) 2015-2017 DxLibEx project
https://github.com/Nagarei/DxLibEx/

Distributed under the Boost Software License, Version 1.0.
(See http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef DXLE_TESTS_INCLUDE_RANDOM_HPP_
#define DXLE_TESTS_INCLUDE_RANDOM_HPP_
#if defined(__MINGW32__) && !defined(__clang__)
//mingw-gcc's std::randome_device is broken.
//gccをwindowsで使うならstd::random_deviceを使ってはいけない - Qiita
//http://qiita.com/nanashi/items/f94b78398a6c79d939e1
# define _CRT_RAND_S
# include <stdlib.h> //rand_s
# include <thread>
#endif //defined(__MINGW32__) && !defined(__clang__)
#if defined(_WIN32) || defined(_WIN64)
# define DXLE_ARC_FOR_WINDWOS 1
# if !defined(CINTERFACE) && defined(__c2__) && __clang_major__ == 3 && __clang_minor__ == 8
//To avoid compile error
//C:\Program Files (x86)\Windows Kits\8.1\Include\um\combaseapi.h(229,21): error : unknown type name 'IUnknown'
// static_cast<IUnknown*>(*pp); // make sure everyone derives from IUnknown
# define CINTERFACE
# endif
# include <Windows.h>
# include <tchar.h>
#elif defined(__linux__)
# define DXLE_ARC_FOR_LINUX 1
# include <sys/types.h>
# include <unistd.h>
# include <fstream>
namespace dxle {
inline unsigned int get_randome_from_dev_random() {
std::ifstream file("/dev/random", std::ios::binary);
if (file.is_open())
{
char buf[sizeof(unsigned int)];
file.read(buf, sizeof(unsigned int));
file.close();
return *reinterpret_cast<int*>(buf);
}
return 0;
}
}
#endif
#include <dxlibex/config/defines.h>
#include <random>
#include <memory>
#include <algorithm>//std::generate
#include <ctime>//clock(), time()
#include <functional>//std::ref in gcc
#include <chrono>
#include <cstdint>
#include <cstring>
#include <vector>
#include <dxlibex/type_traits.hpp>
#if !defined(__c2__) || (defined(__clang__) && (__clang_major__ >= 4 ) || __clang_major__ == 3 && __clang_minor__ >= 9)//古いClang with Microsoft CodeGenはasmに対応していない
# ifndef __INTEL_COMPILER
# include <immintrin.h>
# if defined(_WIN32) || defined(_WIN64)
# include <intrin.h>
# else
# include <x86intrin.h>
# endif //defined(_WIN32) || defined(_WIN64)
# ifdef __GNUC__
# include <cpuid.h>
# endif //__GNUC__
# endif //__INTEL_COMPILER
namespace dxle {
using std::uint32_t;
namespace intrin {
struct regs_t { uint32_t EAX, EBX, ECX, EDX; };
union register_str_cvt {
uint32_t u32[3];
char str[12];
};
inline regs_t get_cpuid(unsigned int level) {
regs_t re = { 0 };
static_assert(sizeof(re) == (sizeof(uint32_t) * 4), "illegal size of struct regs_t ");
# if defined(__INTEL_COMPILER) || defined(_MSC_VER) && !defined(__clang__)
__cpuid(reinterpret_cast<int*>(&re), static_cast<int>(level));
# elif defined(__GNUC__)
__get_cpuid(level, &re.EAX, &re.EBX, &re.ECX, &re.EDX);
# endif
return re;
}
inline bool check_vender(const char* s) {
const auto id = get_cpuid(0);
register_str_cvt vender = { { id.EBX, id.EDX, id.ECX } };
return (0 == std::memcmp(vender.str, s, sizeof(vender.str)));
}
inline bool IsIntelCPU() {
static const auto is_intel_cpu = check_vender("GenuineIntel");//実行中にCPUは変わらないとする
return is_intel_cpu;
}
inline bool IsAMDCPU() {
static const auto is_amd_cpu = check_vender("AuthenticAMD");
return is_amd_cpu;
}
inline bool IsRDRANDsupport() {
DXLE_STATIC_CONSTEXPR uint32_t RDRAND_MASK = 1U << 30U;
if (!IsIntelCPU() && !IsAMDCPU()) return false;
const auto reg = get_cpuid(1);//If RDRAND is supported, the bit 30 of the ECX register is set after calling CPUID standard function 01H.
return (RDRAND_MASK == (reg.ECX & RDRAND_MASK));
}
inline bool IsRDSEEDsupport() {
DXLE_STATIC_CONSTEXPR uint32_t RDSEED_MASK = 1U << 18U;
if (!IsIntelCPU()) return false;
const auto reg = get_cpuid(7);//If RDSEED is supported, the bit 18 of the EBX register is set after calling CPUID standard function 07H.
return (RDSEED_MASK == (reg.EBX & RDSEED_MASK));
}
}
}
#else
# define DXLE_NO_ASM
#endif//!defined(_MSC_VER) || !defined(__clang__)
namespace dxle {
namespace detail {
template<typename Pointer>
struct vector_push_back_helper {
Pointer value;
};
template<typename value_type, typename T, bool T_is_larger>
struct vector_push_back_operator_impl {
void operator()(std::vector<value_type>& v, vector_push_back_helper<T> info) {
if (info.value) v.push_back((value_type)(info.value));
}
};
template<typename value_type>
struct vector_push_back_operator_impl<value_type, value_type, false> {
void operator()(std::vector<value_type>& v, vector_push_back_helper<value_type> info) {
if (info.value) v.push_back(info.value);
}
};
template<typename value_type, typename T>
struct vector_push_back_operator_impl<value_type, T, true> {
void operator()(std::vector<value_type>& v, vector_push_back_helper<T> info) {
DXLE_STATIC_CONSTEXPR size_t size_time = sizeof(T) / sizeof(value_type);
DXLE_STATIC_CONSTEXPR size_t rshft_num = sizeof(value_type) * CHAR_BIT;
for (size_t i = 0; i < size_time; ++i) {
const auto tmp = static_cast<value_type>((std::uintmax_t)(info.value) >> (rshft_num * i));
if (tmp) v.push_back(tmp);
}
}
};
template<typename value_type, typename T, std::enable_if_t<std::is_pointer<T>::value || std::is_arithmetic<T>::value, std::nullptr_t> = nullptr>
inline void operator| (std::vector<value_type>& v, vector_push_back_helper<T> info) {
vector_push_back_operator_impl<value_type, T, (sizeof(value_type) < sizeof(T))> ()(v, info);
}
}
}
namespace dxle {
template<typename T>
dxle::detail::vector_push_back_helper<T> push_back(T pointer) { return{ pointer }; }
using seed_v_t = std::vector<unsigned int>;
inline seed_v_t create_seed_v() {
const auto begin_time = std::chrono::high_resolution_clock::now();
#if defined(__c2__) && __clang_minor__ < 9
constexpr std::size_t randome_device_generate_num = 12;//Clnag with Microsoft CodeGen does not support RDRND/RDSEED so that use std::random_device agressively.
#else
DXLE_STATIC_CONSTEXPR std::size_t randome_device_generate_num = 9;
#endif
seed_v_t sed_v(randome_device_generate_num);// 初期化用ベクター
#ifndef _CRT_RAND_S
std::random_device rnd;// ランダムデバイス
std::generate(sed_v.begin(), sed_v.end(), std::ref(rnd));// ベクタの初期化
#else //_CRT_RAND_S
std::generate(sed_v.begin(), sed_v.end(), []() {
unsigned int re;
if (rand_s(&re)) {
std::this_thread::sleep_for(std::chrono::milliseconds(300));
if (auto err = rand_s(&re)) throw std::runtime_error("rand_s failed. error code:" + std::to_string(err));
}
return re;
});// ベクタの初期化
#endif //_CRT_RAND_S
#ifndef DXLE_NO_ASM
if (intrin::IsRDRANDsupport()) {//RDRAND命令の結果もベクターに追加
for (unsigned int i = 0; i < 4; i++) {
unsigned int rdrand_value = 0;
# if defined(_MSC_VER) || defined(__INTEL_COMPILER)
_rdrand32_step(&rdrand_value);
# else//defined(_MSC_VER) || defined(__INTEL_COMPILER)
__builtin_ia32_rdrand32_step(&rdrand_value);
# endif//defined(_MSC_VER) || defined(__INTEL_COMPILER)
if (0 != rdrand_value) {
sed_v.push_back((rdrand_value < std::numeric_limits<decltype(rdrand_value)>::max() - i) ? rdrand_value + i : rdrand_value);
}
}
}
if (intrin::IsRDSEEDsupport()) {
for (unsigned int i = 0; i < 5; i++) {
unsigned int rdseed_value = 0;
# if defined(_MSC_VER) || defined(__INTEL_COMPILER)
_rdseed32_step(&rdseed_value);
# else//defined(_MSC_VER) || defined(__INTEL_COMPILER)
__builtin_ia32_rdseed32_step(&rdseed_value);
# endif//defined(_MSC_VER) || defined(__INTEL_COMPILER)
if (0 != rdseed_value) {
sed_v.push_back((rdseed_value < std::numeric_limits<decltype(rdseed_value)>::max() - i) ? rdseed_value + i : rdseed_value);
}
}
}
#endif//!defined(DXLE_NO_ASM)
#ifdef DXLE_ARC_FOR_WINDWOS
POINT point;
GetCursorPos(&point);
sed_v | push_back(point.x);
sed_v | push_back(point.y);
sed_v | push_back(GetCurrentProcessId());
#endif //DXLE_ARC_FOR_WINDWOS
#ifdef DXLE_ARC_FOR_LINUX
sed_v | push_back(get_randome_from_dev_random());
sed_v | push_back(getppid());
sed_v | push_back(get_randome_from_dev_random());
#endif
sed_v | push_back(clock());//clock関数の結果もベクターに追加
sed_v | push_back(time(nullptr));//time関数の結果もベクターに追加
//ヒープ領域のアドレスもベクターに追加
auto heap = std::make_unique<char>();
sed_v | push_back(heap.get());
sed_v | push_back(&heap);
sed_v | push_back(time);
const auto end_time = std::chrono::high_resolution_clock::now();
sed_v | push_back((end_time - begin_time).count());
return sed_v;
}
inline std::mt19937 create_engine() {
auto sed_v = create_seed_v();
std::seed_seq seq(sed_v.begin(), sed_v.end());
return std::mt19937(seq);
}
template<typename T>
using uniform_normal_distribution = dxle::first_enabled_t<
std::enable_if<std::is_integral<T>::value, std::uniform_int_distribution<T>>,
std::enable_if<std::is_floating_point<T>::value, std::uniform_real_distribution<T>>
>;
}
extern std::mt19937 engine;
#endif //DXLE_TESTS_INCLUDE_RANDOM_HPP_
Loading