From b321e8bb32d4722787ddb8d09cb799e9bae982c6 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 6 Aug 2016 19:22:16 +0900 Subject: [PATCH 01/39] add iutest as submodule --- .gitmodules | 3 +++ 3rd_party/iutest | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 3rd_party/iutest diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8423d15 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "3rd_party/iutest"] + path = 3rd_party/iutest + url = https://github.com/srz-zumix/iutest.git diff --git a/3rd_party/iutest b/3rd_party/iutest new file mode 160000 index 0000000..85a76d4 --- /dev/null +++ b/3rd_party/iutest @@ -0,0 +1 @@ +Subproject commit 85a76d4d843fd93d3bd00f45975bc137160aada2 From 0d2118d959228314d39156b01af725d408b465b3 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 6 Aug 2016 19:23:05 +0900 Subject: [PATCH 02/39] add testcase(initial) --- tests/no_dxlib.sln | 40 ++ tests/no_dxlib/basic_types_2d.hpp | 54 --- tests/no_dxlib/no_dxlib.vcxproj | 68 ++- tests/no_dxlib/no_dxlib.vcxproj.filters | 3 +- tests/no_dxlib/no_dxlib_test.cpp | 9 +- tests/no_dxlib/random.hpp | 241 +++++++++++ tests/no_dxlib/test_point_c.hpp | 543 ++++++++++++++++++++++++ tests/with_dxLib/with_dxLib_test.cpp | 2 +- 8 files changed, 898 insertions(+), 62 deletions(-) create mode 100644 tests/no_dxlib.sln delete mode 100644 tests/no_dxlib/basic_types_2d.hpp create mode 100644 tests/no_dxlib/random.hpp create mode 100644 tests/no_dxlib/test_point_c.hpp diff --git a/tests/no_dxlib.sln b/tests/no_dxlib.sln new file mode 100644 index 0000000..df15076 --- /dev/null +++ b/tests/no_dxlib.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "no_dxlib", "no_dxlib\no_dxlib.vcxproj", "{44682BAF-4F62-42D9-90EB-D7F46CD21B95}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + clang_Debug|x64 = clang_Debug|x64 + clang_Debug|x86 = clang_Debug|x86 + clang_Release|x64 = clang_Release|x64 + clang_Release|x86 = clang_Release|x86 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Debug|x64.ActiveCfg = clang_Debug|x64 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Debug|x64.Build.0 = clang_Debug|x64 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Debug|x86.ActiveCfg = clang_Debug|Win32 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Debug|x86.Build.0 = clang_Debug|Win32 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Release|x64.ActiveCfg = clang_Release|x64 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Release|x64.Build.0 = clang_Release|x64 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Release|x86.ActiveCfg = clang_Release|Win32 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Release|x86.Build.0 = clang_Release|Win32 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.Debug|x64.ActiveCfg = Debug|x64 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.Debug|x64.Build.0 = Debug|x64 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.Debug|x86.ActiveCfg = Debug|Win32 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.Debug|x86.Build.0 = Debug|Win32 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.Release|x64.ActiveCfg = Release|x64 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.Release|x64.Build.0 = Release|x64 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.Release|x86.ActiveCfg = Release|Win32 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/tests/no_dxlib/basic_types_2d.hpp b/tests/no_dxlib/basic_types_2d.hpp deleted file mode 100644 index 45f81c5..0000000 --- a/tests/no_dxlib/basic_types_2d.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/*============================================================================= - Copyright (C) 2015-2016 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) -=============================================================================*/ -#include -#include -#define BOOST_TEST_MODULE basic_types_2d -#define BOOST_TEST_NO_LIB -#include "boost/test/included/unit_test.hpp" -#include - - -BOOST_AUTO_TEST_CASE(opertor_plus_minus_test) -{ - - auto seed = std::random_device{}(); - std::mt19937 engine(seed); - std::uniform_int_distribution<> dist(INT_MIN, INT_MAX); - auto get_rand = [&engine, &dist](){ return dist(engine); }; - - for (size_t i = 0; i < 10000; ++i) - { - int value_x = get_rand(); - int value_y = get_rand(); - - dxle::pointi point1{ value_x, value_y }; - - BOOST_CHECK_EQUAL(point1.x, value_x); - BOOST_CHECK_EQUAL(point1.y, value_y); - - dxle::pointi point2(3, 2); - dxle::pointi point3 = point1 + point2; - BOOST_CHECK_EQUAL(point3.x, value_x + 3); - BOOST_CHECK_EQUAL(point3.y, value_y + 2); - - auto point4 = point1 - point2; - BOOST_CHECK_EQUAL(point4.x, value_x - 3); - BOOST_CHECK_EQUAL(point4.y, value_y - 2); - - point1 += point2; - BOOST_CHECK_EQUAL(point1.x, value_x + 3); - BOOST_CHECK_EQUAL(point1.y, value_y + 2); - - point1 -= point2; - BOOST_CHECK_EQUAL(point1.x, value_x); - BOOST_CHECK_EQUAL(point1.y, value_y); - - } - - -} \ No newline at end of file diff --git a/tests/no_dxlib/no_dxlib.vcxproj b/tests/no_dxlib/no_dxlib.vcxproj index 819e0ca..dcde86e 100644 --- a/tests/no_dxlib/no_dxlib.vcxproj +++ b/tests/no_dxlib/no_dxlib.vcxproj @@ -1,6 +1,22 @@  + + clang_Debug + Win32 + + + clang_Debug + x64 + + + clang_Release + Win32 + + + clang_Release + x64 + Debug Win32 @@ -22,6 +38,7 @@ {44682BAF-4F62-42D9-90EB-D7F46CD21B95} Win32Proj no_dxlib + 8.1 @@ -47,6 +64,18 @@ true MultiByte + + v140_clang_c2 + + + v140_clang_c2 + + + v140_clang_c2 + + + v140_clang_c2 + @@ -83,7 +112,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\;$(BOOST_ROOT); + ..\..\; MultiThreadedDebug 4702 @@ -101,7 +130,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\;$(BOOST_ROOT); + ..\..\; MultiThreadedDebug 4702 @@ -121,7 +150,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\;$(BOOST_ROOT);%(AdditionalIncludeDirectories) + ..\..\; MultiThreaded 4702 @@ -143,7 +172,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\;$(BOOST_ROOT);%(AdditionalIncludeDirectories) + ..\..\; MultiThreaded 4702 @@ -155,11 +184,40 @@ ..\..\; + + + ..\..\; + Disabled + FullDebug + true + + + + + ..\..\; + Disabled + FullDebug + true + + + + + ..\..\; + true + + + + + ..\..\; + true + + - + + diff --git a/tests/no_dxlib/no_dxlib.vcxproj.filters b/tests/no_dxlib/no_dxlib.vcxproj.filters index b06d303..d46c1da 100644 --- a/tests/no_dxlib/no_dxlib.vcxproj.filters +++ b/tests/no_dxlib/no_dxlib.vcxproj.filters @@ -12,7 +12,8 @@ - + + ソース ファイル diff --git a/tests/no_dxlib/no_dxlib_test.cpp b/tests/no_dxlib/no_dxlib_test.cpp index 494710e..aaf1c6a 100644 --- a/tests/no_dxlib/no_dxlib_test.cpp +++ b/tests/no_dxlib/no_dxlib_test.cpp @@ -5,4 +5,11 @@ Copyright (C) 2015-2016 DxLibEx project Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#include "basic_types_2d.hpp" +#include "../../3rd_party/iutest/include/iutest.hpp" +#include "test_point_c.hpp" +std::mt19937 engine = dxle::create_engine(); +int main(int argc, char** argv) +{ + IUTEST_INIT(&argc, argv); + return IUTEST_RUN_ALL_TESTS(); +} diff --git a/tests/no_dxlib/random.hpp b/tests/no_dxlib/random.hpp new file mode 100644 index 0000000..af49fba --- /dev/null +++ b/tests/no_dxlib/random.hpp @@ -0,0 +1,241 @@ +/*============================================================================= +Copyright (C) 2015-2016 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_TEST_NO_DXLIB_RANDOM_HPP_ +#define DXLE_TEST_NO_DXLIB_RANDOM_HPP_ +#pragma once +#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 //rand_s +# include +#endif //defined(__MINGW32__) && !defined(__clang__) +#if defined(_WIN32) || defined(_WIN64) +# define MY_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(*pp); // make sure everyone derives from IUnknown +# define CINTERFACE +# endif +# include +# include +#elif defined(__linux__) +# define MY_ARC_FOR_LINUX 1 +# include +# include +# include +namespace dxle { + 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(buf); + } + return 0; + } +} +#endif +#include +#include +#include +#include //std::generate +#include //clock(), time() +#include //std::ref in gcc +#include +#include +#include +#include +#include +#if !defined(__c2__) || (defined(__clang__) && (__clang_major__ >= 4 ) || __clang_major__ == 3 && __clang_minor__ >= 9)//古いClang with Microsoft CodeGenはasmに対応していない +# ifndef __INTEL_COMPILER +# include +# if defined(_WIN32) || defined(_WIN64) +# include +# else +# include +# endif //defined(_WIN32) || defined(_WIN64) +# ifdef __GNUC__ +# include +# 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]; + }; + 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(&re), static_cast(level)); +# elif defined(__GNUC__) + __get_cpuid(level, &re.EAX, &re.EBX, &re.ECX, &re.EDX); +# endif + return re; + } + 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))); + } + bool IsIntelCPU() { + static const auto is_intel_cpu = check_vender("GenuineIntel");//実行中にCPUは変わらないとする + return is_intel_cpu; + } + bool IsAMDCPU() { + static const auto is_amd_cpu = check_vender("AuthenticAMD"); + return is_amd_cpu; + } + 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)); + } + 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 MY_NO_ASM +#endif//!defined(_MSC_VER) || !defined(__clang__) +namespace dxle { + namespace detail { + template + struct vector_push_back_helper { + Pointer value; + }; + template + struct vector_push_back_operator_impl { + void operator()(std::vector& v, vector_push_back_helper info) { + if (info.value) v.push_back((value_type)(info.value)); + } + }; + template + struct vector_push_back_operator_impl { + void operator()(std::vector& v, vector_push_back_helper info) { + if (info.value) v.push_back(info.value); + } + }; + template + struct vector_push_back_operator_impl { + void operator()(std::vector& v, vector_push_back_helper 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((std::uintmax_t)(info.value) >> (rshft_num * i)); + if (tmp) v.push_back(tmp); + } + } + }; + template::value || std::is_arithmetic::value, std::nullptr_t> = nullptr> + void operator| (std::vector& v, vector_push_back_helper info) { + vector_push_back_operator_impl ()(v, info); + } + } +} +namespace dxle { + template + dxle::detail::vector_push_back_helper push_back(T pointer) { return{ pointer }; } + using seed_v_t = std::vector; + 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 MY_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::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::max() - i) ? rdseed_value + i : rdseed_value); + } + } + } +#endif//!defined(MY_NO_ASM) +#ifdef MY_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 //MY_ARC_FOR_WINDWOS +#ifdef MY_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(); + sed_v | push_back(heap.get()); + sed_v | push_back(&heap); + const auto end_time = std::chrono::high_resolution_clock::now(); + sed_v | push_back((end_time - begin_time).count()); + return sed_v; + } + 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 + using uniform_normal_distribution = dxle::first_enabled_t< + std::enable_if::value, std::uniform_int_distribution>, + std::enable_if::value, std::uniform_real_distribution> + >; +} +extern std::mt19937 engine; +#endif //DXLE_TEST_NO_DXLIB_RANDOM_HPP_ diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp new file mode 100644 index 0000000..f746791 --- /dev/null +++ b/tests/no_dxlib/test_point_c.hpp @@ -0,0 +1,543 @@ +/*============================================================================= + Copyright (C) 2015-2016 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) +=============================================================================*/ +#include "../../3rd_party/iutest/include/iutest.hpp" +#include +#include +#include +#include "random.hpp" +#include +#include +#include +IUTEST_TEST(point_c_construct_test, type_int32_t) { + using type = std::int32_t; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const dxle::point_c value = { value_x, value_y }; + IUTEST_ASSERT(value.x == value_x); + IUTEST_ASSERT(value.y == value_y); + } + const dxle::point_c value1 = {}; + IUTEST_ASSERT(value1.x == 0); + IUTEST_ASSERT(value1.y == 0); + const auto value2 = value1; + IUTEST_ASSERT(value2.x == 0); + IUTEST_ASSERT(value2.y == 0); + const auto value3 = std::move(value1); + IUTEST_ASSERT(value2.x == 0); + IUTEST_ASSERT(value2.y == 0); + const dxle::point_c value4 = { 2, -9 }; + IUTEST_ASSERT(value4.x == 2); + IUTEST_ASSERT(value4.y == -9); +} +IUTEST_TEST(point_c_construct_test, type_int64_t) { + using type = std::int64_t; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const dxle::point_c value = { value_x, value_y }; + IUTEST_ASSERT(value.x == value_x); + IUTEST_ASSERT(value.y == value_y); + } + const dxle::point_c value1 = {}; + IUTEST_ASSERT(value1.x == 0); + IUTEST_ASSERT(value1.y == 0); + const auto value2 = value1; + IUTEST_ASSERT(value2.x == 0); + IUTEST_ASSERT(value2.y == 0); + const auto value3 = std::move(value1); + IUTEST_ASSERT(value2.x == 0); + IUTEST_ASSERT(value2.y == 0); + const dxle::point_c value4 = { 2, -9 }; + IUTEST_ASSERT(value4.x == 2); + IUTEST_ASSERT(value4.y == -9); +} +IUTEST_TEST(point_c_construct_test, type_uint32_t) { + using type = std::uint32_t; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const dxle::point_c value = { value_x, value_y }; + IUTEST_ASSERT(value.x == value_x); + IUTEST_ASSERT(value.y == value_y); + } + const dxle::point_c value1 = {}; + IUTEST_ASSERT(value1.x == 0); + IUTEST_ASSERT(value1.y == 0); + const auto value2 = value1; + IUTEST_ASSERT(value2.x == 0); + IUTEST_ASSERT(value2.y == 0); + const auto value3 = std::move(value1); + IUTEST_ASSERT(value2.x == 0); + IUTEST_ASSERT(value2.y == 0); + const dxle::point_c value4 = { 2, 13 }; + IUTEST_ASSERT(value4.x == 2); + IUTEST_ASSERT(value4.y == 13); +} +IUTEST_TEST(point_c_construct_test, type_uint64_t) { + using type = std::uint64_t; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const dxle::point_c value = { value_x, value_y }; + IUTEST_ASSERT(value.x == value_x); + IUTEST_ASSERT(value.y == value_y); + } + const dxle::point_c value1 = {}; + IUTEST_ASSERT(value1.x == 0); + IUTEST_ASSERT(value1.y == 0); + const auto value2 = value1; + IUTEST_ASSERT(value2.x == 0); + IUTEST_ASSERT(value2.y == 0); + const auto value3 = std::move(value1); + IUTEST_ASSERT(value2.x == 0); + IUTEST_ASSERT(value2.y == 0); + const dxle::point_c value4 = { 2, 13 }; + IUTEST_ASSERT(value4.x == 2); + IUTEST_ASSERT(value4.y == 13); +} +IUTEST_TEST(point_c_construct_test, type_float) { + using type = float; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const dxle::point_c value = { value_x, value_y }; + IUTEST_ASSERT(value.x == value_x); + IUTEST_ASSERT(value.y == value_y); + } + const dxle::point_c value1 = {}; + IUTEST_ASSERT(value1.x == 0); + IUTEST_ASSERT(value1.y == 0); + const auto value2 = value1; + IUTEST_ASSERT(value2.x == 0); + IUTEST_ASSERT(value2.y == 0); + const auto value3 = std::move(value1); + IUTEST_ASSERT(value2.x == 0); + IUTEST_ASSERT(value2.y == 0); + const dxle::point_c value4 = { 2, -9 }; + IUTEST_ASSERT(value4.x == 2); + IUTEST_ASSERT(value4.y == -9); +} +IUTEST_TEST(point_c_construct_test, type_double) { + using type = double; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const dxle::point_c value = { value_x, value_y }; + IUTEST_ASSERT(value.x == value_x); + IUTEST_ASSERT(value.y == value_y); + } + const dxle::point_c value1 = {}; + IUTEST_ASSERT(value1.x == 0); + IUTEST_ASSERT(value1.y == 0); + const auto value2 = value1; + IUTEST_ASSERT(value2.x == 0); + IUTEST_ASSERT(value2.y == 0); + const auto value3 = std::move(value1); + IUTEST_ASSERT(value2.x == 0); + IUTEST_ASSERT(value2.y == 0); + const dxle::point_c value4 = { 2, 13 }; + IUTEST_ASSERT(value4.x == 2); + IUTEST_ASSERT(value4.y == 13); +} +IUTEST_TEST(point_c_factory_test, type_int32_t) { + using type = std::int32_t; + const std::pair pa = { 12, -34 }; + const auto po = dxle::make_point_c(pa); + static_assert(std::is_same::value, "err"); + IUTEST_ASSERT(po.x == pa.first); + IUTEST_ASSERT(po.y == pa.second); + const auto po2 = dxle::make_point_c(std::pair(pa)); + IUTEST_ASSERT(po2.x == pa.first); + IUTEST_ASSERT(po2.y == pa.second); +} +IUTEST_TEST(point_c_factory_test, type_uint32_t) { + using type = std::uint32_t; + const std::pair pa = { 12, 32 }; + const auto po = dxle::make_point_c(pa); + static_assert(std::is_same::value, "err"); + IUTEST_ASSERT(po.x == pa.first); + IUTEST_ASSERT(po.y == pa.second); + const auto po2 = dxle::make_point_c(std::pair(pa)); + IUTEST_ASSERT(po2.x == pa.first); + IUTEST_ASSERT(po2.y == pa.second); +} +IUTEST_TEST(point_c_factory_test, type_int64_t) { + using type = std::int64_t; + const std::pair pa = { 12, -34 }; + const auto po = dxle::make_point_c(pa); + static_assert(std::is_same::value, "err"); + IUTEST_ASSERT(po.x == pa.first); + IUTEST_ASSERT(po.y == pa.second); + const auto po2 = dxle::make_point_c(std::pair(pa)); + IUTEST_ASSERT(po2.x == pa.first); + IUTEST_ASSERT(po2.y == pa.second); +} +IUTEST_TEST(point_c_factory_test, type_uint64_t) { + using type = std::uint64_t; + const std::pair pa = { 12, 32 }; + const auto po = dxle::make_point_c(pa); + static_assert(std::is_same::value, "err"); + IUTEST_ASSERT(po.x == pa.first); + IUTEST_ASSERT(po.y == pa.second); + const auto po2 = dxle::make_point_c(std::pair(pa)); + IUTEST_ASSERT(po2.x == pa.first); + IUTEST_ASSERT(po2.y == pa.second); +} +IUTEST_TEST(point_c_factory_test, type_float) { + using type = float; + const std::pair pa = { 12.4f, 1.746f }; + const auto po = dxle::make_point_c(pa); + static_assert(std::is_same::value, "err"); + IUTEST_ASSERT(po.x == pa.first); + IUTEST_ASSERT(po.y == pa.second); + const auto po2 = dxle::make_point_c(std::pair(pa)); + IUTEST_ASSERT(po2.x == pa.first); + IUTEST_ASSERT(po2.y == pa.second); +} +IUTEST_TEST(point_c_factory_test, type_double) { + using type = double; + const std::pair pa = { 12.4, 1.746 }; + const auto po = dxle::make_point_c(pa); + static_assert(std::is_same::value, "err"); + IUTEST_ASSERT(po.x == pa.first); + IUTEST_ASSERT(po.y == pa.second); + const auto po2 = dxle::make_point_c(std::pair(pa)); + IUTEST_ASSERT(po2.x == pa.first); + IUTEST_ASSERT(po2.y == pa.second); +} +IUTEST_TEST(point_c_operaotr_eq_test, type_int32_t) { + using type = std::int32_t; + const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const dxle::point_c value = { value_x, value_y }; + IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); + } +} +IUTEST_TEST(point_c_operaotr_eq_test, type_uint32_t) { + using type = std::uint32_t; + const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const dxle::point_c value = { value_x, value_y }; + IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); + } +} +IUTEST_TEST(point_c_operaotr_eq_test, type_int64_t) { + using type = std::int64_t; + const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const dxle::point_c value = { value_x, value_y }; + IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); + } +} +IUTEST_TEST(point_c_operaotr_eq_test, type_uint64_t) { + using type = std::uint64_t; + const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const dxle::point_c value = { value_x, value_y }; + IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); + } +} +IUTEST_TEST(point_c_operaotr_eq_test, type_float) { + using type = float; + const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const dxle::point_c value = { value_x, value_y }; + IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); + } +} +IUTEST_TEST(point_c_operaotr_eq_test, type_double) { + using type = double; + const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const dxle::point_c value = { value_x, value_y }; + IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); + } +} +IUTEST_TEST(point_c_operator_add_test, type_int32_t) { + using type = std::int32_t; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + auto get_rand2 = [](type n1, type n2, int modifyer) { + const auto minmax = std::minmax(n1, n2); + return dxle::uniform_normal_distribution( + (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer + )(engine); + }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const dxle::point_c value1 = { value1_x, value1_y }; + const auto first_add_dist = get_rand2(value1_x, value1_y, 1); + auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist); + const auto second_add_dist = get_rand2(value2.x, value2.y, 0); + value2 += dxle::point_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); + } +} +IUTEST_TEST(point_c_operator_add_test, type_uint32_t) { + using type = std::uint32_t; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + auto get_rand2 = [](type n1, type n2, int modifyer) { + const auto minmax = std::minmax(n1, n2); + return dxle::uniform_normal_distribution( + (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer + )(engine); + }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const dxle::point_c value1 = { value1_x, value1_y }; + const auto first_add_dist = get_rand2(value1_x, value1_y, 1); + auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist); + const auto second_add_dist = get_rand2(value2.x, value2.y, 0); + value2 += dxle::point_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); + } +} +IUTEST_TEST(point_c_operator_add_test, type_int64_t) { + using type = std::int64_t; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + auto get_rand2 = [](type n1, type n2, int modifyer) { + const auto minmax = std::minmax(n1, n2); + return dxle::uniform_normal_distribution( + (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer + )(engine); + }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const dxle::point_c value1 = { value1_x, value1_y }; + const auto first_add_dist = get_rand2(value1_x, value1_y, 1); + auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist); + const auto second_add_dist = get_rand2(value2.x, value2.y, 0); + value2 += dxle::point_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); + } +} +IUTEST_TEST(point_c_operator_add_test, type_uint64_t) { + using type = std::uint64_t; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + auto get_rand2 = [](type n1, type n2, int modifyer) { + const auto minmax = std::minmax(n1, n2); + return dxle::uniform_normal_distribution( + (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer + )(engine); + }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const dxle::point_c value1 = { value1_x, value1_y }; + const auto first_add_dist = get_rand2(value1_x, value1_y, 1); + auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist); + const auto second_add_dist = get_rand2(value2.x, value2.y, 0); + value2 += dxle::point_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); + } +} +IUTEST_TEST(point_c_operator_add_test, type_float) { + using type = float; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + auto get_rand2 = [](type n1, type n2, int modifyer) { + const auto minmax = std::minmax(n1, n2); + return dxle::uniform_normal_distribution( + (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer + )(engine); + }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const dxle::point_c value1 = { value1_x, value1_y }; + const auto first_add_dist = get_rand2(value1_x, value1_y, 1); + auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist); + const auto second_add_dist = get_rand2(value2.x, value2.y, 0); + value2 += dxle::point_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); + } +} +IUTEST_TEST(point_c_operator_add_test, type_double) { + using type = double; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + auto get_rand2 = [](type n1, type n2, int modifyer) { + const auto minmax = std::minmax(n1, n2); + return dxle::uniform_normal_distribution( + (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer + )(engine); + }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const dxle::point_c value1 = { value1_x, value1_y }; + const auto first_add_dist = get_rand2(value1_x, value1_y, 1); + auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist); + const auto second_add_dist = get_rand2(value2.x, value2.y, 0); + value2 += dxle::point_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); + } +} diff --git a/tests/with_dxLib/with_dxLib_test.cpp b/tests/with_dxLib/with_dxLib_test.cpp index bb6576d..dbc4f75 100644 --- a/tests/with_dxLib/with_dxLib_test.cpp +++ b/tests/with_dxLib/with_dxLib_test.cpp @@ -1 +1 @@ -#include "GraphTest.hpp" \ No newline at end of file +#include "graph.hpp" From 8b932f1081326002452b2407c609fa5fdc9174fc Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 7 Aug 2016 02:32:17 +0900 Subject: [PATCH 03/39] add test case : point_c class operator-, operator-= --- tests/no_dxlib/no_dxlib.vcxproj | 4 +- tests/no_dxlib/test_point_c.hpp | 296 +++++++++++++++++++++----------- 2 files changed, 202 insertions(+), 98 deletions(-) diff --git a/tests/no_dxlib/no_dxlib.vcxproj b/tests/no_dxlib/no_dxlib.vcxproj index dcde86e..394ffdb 100644 --- a/tests/no_dxlib/no_dxlib.vcxproj +++ b/tests/no_dxlib/no_dxlib.vcxproj @@ -132,7 +132,7 @@ true ..\..\; MultiThreadedDebug - 4702 + 4189;5030 Console @@ -174,7 +174,7 @@ true ..\..\; MultiThreaded - 4702 + 4189;5030 Console diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp index f746791..80e617c 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/test_point_c.hpp @@ -13,6 +13,14 @@ #include #include #include +template +DXLE_CONSTEXPR bool is_l_zero(T&& val) { + return static_cast(0) == val; +} +template +DXLE_CONSTEXPR bool is_l_zero(T&& val, Rest&&... rest) { + return static_cast(0) == val && is_l_zero(std::forward(rest)...); +} IUTEST_TEST(point_c_construct_test, type_int32_t) { using type = std::int32_t; dxle::uniform_normal_distribution dist; @@ -30,14 +38,9 @@ IUTEST_TEST(point_c_construct_test, type_int32_t) { IUTEST_ASSERT(value.y == value_y); } const dxle::point_c value1 = {}; - IUTEST_ASSERT(value1.x == 0); - IUTEST_ASSERT(value1.y == 0); const auto value2 = value1; - IUTEST_ASSERT(value2.x == 0); - IUTEST_ASSERT(value2.y == 0); const auto value3 = std::move(value1); - IUTEST_ASSERT(value2.x == 0); - IUTEST_ASSERT(value2.y == 0); + IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value2.x, value2.y, value3.x, value3.y)); const dxle::point_c value4 = { 2, -9 }; IUTEST_ASSERT(value4.x == 2); IUTEST_ASSERT(value4.y == -9); @@ -59,14 +62,9 @@ IUTEST_TEST(point_c_construct_test, type_int64_t) { IUTEST_ASSERT(value.y == value_y); } const dxle::point_c value1 = {}; - IUTEST_ASSERT(value1.x == 0); - IUTEST_ASSERT(value1.y == 0); const auto value2 = value1; - IUTEST_ASSERT(value2.x == 0); - IUTEST_ASSERT(value2.y == 0); const auto value3 = std::move(value1); - IUTEST_ASSERT(value2.x == 0); - IUTEST_ASSERT(value2.y == 0); + IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value2.x, value2.y, value3.x, value3.y)); const dxle::point_c value4 = { 2, -9 }; IUTEST_ASSERT(value4.x == 2); IUTEST_ASSERT(value4.y == -9); @@ -88,17 +86,12 @@ IUTEST_TEST(point_c_construct_test, type_uint32_t) { IUTEST_ASSERT(value.y == value_y); } const dxle::point_c value1 = {}; - IUTEST_ASSERT(value1.x == 0); - IUTEST_ASSERT(value1.y == 0); const auto value2 = value1; - IUTEST_ASSERT(value2.x == 0); - IUTEST_ASSERT(value2.y == 0); const auto value3 = std::move(value1); - IUTEST_ASSERT(value2.x == 0); - IUTEST_ASSERT(value2.y == 0); + IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value2.x, value2.y, value3.x, value3.y)); const dxle::point_c value4 = { 2, 13 }; - IUTEST_ASSERT(value4.x == 2); - IUTEST_ASSERT(value4.y == 13); + IUTEST_ASSERT(value4.x == 2u); + IUTEST_ASSERT(value4.y == 13u); } IUTEST_TEST(point_c_construct_test, type_uint64_t) { using type = std::uint64_t; @@ -117,17 +110,12 @@ IUTEST_TEST(point_c_construct_test, type_uint64_t) { IUTEST_ASSERT(value.y == value_y); } const dxle::point_c value1 = {}; - IUTEST_ASSERT(value1.x == 0); - IUTEST_ASSERT(value1.y == 0); const auto value2 = value1; - IUTEST_ASSERT(value2.x == 0); - IUTEST_ASSERT(value2.y == 0); const auto value3 = std::move(value1); - IUTEST_ASSERT(value2.x == 0); - IUTEST_ASSERT(value2.y == 0); + IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value2.x, value2.y, value3.x, value3.y)); const dxle::point_c value4 = { 2, 13 }; - IUTEST_ASSERT(value4.x == 2); - IUTEST_ASSERT(value4.y == 13); + IUTEST_ASSERT(value4.x == 2u); + IUTEST_ASSERT(value4.y == 13u); } IUTEST_TEST(point_c_construct_test, type_float) { using type = float; @@ -146,14 +134,9 @@ IUTEST_TEST(point_c_construct_test, type_float) { IUTEST_ASSERT(value.y == value_y); } const dxle::point_c value1 = {}; - IUTEST_ASSERT(value1.x == 0); - IUTEST_ASSERT(value1.y == 0); const auto value2 = value1; - IUTEST_ASSERT(value2.x == 0); - IUTEST_ASSERT(value2.y == 0); const auto value3 = std::move(value1); - IUTEST_ASSERT(value2.x == 0); - IUTEST_ASSERT(value2.y == 0); + IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value2.x, value2.y, value3.x, value3.y)); const dxle::point_c value4 = { 2, -9 }; IUTEST_ASSERT(value4.x == 2); IUTEST_ASSERT(value4.y == -9); @@ -175,14 +158,9 @@ IUTEST_TEST(point_c_construct_test, type_double) { IUTEST_ASSERT(value.y == value_y); } const dxle::point_c value1 = {}; - IUTEST_ASSERT(value1.x == 0); - IUTEST_ASSERT(value1.y == 0); const auto value2 = value1; - IUTEST_ASSERT(value2.x == 0); - IUTEST_ASSERT(value2.y == 0); const auto value3 = std::move(value1); - IUTEST_ASSERT(value2.x == 0); - IUTEST_ASSERT(value2.y == 0); + IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value2.x, value2.y, value3.x, value3.y)); const dxle::point_c value4 = { 2, 13 }; IUTEST_ASSERT(value4.x == 2); IUTEST_ASSERT(value4.y == 13); @@ -361,17 +339,20 @@ IUTEST_TEST(point_c_operaotr_eq_test, type_double) { IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); } } +template +T get_rand_for_add(T n1, T n2, int modifyer) { + using lim = std::numeric_limits; + const auto minmax = std::minmax(n1, n2); + return dxle::uniform_normal_distribution( + (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, + (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer + )(engine); +} IUTEST_TEST(point_c_operator_add_test, type_int32_t) { using type = std::int32_t; using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); auto get_rand = [&dist]() { return dist(engine); }; - auto get_rand2 = [](type n1, type n2, int modifyer) { - const auto minmax = std::minmax(n1, n2); - return dxle::uniform_normal_distribution( - (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer - )(engine); - }; for ( #ifndef DXLE_NO_CXX11_ATTRIBUTES [[gnu::unused]] @@ -381,11 +362,11 @@ IUTEST_TEST(point_c_operator_add_test, type_int32_t) { const auto value1_x = get_rand(); const auto value1_y = get_rand(); const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand2(value1_x, value1_y, 1); + const auto first_add_dist = get_rand_for_add(value1_x, value1_y, 1); auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist); - const auto second_add_dist = get_rand2(value2.x, value2.y, 0); + const auto second_add_dist = get_rand_for_add(value2.x, value2.y, 0); value2 += dxle::point_c{second_add_dist, second_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); @@ -396,12 +377,6 @@ IUTEST_TEST(point_c_operator_add_test, type_uint32_t) { using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); auto get_rand = [&dist]() { return dist(engine); }; - auto get_rand2 = [](type n1, type n2, int modifyer) { - const auto minmax = std::minmax(n1, n2); - return dxle::uniform_normal_distribution( - (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer - )(engine); - }; for ( #ifndef DXLE_NO_CXX11_ATTRIBUTES [[gnu::unused]] @@ -411,11 +386,11 @@ IUTEST_TEST(point_c_operator_add_test, type_uint32_t) { const auto value1_x = get_rand(); const auto value1_y = get_rand(); const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand2(value1_x, value1_y, 1); + const auto first_add_dist = get_rand_for_add(value1_x, value1_y, 1); auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist); - const auto second_add_dist = get_rand2(value2.x, value2.y, 0); + const auto second_add_dist = get_rand_for_add(value2.x, value2.y, 0); value2 += dxle::point_c{second_add_dist, second_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); @@ -426,26 +401,20 @@ IUTEST_TEST(point_c_operator_add_test, type_int64_t) { using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); auto get_rand = [&dist]() { return dist(engine); }; - auto get_rand2 = [](type n1, type n2, int modifyer) { - const auto minmax = std::minmax(n1, n2); - return dxle::uniform_normal_distribution( - (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer - )(engine); - }; for ( #ifndef DXLE_NO_CXX11_ATTRIBUTES [[gnu::unused]] #endif - auto i : dxle::rep(10) - ) { + auto i : dxle::rep(10) + ) { const auto value1_x = get_rand(); const auto value1_y = get_rand(); const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand2(value1_x, value1_y, 1); + const auto first_add_dist = get_rand_for_add(value1_x, value1_y, 1); auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist); - const auto second_add_dist = get_rand2(value2.x, value2.y, 0); + const auto second_add_dist = get_rand_for_add(value2.x, value2.y, 0); value2 += dxle::point_c{second_add_dist, second_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); @@ -456,26 +425,20 @@ IUTEST_TEST(point_c_operator_add_test, type_uint64_t) { using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); auto get_rand = [&dist]() { return dist(engine); }; - auto get_rand2 = [](type n1, type n2, int modifyer) { - const auto minmax = std::minmax(n1, n2); - return dxle::uniform_normal_distribution( - (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer - )(engine); - }; for ( #ifndef DXLE_NO_CXX11_ATTRIBUTES [[gnu::unused]] #endif - auto i : dxle::rep(10) - ) { + auto i : dxle::rep(10) + ) { const auto value1_x = get_rand(); const auto value1_y = get_rand(); const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand2(value1_x, value1_y, 1); + const auto first_add_dist = get_rand_for_add(value1_x, value1_y, 1); auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist); - const auto second_add_dist = get_rand2(value2.x, value2.y, 0); + const auto second_add_dist = get_rand_for_add(value2.x, value2.y, 0); value2 += dxle::point_c{second_add_dist, second_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); @@ -486,26 +449,20 @@ IUTEST_TEST(point_c_operator_add_test, type_float) { using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); auto get_rand = [&dist]() { return dist(engine); }; - auto get_rand2 = [](type n1, type n2, int modifyer) { - const auto minmax = std::minmax(n1, n2); - return dxle::uniform_normal_distribution( - (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer - )(engine); - }; for ( #ifndef DXLE_NO_CXX11_ATTRIBUTES [[gnu::unused]] #endif - auto i : dxle::rep(10) - ) { + auto i : dxle::rep(10) + ) { const auto value1_x = get_rand(); const auto value1_y = get_rand(); const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand2(value1_x, value1_y, 1); + const auto first_add_dist = get_rand_for_add(value1_x, value1_y, 1); auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist); - const auto second_add_dist = get_rand2(value2.x, value2.y, 0); + const auto second_add_dist = get_rand_for_add(value2.x, value2.y, 0); value2 += dxle::point_c{second_add_dist, second_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); @@ -516,28 +473,175 @@ IUTEST_TEST(point_c_operator_add_test, type_double) { using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); auto get_rand = [&dist]() { return dist(engine); }; - auto get_rand2 = [](type n1, type n2, int modifyer) { - const auto minmax = std::minmax(n1, n2); - return dxle::uniform_normal_distribution( - (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer - )(engine); - }; for ( #ifndef DXLE_NO_CXX11_ATTRIBUTES [[gnu::unused]] #endif - auto i : dxle::rep(10) - ) { + auto i : dxle::rep(10) + ) { const auto value1_x = get_rand(); const auto value1_y = get_rand(); const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand2(value1_x, value1_y, 1); + const auto first_add_dist = get_rand_for_add(value1_x, value1_y, 1); auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist); - const auto second_add_dist = get_rand2(value2.x, value2.y, 0); + const auto second_add_dist = get_rand_for_add(value2.x, value2.y, 0); value2 += dxle::point_c{second_add_dist, second_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); } } +template +T get_rand_for_sub(T n1, T n2, int modifyer) { + using lim = std::numeric_limits; + const auto minmax = std::minmax(n1, n2); + return dxle::uniform_normal_distribution( + (minmax.first < 0) ? lim::min() : lim::min() + minmax.first + modifyer, + (minmax.second > 0) ? lim::max() : lim::max() + minmax.second - modifyer + )(engine); +} +IUTEST_TEST(point_c_operator_sub_test, type_int32_t) { + using type = std::int32_t; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const dxle::point_c value1 = { value1_x, value1_y }; + const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, 1); + auto value2 = value1 - dxle::point_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist); + const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, 0); + value2 -= dxle::point_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); + } +} +IUTEST_TEST(point_c_operator_sub_test, type_uint32_t) { + using type = std::uint32_t; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const dxle::point_c value1 = { value1_x, value1_y }; + const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, 1); + auto value2 = value1 - dxle::point_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist); + const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, 0); + value2 -= dxle::point_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); + } +} +IUTEST_TEST(point_c_operator_sub_test, type_int64_t) { + using type = std::int64_t; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const dxle::point_c value1 = { value1_x, value1_y }; + const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, 1); + auto value2 = value1 - dxle::point_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist); + const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, 0); + value2 -= dxle::point_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); + } +} +IUTEST_TEST(point_c_operator_sub_test, type_uint64_t) { + using type = std::uint64_t; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const dxle::point_c value1 = { value1_x, value1_y }; + const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, 1); + auto value2 = value1 - dxle::point_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist); + const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, 0); + value2 -= dxle::point_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); + } +} +IUTEST_TEST(point_c_operator_sub_test, type_float) { + using type = float; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const dxle::point_c value1 = { value1_x, value1_y }; + const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, 1); + auto value2 = value1 - dxle::point_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist); + const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, 0); + value2 -= dxle::point_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); + } +} +IUTEST_TEST(point_c_operator_sub_test, type_double) { + using type = double; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const dxle::point_c value1 = { value1_x, value1_y }; + const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, 1); + auto value2 = value1 - dxle::point_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist); + const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, 0); + value2 -= dxle::point_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); + } +} From 842eb4439e396762dc5f5238400152a0ea25fb7c Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 7 Aug 2016 15:06:18 +0900 Subject: [PATCH 04/39] =?UTF-8?q?=E5=9E=8B=E4=BB=98=E3=81=91=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=AB=E6=9B=B8=E3=81=8D=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/no_dxlib/test_point_c.hpp | 539 ++------------------------------ 1 file changed, 19 insertions(+), 520 deletions(-) diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp index 80e617c..f2b22dc 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/test_point_c.hpp @@ -21,8 +21,12 @@ template DXLE_CONSTEXPR bool is_l_zero(T&& val, Rest&&... rest) { return static_cast(0) == val && is_l_zero(std::forward(rest)...); } -IUTEST_TEST(point_c_construct_test, type_int32_t) { - using type = std::int32_t; +template +struct point_c_test : public ::iutest::Test{}; +using test_types = ::iutest::Types; +IUTEST_TYPED_TEST_CASE(point_c_test, test_types); +IUTEST_TYPED_TEST(point_c_test, construct) { + using type = TypeParam; dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; for ( @@ -41,288 +45,23 @@ IUTEST_TEST(point_c_construct_test, type_int32_t) { const auto value2 = value1; const auto value3 = std::move(value1); IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value2.x, value2.y, value3.x, value3.y)); - const dxle::point_c value4 = { 2, -9 }; - IUTEST_ASSERT(value4.x == 2); - IUTEST_ASSERT(value4.y == -9); -} -IUTEST_TEST(point_c_construct_test, type_int64_t) { - using type = std::int64_t; - dxle::uniform_normal_distribution dist; - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value_x = get_rand(); - const auto value_y = get_rand(); - const dxle::point_c value = { value_x, value_y }; - IUTEST_ASSERT(value.x == value_x); - IUTEST_ASSERT(value.y == value_y); - } - const dxle::point_c value1 = {}; - const auto value2 = value1; - const auto value3 = std::move(value1); - IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value2.x, value2.y, value3.x, value3.y)); - const dxle::point_c value4 = { 2, -9 }; - IUTEST_ASSERT(value4.x == 2); - IUTEST_ASSERT(value4.y == -9); -} -IUTEST_TEST(point_c_construct_test, type_uint32_t) { - using type = std::uint32_t; - dxle::uniform_normal_distribution dist; - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value_x = get_rand(); - const auto value_y = get_rand(); - const dxle::point_c value = { value_x, value_y }; - IUTEST_ASSERT(value.x == value_x); - IUTEST_ASSERT(value.y == value_y); - } - const dxle::point_c value1 = {}; - const auto value2 = value1; - const auto value3 = std::move(value1); - IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value2.x, value2.y, value3.x, value3.y)); - const dxle::point_c value4 = { 2, 13 }; - IUTEST_ASSERT(value4.x == 2u); - IUTEST_ASSERT(value4.y == 13u); -} -IUTEST_TEST(point_c_construct_test, type_uint64_t) { - using type = std::uint64_t; - dxle::uniform_normal_distribution dist; - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value_x = get_rand(); - const auto value_y = get_rand(); - const dxle::point_c value = { value_x, value_y }; - IUTEST_ASSERT(value.x == value_x); - IUTEST_ASSERT(value.y == value_y); - } - const dxle::point_c value1 = {}; - const auto value2 = value1; - const auto value3 = std::move(value1); - IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value2.x, value2.y, value3.x, value3.y)); - const dxle::point_c value4 = { 2, 13 }; - IUTEST_ASSERT(value4.x == 2u); - IUTEST_ASSERT(value4.y == 13u); -} -IUTEST_TEST(point_c_construct_test, type_float) { - using type = float; - dxle::uniform_normal_distribution dist; - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value_x = get_rand(); - const auto value_y = get_rand(); - const dxle::point_c value = { value_x, value_y }; - IUTEST_ASSERT(value.x == value_x); - IUTEST_ASSERT(value.y == value_y); - } - const dxle::point_c value1 = {}; - const auto value2 = value1; - const auto value3 = std::move(value1); - IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value2.x, value2.y, value3.x, value3.y)); - const dxle::point_c value4 = { 2, -9 }; - IUTEST_ASSERT(value4.x == 2); - IUTEST_ASSERT(value4.y == -9); + const dxle::point_c value4 = { 2, 12 }; + IUTEST_ASSERT(value4.x == static_cast(2)); + IUTEST_ASSERT(value4.y == static_cast(12)); } -IUTEST_TEST(point_c_construct_test, type_double) { - using type = double; - dxle::uniform_normal_distribution dist; - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value_x = get_rand(); - const auto value_y = get_rand(); - const dxle::point_c value = { value_x, value_y }; - IUTEST_ASSERT(value.x == value_x); - IUTEST_ASSERT(value.y == value_y); - } - const dxle::point_c value1 = {}; - const auto value2 = value1; - const auto value3 = std::move(value1); - IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value2.x, value2.y, value3.x, value3.y)); - const dxle::point_c value4 = { 2, 13 }; - IUTEST_ASSERT(value4.x == 2); - IUTEST_ASSERT(value4.y == 13); -} -IUTEST_TEST(point_c_factory_test, type_int32_t) { - using type = std::int32_t; - const std::pair pa = { 12, -34 }; - const auto po = dxle::make_point_c(pa); - static_assert(std::is_same::value, "err"); - IUTEST_ASSERT(po.x == pa.first); - IUTEST_ASSERT(po.y == pa.second); - const auto po2 = dxle::make_point_c(std::pair(pa)); - IUTEST_ASSERT(po2.x == pa.first); - IUTEST_ASSERT(po2.y == pa.second); -} -IUTEST_TEST(point_c_factory_test, type_uint32_t) { - using type = std::uint32_t; - const std::pair pa = { 12, 32 }; +IUTEST_TYPED_TEST(point_c_test, factory) { + using type = TypeParam; + const std::pair pa = { static_cast(12), static_cast(23) }; const auto po = dxle::make_point_c(pa); - static_assert(std::is_same::value, "err"); + static_assert(std::is_same::value, "err"); IUTEST_ASSERT(po.x == pa.first); IUTEST_ASSERT(po.y == pa.second); const auto po2 = dxle::make_point_c(std::pair(pa)); IUTEST_ASSERT(po2.x == pa.first); IUTEST_ASSERT(po2.y == pa.second); } -IUTEST_TEST(point_c_factory_test, type_int64_t) { - using type = std::int64_t; - const std::pair pa = { 12, -34 }; - const auto po = dxle::make_point_c(pa); - static_assert(std::is_same::value, "err"); - IUTEST_ASSERT(po.x == pa.first); - IUTEST_ASSERT(po.y == pa.second); - const auto po2 = dxle::make_point_c(std::pair(pa)); - IUTEST_ASSERT(po2.x == pa.first); - IUTEST_ASSERT(po2.y == pa.second); -} -IUTEST_TEST(point_c_factory_test, type_uint64_t) { - using type = std::uint64_t; - const std::pair pa = { 12, 32 }; - const auto po = dxle::make_point_c(pa); - static_assert(std::is_same::value, "err"); - IUTEST_ASSERT(po.x == pa.first); - IUTEST_ASSERT(po.y == pa.second); - const auto po2 = dxle::make_point_c(std::pair(pa)); - IUTEST_ASSERT(po2.x == pa.first); - IUTEST_ASSERT(po2.y == pa.second); -} -IUTEST_TEST(point_c_factory_test, type_float) { - using type = float; - const std::pair pa = { 12.4f, 1.746f }; - const auto po = dxle::make_point_c(pa); - static_assert(std::is_same::value, "err"); - IUTEST_ASSERT(po.x == pa.first); - IUTEST_ASSERT(po.y == pa.second); - const auto po2 = dxle::make_point_c(std::pair(pa)); - IUTEST_ASSERT(po2.x == pa.first); - IUTEST_ASSERT(po2.y == pa.second); -} -IUTEST_TEST(point_c_factory_test, type_double) { - using type = double; - const std::pair pa = { 12.4, 1.746 }; - const auto po = dxle::make_point_c(pa); - static_assert(std::is_same::value, "err"); - IUTEST_ASSERT(po.x == pa.first); - IUTEST_ASSERT(po.y == pa.second); - const auto po2 = dxle::make_point_c(std::pair(pa)); - IUTEST_ASSERT(po2.x == pa.first); - IUTEST_ASSERT(po2.y == pa.second); -} -IUTEST_TEST(point_c_operaotr_eq_test, type_int32_t) { - using type = std::int32_t; - const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; - IUTEST_ASSERT(eq1); - dxle::uniform_normal_distribution dist; - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value_x = get_rand(); - const auto value_y = get_rand(); - const dxle::point_c value = { value_x, value_y }; - IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); - } -} -IUTEST_TEST(point_c_operaotr_eq_test, type_uint32_t) { - using type = std::uint32_t; - const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; - IUTEST_ASSERT(eq1); - dxle::uniform_normal_distribution dist; - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value_x = get_rand(); - const auto value_y = get_rand(); - const dxle::point_c value = { value_x, value_y }; - IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); - } -} -IUTEST_TEST(point_c_operaotr_eq_test, type_int64_t) { - using type = std::int64_t; - const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; - IUTEST_ASSERT(eq1); - dxle::uniform_normal_distribution dist; - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value_x = get_rand(); - const auto value_y = get_rand(); - const dxle::point_c value = { value_x, value_y }; - IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); - } -} -IUTEST_TEST(point_c_operaotr_eq_test, type_uint64_t) { - using type = std::uint64_t; - const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; - IUTEST_ASSERT(eq1); - dxle::uniform_normal_distribution dist; - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value_x = get_rand(); - const auto value_y = get_rand(); - const dxle::point_c value = { value_x, value_y }; - IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); - } -} -IUTEST_TEST(point_c_operaotr_eq_test, type_float) { - using type = float; - const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; - IUTEST_ASSERT(eq1); - dxle::uniform_normal_distribution dist; - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value_x = get_rand(); - const auto value_y = get_rand(); - const dxle::point_c value = { value_x, value_y }; - IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); - } -} -IUTEST_TEST(point_c_operaotr_eq_test, type_double) { - using type = double; +IUTEST_TYPED_TEST(point_c_test, operaotr_eq) { + using type = TypeParam; const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; IUTEST_ASSERT(eq1); dxle::uniform_normal_distribution dist; @@ -348,128 +87,8 @@ T get_rand_for_add(T n1, T n2, int modifyer) { (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer )(engine); } -IUTEST_TEST(point_c_operator_add_test, type_int32_t) { - using type = std::int32_t; - using lim = std::numeric_limits; - dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value1_x = get_rand(); - const auto value1_y = get_rand(); - const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand_for_add(value1_x, value1_y, 1); - auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; - IUTEST_ASSERT(value2.x == value1_x + first_add_dist); - IUTEST_ASSERT(value2.y == value1_y + first_add_dist); - const auto second_add_dist = get_rand_for_add(value2.x, value2.y, 0); - value2 += dxle::point_c{second_add_dist, second_add_dist}; - IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); - IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); - } -} -IUTEST_TEST(point_c_operator_add_test, type_uint32_t) { - using type = std::uint32_t; - using lim = std::numeric_limits; - dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value1_x = get_rand(); - const auto value1_y = get_rand(); - const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand_for_add(value1_x, value1_y, 1); - auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; - IUTEST_ASSERT(value2.x == value1_x + first_add_dist); - IUTEST_ASSERT(value2.y == value1_y + first_add_dist); - const auto second_add_dist = get_rand_for_add(value2.x, value2.y, 0); - value2 += dxle::point_c{second_add_dist, second_add_dist}; - IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); - IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); - } -} -IUTEST_TEST(point_c_operator_add_test, type_int64_t) { - using type = std::int64_t; - using lim = std::numeric_limits; - dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value1_x = get_rand(); - const auto value1_y = get_rand(); - const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand_for_add(value1_x, value1_y, 1); - auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; - IUTEST_ASSERT(value2.x == value1_x + first_add_dist); - IUTEST_ASSERT(value2.y == value1_y + first_add_dist); - const auto second_add_dist = get_rand_for_add(value2.x, value2.y, 0); - value2 += dxle::point_c{second_add_dist, second_add_dist}; - IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); - IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); - } -} -IUTEST_TEST(point_c_operator_add_test, type_uint64_t) { - using type = std::uint64_t; - using lim = std::numeric_limits; - dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value1_x = get_rand(); - const auto value1_y = get_rand(); - const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand_for_add(value1_x, value1_y, 1); - auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; - IUTEST_ASSERT(value2.x == value1_x + first_add_dist); - IUTEST_ASSERT(value2.y == value1_y + first_add_dist); - const auto second_add_dist = get_rand_for_add(value2.x, value2.y, 0); - value2 += dxle::point_c{second_add_dist, second_add_dist}; - IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); - IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); - } -} -IUTEST_TEST(point_c_operator_add_test, type_float) { - using type = float; - using lim = std::numeric_limits; - dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value1_x = get_rand(); - const auto value1_y = get_rand(); - const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand_for_add(value1_x, value1_y, 1); - auto value2 = value1 + dxle::point_c{first_add_dist, first_add_dist}; - IUTEST_ASSERT(value2.x == value1_x + first_add_dist); - IUTEST_ASSERT(value2.y == value1_y + first_add_dist); - const auto second_add_dist = get_rand_for_add(value2.x, value2.y, 0); - value2 += dxle::point_c{second_add_dist, second_add_dist}; - IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); - IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); - } -} -IUTEST_TEST(point_c_operator_add_test, type_double) { - using type = double; +IUTEST_TYPED_TEST(point_c_test, operator_add) { + using type = TypeParam; using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); auto get_rand = [&dist]() { return dist(engine); }; @@ -501,128 +120,8 @@ T get_rand_for_sub(T n1, T n2, int modifyer) { (minmax.second > 0) ? lim::max() : lim::max() + minmax.second - modifyer )(engine); } -IUTEST_TEST(point_c_operator_sub_test, type_int32_t) { - using type = std::int32_t; - using lim = std::numeric_limits; - dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value1_x = get_rand(); - const auto value1_y = get_rand(); - const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, 1); - auto value2 = value1 - dxle::point_c{first_add_dist, first_add_dist}; - IUTEST_ASSERT(value2.x == value1_x - first_add_dist); - IUTEST_ASSERT(value2.y == value1_y - first_add_dist); - const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, 0); - value2 -= dxle::point_c{second_add_dist, second_add_dist}; - IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); - IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); - } -} -IUTEST_TEST(point_c_operator_sub_test, type_uint32_t) { - using type = std::uint32_t; - using lim = std::numeric_limits; - dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value1_x = get_rand(); - const auto value1_y = get_rand(); - const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, 1); - auto value2 = value1 - dxle::point_c{first_add_dist, first_add_dist}; - IUTEST_ASSERT(value2.x == value1_x - first_add_dist); - IUTEST_ASSERT(value2.y == value1_y - first_add_dist); - const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, 0); - value2 -= dxle::point_c{second_add_dist, second_add_dist}; - IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); - IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); - } -} -IUTEST_TEST(point_c_operator_sub_test, type_int64_t) { - using type = std::int64_t; - using lim = std::numeric_limits; - dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value1_x = get_rand(); - const auto value1_y = get_rand(); - const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, 1); - auto value2 = value1 - dxle::point_c{first_add_dist, first_add_dist}; - IUTEST_ASSERT(value2.x == value1_x - first_add_dist); - IUTEST_ASSERT(value2.y == value1_y - first_add_dist); - const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, 0); - value2 -= dxle::point_c{second_add_dist, second_add_dist}; - IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); - IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); - } -} -IUTEST_TEST(point_c_operator_sub_test, type_uint64_t) { - using type = std::uint64_t; - using lim = std::numeric_limits; - dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value1_x = get_rand(); - const auto value1_y = get_rand(); - const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, 1); - auto value2 = value1 - dxle::point_c{first_add_dist, first_add_dist}; - IUTEST_ASSERT(value2.x == value1_x - first_add_dist); - IUTEST_ASSERT(value2.y == value1_y - first_add_dist); - const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, 0); - value2 -= dxle::point_c{second_add_dist, second_add_dist}; - IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); - IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); - } -} -IUTEST_TEST(point_c_operator_sub_test, type_float) { - using type = float; - using lim = std::numeric_limits; - dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); - auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { - const auto value1_x = get_rand(); - const auto value1_y = get_rand(); - const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, 1); - auto value2 = value1 - dxle::point_c{first_add_dist, first_add_dist}; - IUTEST_ASSERT(value2.x == value1_x - first_add_dist); - IUTEST_ASSERT(value2.y == value1_y - first_add_dist); - const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, 0); - value2 -= dxle::point_c{second_add_dist, second_add_dist}; - IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); - IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); - } -} -IUTEST_TEST(point_c_operator_sub_test, type_double) { - using type = double; +IUTEST_TYPED_TEST(point_c_test, operator_sub) { + using type = TypeParam; using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); auto get_rand = [&dist]() { return dist(engine); }; From 46ece80f93859e7252bc2956ea18847bc98f6bbd Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 7 Aug 2016 15:09:08 +0900 Subject: [PATCH 05/39] fix typo --- tests/no_dxlib/test_point_c.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp index f2b22dc..f0a5350 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/test_point_c.hpp @@ -79,12 +79,12 @@ IUTEST_TYPED_TEST(point_c_test, operaotr_eq) { } } template -T get_rand_for_add(T n1, T n2, int modifyer) { +T get_rand_for_add(T n1, T n2, int modifier) { using lim = std::numeric_limits; const auto minmax = std::minmax(n1, n2); return dxle::uniform_normal_distribution( - (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifyer, - (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifyer + (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifier, + (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifier )(engine); } IUTEST_TYPED_TEST(point_c_test, operator_add) { @@ -112,12 +112,12 @@ IUTEST_TYPED_TEST(point_c_test, operator_add) { } } template -T get_rand_for_sub(T n1, T n2, int modifyer) { +T get_rand_for_sub(T n1, T n2, int modifier) { using lim = std::numeric_limits; const auto minmax = std::minmax(n1, n2); return dxle::uniform_normal_distribution( - (minmax.first < 0) ? lim::min() : lim::min() + minmax.first + modifyer, - (minmax.second > 0) ? lim::max() : lim::max() + minmax.second - modifyer + (minmax.first < 0) ? lim::min() : lim::min() + minmax.first + modifier, + (minmax.second > 0) ? lim::max() : lim::max() + minmax.second - modifier )(engine); } IUTEST_TYPED_TEST(point_c_test, operator_sub) { From 3bf46d214684b549977cc2a908475782401ce1df Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 7 Aug 2016 20:05:57 +0900 Subject: [PATCH 06/39] delim char should be written by variable-template-like template function --- dxlibex/basic_types/point2d.hpp | 3 ++- dxlibex/basic_types/point3d.hpp | 5 +++-- dxlibex/basic_types/size.hpp | 3 ++- dxlibex/char_constant.hpp | 11 +++++++++++ dxlibex/char_constant/char_constant.hpp | 22 ++++++++++++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 dxlibex/char_constant.hpp create mode 100644 dxlibex/char_constant/char_constant.hpp diff --git a/dxlibex/basic_types/point2d.hpp b/dxlibex/basic_types/point2d.hpp index 16e9793..0c5d38d 100644 --- a/dxlibex/basic_types/point2d.hpp +++ b/dxlibex/basic_types/point2d.hpp @@ -20,6 +20,7 @@ #include "dxlibex/algorithm.hpp" #include "dxlibex/math.hpp" #include "dxlibex/cstdlib.hpp" +#include "dxlibex/char_constant.hpp" //#include "dxlibex/basic_types.hpp"//DO NOT REMOVE COMMENT-OUT to avoid redefine #include #include //std::pair @@ -210,7 +211,7 @@ namespace dxle { { use_big_type_when_one_byte_t x, y; is >> x; - is.ignore((std::numeric_limits::max)(), ','); + is.ignore((std::numeric_limits::max)(), dxle::char_constant::comma()); is >> y; p.x = static_cast(x); p.y = static_cast(y); } diff --git a/dxlibex/basic_types/point3d.hpp b/dxlibex/basic_types/point3d.hpp index a759585..9ee5721 100644 --- a/dxlibex/basic_types/point3d.hpp +++ b/dxlibex/basic_types/point3d.hpp @@ -18,6 +18,7 @@ #include "dxlibex/algorithm/safe_dist.hpp" #include "dxlibex/math.hpp" #include "dxlibex/cstdlib.hpp" +#include "dxlibex/char_constant.hpp" //#include "dxlibex/basic_types.hpp"//DO NOT REMOVE COMMENT-OUT to avoid redefine #include #include @@ -187,9 +188,9 @@ namespace dxle { { use_big_type_when_one_byte_t x, y, z; is >> x; - is.ignore((std::numeric_limits::max)(), ','); + is.ignore((std::numeric_limits::max)(), dxle::char_constant::comma()); is >> y; - is.ignore((std::numeric_limits::max)(), ','); + is.ignore((std::numeric_limits::max)(), dxle::char_constant::comma()); is >> z; p.x = static_cast(x); p.y = static_cast(y); p.z = static_cast(z); } diff --git a/dxlibex/basic_types/size.hpp b/dxlibex/basic_types/size.hpp index a6708ea..8ce3c40 100644 --- a/dxlibex/basic_types/size.hpp +++ b/dxlibex/basic_types/size.hpp @@ -17,6 +17,7 @@ #include "dxlibex/basic_types/coordinate_operator_bool_helper.hpp" #include "dxlibex/math.hpp" #include "dxlibex/cstdlib.hpp" +#include "dxlibex/char_constant.hpp" //#include "dxlibex/basic_types.hpp"//DO NOT REMOVE COMMENT-OUT to avoid redefine #include #include //std::pair @@ -213,7 +214,7 @@ namespace dxle { { use_big_type_when_one_byte_t width, height; is >> width; - is.ignore((std::numeric_limits::max)(), ','); + is.ignore((std::numeric_limits::max)(), dxle::char_constant::comma()); is >> height; s.width = static_cast(width); s.height = static_cast(height); } diff --git a/dxlibex/char_constant.hpp b/dxlibex/char_constant.hpp new file mode 100644 index 0000000..52c45b6 --- /dev/null +++ b/dxlibex/char_constant.hpp @@ -0,0 +1,11 @@ +/*============================================================================= + Copyright (C) 2015-2016 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_INC_CHAR_CONSTANT_HPP_ +#define DXLE_INC_CHAR_CONSTANT_HPP_ +#include "dxlibex/char_constant/char_constant.hpp" +#endif //DXLE_INC_CHAR_CONSTANT_HPP_ diff --git a/dxlibex/char_constant/char_constant.hpp b/dxlibex/char_constant/char_constant.hpp new file mode 100644 index 0000000..d26dd38 --- /dev/null +++ b/dxlibex/char_constant/char_constant.hpp @@ -0,0 +1,22 @@ +/*============================================================================= + Copyright (C) 2015-2016 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_INC_CHAR_CONSTANT_CHAR_CONSTANT_HPP_ +#define DXLE_INC_CHAR_CONSTANT_CHAR_CONSTANT_HPP_ +#include "dxlibex/config/no_min_max.h" +#include "dxlibex/config/defines.h" +#include +#include +namespace dxle{ + namespace char_constant{ + template + DXLE_CONSTEXPR CharType comma(); + template<> DXLE_CONSTEXPR char comma() { return ','; } + template<> DXLE_CONSTEXPR wchar_t comma() { return L','; } + } +} +#endif //DXLE_INC_CHAR_CONSTANT_CHAR_CONSTANT_HPP_ From a7bf11bb539554d73a16ed6ca334f55c06510071 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 7 Aug 2016 20:06:26 +0900 Subject: [PATCH 07/39] write istream/ostream operator test --- tests/no_dxlib/test_point_c.hpp | 140 +++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 2 deletions(-) diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp index f0a5350..b1bf298 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/test_point_c.hpp @@ -13,6 +13,7 @@ #include #include #include +#include template DXLE_CONSTEXPR bool is_l_zero(T&& val) { return static_cast(0) == val; @@ -23,8 +24,7 @@ DXLE_CONSTEXPR bool is_l_zero(T&& val, Rest&&... rest) { } template struct point_c_test : public ::iutest::Test{}; -using test_types = ::iutest::Types; -IUTEST_TYPED_TEST_CASE(point_c_test, test_types); +IUTEST_TYPED_TEST_CASE(point_c_test, ::iutest::Types); IUTEST_TYPED_TEST(point_c_test, construct) { using type = TypeParam; dxle::uniform_normal_distribution dist; @@ -78,6 +78,142 @@ IUTEST_TYPED_TEST(point_c_test, operaotr_eq) { IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); } } +IUTEST_TYPED_TEST(point_c_test, ostream_operator) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto x = get_rand(); + const auto y = get_rand(); + std::stringstream ss1; + ss1 << x << ", " << y; + const dxle::point_c value = { x, y }; + std::stringstream ss2; + ss2 << value; + IUTEST_ASSERT_EQ(ss1.str(), ss2.str()); + } +} +IUTEST_TYPED_TEST(point_c_test, wostream_operator) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto x = get_rand(); + const auto y = get_rand(); + std::wstringstream ss1; + ss1 << x << L", " << y; + const dxle::point_c value = { x, y }; + std::wstringstream ss2; + ss2 << value; + IUTEST_ASSERT_EQ(ss1.str(), ss2.str()); + } +} +IUTEST_TYPED_TEST(point_c_test, istream_operator) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + std::stringstream ss1; + ss1 << get_rand() << ", " << get_rand(); + std::stringstream ss2; + ss2 << ss1.str(); + type v1, v2; + ss1 >> v1; + ss1.ignore((std::numeric_limits::max)(), ','); + ss1 >> v2; + dxle::point_c v; + ss2 >> v; + IUTEST_ASSERT(v == dxle::point_c(v1, v2)); + } +} +IUTEST_TYPED_TEST(point_c_test, wistream_operator) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + std::wstringstream ss1; + ss1 << get_rand() << L", " << get_rand(); + std::wstringstream ss2; + ss2 << ss1.str(); + type v1, v2; + ss1 >> v1; + ss1.ignore((std::numeric_limits::max)(), L','); + ss1 >> v2; + dxle::point_c v; + ss2 >> v; + IUTEST_ASSERT(v == dxle::point_c(v1, v2)); + } +} +IUTEST_TYPED_TEST(point_c_test, unary_operaotr_plus) { + using type = TypeParam; + const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const dxle::point_c value1 = { get_rand(), get_rand() }; + const auto value2 = +value1; + IUTEST_ASSERT(value1 == value2); + } +} +namespace detail { + template::value> + struct point_c_test_unary_operaotr_minus_helper { + using type = T; + void operator()() {} + }; + template + struct point_c_test_unary_operaotr_minus_helper { + using type = T; + void operator()() { + const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto x = get_rand(); + const auto y = get_rand(); + + const dxle::point_c value1 = { x, y }; + const auto value2 = -value1; + IUTEST_ASSERT(value2 == dxle::point_c(-x, -y)); + } + } + }; +} +IUTEST_TYPED_TEST(point_c_test, unary_operaotr_minus) { + detail::point_c_test_unary_operaotr_minus_helper{}(); +} template T get_rand_for_add(T n1, T n2, int modifier) { using lim = std::numeric_limits; From 410967deaca0c4fc363b3cf0eb3f1b69c7a9e6b9 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 7 Aug 2016 22:23:25 +0900 Subject: [PATCH 08/39] write mul operators test --- tests/no_dxlib/no_dxlib.vcxproj | 4 +++ tests/no_dxlib/test_point_c.hpp | 64 ++++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/tests/no_dxlib/no_dxlib.vcxproj b/tests/no_dxlib/no_dxlib.vcxproj index 394ffdb..4d7883f 100644 --- a/tests/no_dxlib/no_dxlib.vcxproj +++ b/tests/no_dxlib/no_dxlib.vcxproj @@ -190,6 +190,7 @@ Disabled FullDebug true + -Wextra %(AdditionalOptions) @@ -198,18 +199,21 @@ Disabled FullDebug true + -Wextra %(AdditionalOptions) ..\..\; true + -Wextra %(AdditionalOptions) ..\..\; true + -Wextra %(AdditionalOptions) diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp index b1bf298..9c0ea6c 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/test_point_c.hpp @@ -270,13 +270,61 @@ IUTEST_TYPED_TEST(point_c_test, operator_sub) { const auto value1_x = get_rand(); const auto value1_y = get_rand(); const dxle::point_c value1 = { value1_x, value1_y }; - const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, 1); - auto value2 = value1 - dxle::point_c{first_add_dist, first_add_dist}; - IUTEST_ASSERT(value2.x == value1_x - first_add_dist); - IUTEST_ASSERT(value2.y == value1_y - first_add_dist); - const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, 0); - value2 -= dxle::point_c{second_add_dist, second_add_dist}; - IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); - IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); + const auto first_sub_dist = get_rand_for_sub(value1_x, value1_y, 1); + auto value2 = value1 - dxle::point_c{first_sub_dist, first_sub_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_sub_dist); + IUTEST_ASSERT(value2.y == value1_y - first_sub_dist); + const auto second_sub_dist = get_rand_for_sub(value2.x, value2.y, 0); + value2 -= dxle::point_c{second_sub_dist, second_sub_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_sub_dist - second_sub_dist); + IUTEST_ASSERT(value2.y == value1_y - first_sub_dist - second_sub_dist); + } +} +template::value, std::nullptr_t> = nullptr> +T inferior_sqrt(T x) { return static_cast(::std::sqrt(x)); } +template::value, std::nullptr_t> = nullptr> +T inferior_sqrt(T x) { return (x < 0) ? 0 : static_cast(::std::sqrt(x)); } +std::int64_t inferior_sqrt(const std::int64_t x) { + return (x < 0) ? 0 : x < static_cast(std::numeric_limits::max()) ? static_cast(::std::sqrt(x)) + : static_cast(inferior_sqrt(static_cast(x))); +} +std::uint64_t inferior_sqrt(const std::uint64_t x) +{ + if(x < static_cast(std::numeric_limits::max())) return static_cast(::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; +} +template::value, std::nullptr_t> = nullptr> +T inferior_sqrt2(T x) { return (x < 0) ? -inferior_sqrt(-x) : inferior_sqrt(x); } +template::value, std::nullptr_t> = nullptr> +T inferior_sqrt2(T x) { return inferior_sqrt(x); } +IUTEST_TYPED_TEST(point_c_test, operator_mul) { + using type = TypeParam; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(inferior_sqrt2(lim::min()), inferior_sqrt(lim::max())); + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + dxle::point_c value1 = { value1_x, value1_y }; + const auto first_mul_dist = get_rand(); + auto value2 = value1 * first_mul_dist; + IUTEST_ASSERT(value2.x == value1_x * first_mul_dist); + IUTEST_ASSERT(value2.y == value1_y * first_mul_dist); + auto value3 = first_mul_dist * value1; + IUTEST_ASSERT(value2 == value3); + value1 *= first_mul_dist; + IUTEST_ASSERT(value3 == value1); } } From 5887649e436dcd99e3daaa3c997883c8468c4c2f Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 8 Aug 2016 00:44:48 +0900 Subject: [PATCH 09/39] fix macro name --- tests/no_dxlib/random.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/no_dxlib/random.hpp b/tests/no_dxlib/random.hpp index af49fba..2f75a69 100644 --- a/tests/no_dxlib/random.hpp +++ b/tests/no_dxlib/random.hpp @@ -17,7 +17,7 @@ Distributed under the Boost Software License, Version 1.0. # include #endif //defined(__MINGW32__) && !defined(__clang__) #if defined(_WIN32) || defined(_WIN64) -# define MY_ARC_FOR_WINDWOS 1 +# 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' @@ -27,7 +27,7 @@ Distributed under the Boost Software License, Version 1.0. # include # include #elif defined(__linux__) -# define MY_ARC_FOR_LINUX 1 +# define DXLE_ARC_FOR_LINUX 1 # include # include # include @@ -114,7 +114,7 @@ namespace dxle { } } #else -# define MY_NO_ASM +# define DXLE_NO_ASM #endif//!defined(_MSC_VER) || !defined(__clang__) namespace dxle { namespace detail { @@ -176,7 +176,7 @@ namespace dxle { return re; });// ベクタの初期化 #endif //_CRT_RAND_S -#ifndef MY_NO_ASM +#ifndef DXLE_NO_ASM if (intrin::IsRDRANDsupport()) {//RDRAND命令の結果もベクターに追加 for (unsigned int i = 0; i < 4; i++) { unsigned int rdrand_value = 0; @@ -203,15 +203,15 @@ namespace dxle { } } } -#endif//!defined(MY_NO_ASM) -#ifdef MY_ARC_FOR_WINDWOS +#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 //MY_ARC_FOR_WINDWOS -#ifdef MY_ARC_FOR_LINUX +#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()); From f711d69c8939163a0361f18dd3d968a7760e2bf9 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 8 Aug 2016 00:45:29 +0900 Subject: [PATCH 10/39] test_point_c_test : add test for div operators --- tests/no_dxlib/test_point_c.hpp | 48 ++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp index 9c0ea6c..2f768f2 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/test_point_c.hpp @@ -318,13 +318,49 @@ IUTEST_TYPED_TEST(point_c_test, operator_mul) { const auto value1_x = get_rand(); const auto value1_y = get_rand(); dxle::point_c value1 = { value1_x, value1_y }; - const auto first_mul_dist = get_rand(); - auto value2 = value1 * first_mul_dist; - IUTEST_ASSERT(value2.x == value1_x * first_mul_dist); - IUTEST_ASSERT(value2.y == value1_y * first_mul_dist); - auto value3 = first_mul_dist * value1; + const auto first_mul_num = get_rand(); + auto value2 = value1 * first_mul_num; + IUTEST_ASSERT(value2.x == value1_x * first_mul_num); + IUTEST_ASSERT(value2.y == value1_y * first_mul_num); + auto value3 = first_mul_num * value1; IUTEST_ASSERT(value2 == value3); - value1 *= first_mul_dist; + value1 *= first_mul_num; IUTEST_ASSERT(value3 == value1); } } +template +T get_rand_for_div1(T min, T max) { + const auto minmax = std::minmax(min, max); + const auto re = dxle::uniform_normal_distribution(minmax.first, minmax.second)(engine); + return (0 != re) ? re : get_rand_for_div1(min, max); +} +template::value, std::nullptr_t> = nullptr> +T get_rand_for_div2(T n1, T n2) { + const auto min = std::min(std::abs(n1), std::abs(n2)); + return get_rand_for_div1(1, min); +} +template::value, std::nullptr_t> = nullptr> +T get_rand_for_div2(T n1, T n2) { + const auto min = std::min(n1, n2); + return get_rand_for_div1(1u, min); +} +IUTEST_TYPED_TEST(point_c_test, operator_div) { + using type = TypeParam; + using lim = std::numeric_limits; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand_for_div1(lim::min(), lim::max()); + const auto value1_y = get_rand_for_div1(lim::min(), lim::max()); + dxle::point_c value1 = { value1_x, value1_y }; + const auto first_div_num = get_rand_for_div2(value1_x, value1_y); + auto value2 = value1 / first_div_num; + IUTEST_ASSERT(value2.x == value1_x / first_div_num); + IUTEST_ASSERT(value2.y == value1_y / first_div_num); + value1 /= first_div_num; + IUTEST_ASSERT(value2 == value1); + } +} From 4862b5173df9c34f6acb3c23ca054b6a8ffaf626 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 8 Aug 2016 02:30:25 +0900 Subject: [PATCH 11/39] test_point_c_test : add test for abs free function without for unsigned types ref : #87 --- tests/no_dxlib/test_point_c.hpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp index 2f768f2..afa5e26 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/test_point_c.hpp @@ -364,3 +364,32 @@ IUTEST_TYPED_TEST(point_c_test, operator_div) { IUTEST_ASSERT(value2 == value1); } } +namespace detail { + template::value> + struct point_c_test_abs_helper { + void operator()(){} + }; + template + struct point_c_test_abs_helper { + using type = T; + void operator()() { + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::lowest(), -1); + auto get_rand = [&dist]() { return dist(engine); }; + for ( + #ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] + #endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + dxle::point_c value1 = { value1_x, value1_y }; + IUTEST_ASSERT(dxle::point_c(dxle::abs(value1_x), dxle::abs(value1_y)) == dxle::abs(value1)); + } + } + }; +} +IUTEST_TYPED_TEST(point_c_test, abs) { + detail::point_c_test_abs_helper()(); +} From 1f11f383d4e9d3853d0d8130f218320abb5e8233 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 8 Aug 2016 10:31:02 +0900 Subject: [PATCH 12/39] test_point_c_test : add testcase for dot product function --- tests/no_dxlib/test_point_c.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp index afa5e26..2bbb06d 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/test_point_c.hpp @@ -393,3 +393,21 @@ namespace detail { IUTEST_TYPED_TEST(point_c_test, abs) { detail::point_c_test_abs_helper()(); } +IUTEST_TYPED_TEST(point_c_test, dot_product) { + using type = TypeParam; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(inferior_sqrt2(lim::min()) / 2, inferior_sqrt(lim::max()) / 2); + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const dxle::point_c value1 = { get_rand(), get_rand() }; + const dxle::point_c value2 = { get_rand(), get_rand() }; + const auto re1 = dxle::dot(value1, value2); + const auto re2 = value1.x * value2.x + value1.y * value2.y; + IUTEST_ASSERT(re1 == re2); + } +} From 0101daf1dceaac1bda24d697115ef1ed7286330f Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 8 Aug 2016 11:04:40 +0900 Subject: [PATCH 13/39] fix compile error on VS2013 --- dxlibex/char_constant/char_constant.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dxlibex/char_constant/char_constant.hpp b/dxlibex/char_constant/char_constant.hpp index d26dd38..3fe633d 100644 --- a/dxlibex/char_constant/char_constant.hpp +++ b/dxlibex/char_constant/char_constant.hpp @@ -10,7 +10,9 @@ #include "dxlibex/config/no_min_max.h" #include "dxlibex/config/defines.h" #include -#include +#if DXLE_USE_UNICODE_LITERALS +# include +#endif namespace dxle{ namespace char_constant{ template From 460ed72d03aa172a2083abce39bf8cba47bc17eb Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 8 Aug 2016 11:05:22 +0900 Subject: [PATCH 14/39] test_point_c_test : fix compile error on VS2013 --- tests/no_dxlib/test_point_c.hpp | 58 +++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp index 2bbb06d..e8bf92b 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/test_point_c.hpp @@ -280,10 +280,18 @@ IUTEST_TYPED_TEST(point_c_test, operator_sub) { IUTEST_ASSERT(value2.y == value1_y - first_sub_dist - second_sub_dist); } } -template::value, std::nullptr_t> = nullptr> -T inferior_sqrt(T x) { return static_cast(::std::sqrt(x)); } -template::value, std::nullptr_t> = nullptr> -T inferior_sqrt(T x) { return (x < 0) ? 0 : static_cast(::std::sqrt(x)); } +namespace deatil{ + template::value> + struct inferior_sqrt_helper{ + T operator()(T x){ return static_cast(::std::sqrt(x)); } + }; + template + struct inferior_sqrt_helper{ + T operator()(T x){ return (x < 0) ? 0 : static_cast(::std::sqrt(x)); } + }; +} +template +T inferior_sqrt(T x) { return deatil::inferior_sqrt_helper()(x); } std::int64_t inferior_sqrt(const std::int64_t x) { return (x < 0) ? 0 : x < static_cast(std::numeric_limits::max()) ? static_cast(::std::sqrt(x)) : static_cast(inferior_sqrt(static_cast(x))); @@ -300,10 +308,18 @@ std::uint64_t inferior_sqrt(const std::uint64_t x) } while (s < t); return t; } -template::value, std::nullptr_t> = nullptr> -T inferior_sqrt2(T x) { return (x < 0) ? -inferior_sqrt(-x) : inferior_sqrt(x); } -template::value, std::nullptr_t> = nullptr> -T inferior_sqrt2(T x) { return inferior_sqrt(x); } +namespace deatil{ + template::value> + struct inferior_sqrt2_helper{ + T operator()(T x){ return inferior_sqrt(x); } + }; + template + struct inferior_sqrt2_helper{ + T operator()(T x){ return (x < 0) ? -inferior_sqrt(-x) : inferior_sqrt(x); } + }; +} +template +T inferior_sqrt2(T x) { return deatil::inferior_sqrt2_helper()(x); } IUTEST_TYPED_TEST(point_c_test, operator_mul) { using type = TypeParam; using lim = std::numeric_limits; @@ -334,16 +350,24 @@ T get_rand_for_div1(T min, T max) { const auto re = dxle::uniform_normal_distribution(minmax.first, minmax.second)(engine); return (0 != re) ? re : get_rand_for_div1(min, max); } -template::value, std::nullptr_t> = nullptr> -T get_rand_for_div2(T n1, T n2) { - const auto min = std::min(std::abs(n1), std::abs(n2)); - return get_rand_for_div1(1, min); -} -template::value, std::nullptr_t> = nullptr> -T get_rand_for_div2(T n1, T n2) { - const auto min = std::min(n1, n2); - return get_rand_for_div1(1u, min); +namespace deatil{ + template::value> + struct get_rand_for_div2_helper{ + T operator()(T n1, T n2) { + const auto min = std::min(n1, n2); + return get_rand_for_div1(1u, min); + } + }; + template + struct get_rand_for_div2_helper{ + T operator()(T n1, T n2) { + const auto min = std::min(std::abs(n1), std::abs(n2)); + return get_rand_for_div1(1, min); + } + }; } +template +T get_rand_for_div2(T n1, T n2) { return deatil::get_rand_for_div2_helper()(n1, n2); } IUTEST_TYPED_TEST(point_c_test, operator_div) { using type = TypeParam; using lim = std::numeric_limits; From e073b8023cc5c28c4f8a70faf8603246ce28c8eb Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 8 Aug 2016 11:21:28 +0900 Subject: [PATCH 15/39] test_point_c_test : add test for abs free function whitch takes unsigned types ref : #87 --- tests/no_dxlib/test_point_c.hpp | 38 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp index e8bf92b..3ec186a 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/test_point_c.hpp @@ -391,31 +391,33 @@ IUTEST_TYPED_TEST(point_c_test, operator_div) { namespace detail { template::value> struct point_c_test_abs_helper { - void operator()(){} + using type = T; + using lim = std::numeric_limits; + type operator()() { return lim::max(); } }; template struct point_c_test_abs_helper { using type = T; - void operator()() { - using lim = std::numeric_limits; - dxle::uniform_normal_distribution dist(lim::lowest(), -1); - auto get_rand = [&dist]() { return dist(engine); }; - for ( - #ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] - #endif - auto i : dxle::rep(10) - ) { - const auto value1_x = get_rand(); - const auto value1_y = get_rand(); - dxle::point_c value1 = { value1_x, value1_y }; - IUTEST_ASSERT(dxle::point_c(dxle::abs(value1_x), dxle::abs(value1_y)) == dxle::abs(value1)); - } - } + using lim = std::numeric_limits; + type operator()() { return -1; } }; } IUTEST_TYPED_TEST(point_c_test, abs) { - detail::point_c_test_abs_helper()(); + using type = TypeParam; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::lowest(), detail::point_c_test_abs_helper()()); + auto get_rand = [&dist]() { return dist(engine); }; + for ( +#ifndef DXLE_NO_CXX11_ATTRIBUTES + [[gnu::unused]] +#endif + auto i : dxle::rep(10) + ) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + dxle::point_c value1 = { value1_x, value1_y }; + IUTEST_ASSERT(dxle::point_c(dxle::abs(value1_x), dxle::abs(value1_y)) == dxle::abs(value1)); + } } IUTEST_TYPED_TEST(point_c_test, dot_product) { using type = TypeParam; From 032de7e584fd0c09488b8af4c773e52a1a9e5504 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 01:12:33 +0900 Subject: [PATCH 16/39] project setting: support vs2017 --- samples/timer/timer.vcxproj | 3 +-- vcxcompat.props | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/samples/timer/timer.vcxproj b/samples/timer/timer.vcxproj index 257df50..029a714 100644 --- a/samples/timer/timer.vcxproj +++ b/samples/timer/timer.vcxproj @@ -16,16 +16,15 @@ timer + Application true - v140 MultiByte Application false - v140 true MultiByte diff --git a/vcxcompat.props b/vcxcompat.props index 30ef0d0..9e7cee8 100644 --- a/vcxcompat.props +++ b/vcxcompat.props @@ -6,4 +6,7 @@ v140 + + v141 + From 70384fbf23e73576974d8e52eab29fa66e87f7ab Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 01:12:45 +0900 Subject: [PATCH 17/39] update gitignore for VS2017 and test --- .gitignore | 135 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 0dee9e3..ccf9e48 100644 --- a/.gitignore +++ b/.gitignore @@ -4,28 +4,34 @@ # User-specific files *.suo *.user +*.userosscache *.sln.docstates +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + # Build results -[Dd]ebug/ +*[Dd]ebug/ [Dd]ebugPublic/ -[Rr]elease/ -clang_Debug/ -clang_Release/ -x64/ -build/ +*[Rr]elease/ +[Rr]eleases/ +[Xx]64/ +[Xx]86/ +[Bb]uild/ bld/ [Bb]in/ [Oo]bj/ -# Roslyn cache directories -*.ide/ +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* -#NUNIT +# NUNIT *.VisualState.xml TestResult.xml @@ -34,6 +40,10 @@ TestResult.xml [Rr]eleasePS/ dlldata.c +# DNX +project.lock.json +artifacts/ + *_i.c *_p.c *_i.h @@ -52,15 +62,12 @@ dlldata.c *.tmp *.tmp_proj *.log -*.tlog -*.exe *.vspscc *.vssscc .builds *.pidb *.svclog *.scc -*.lastbuildstate # Chutzpah Test files _Chutzpah* @@ -69,14 +76,17 @@ _Chutzpah* ipch/ *.aps *.ncb +*.opendb *.opensdf *.sdf *.cachefile +*.VC.db # Visual Studio profiler *.psess *.vsp *.vspx +*.sap # TFS 2012 Local Workspace $tf/ @@ -89,7 +99,7 @@ _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user -# JustCode is a .NET coding addin-in +# JustCode is a .NET coding add-in .JustCode # TeamCity is a build add-in @@ -101,6 +111,7 @@ _TeamCity* # NCrunch _NCrunch_* .*crunch*.local.xml +nCrunchTemp_* # MightyMoose *.mm.* @@ -128,33 +139,47 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml -## TODO: Comment the next line if you want to checkin your -## web deploy settings but do note that will include unencrypted -## passwords -#*.pubxml - -# NuGet Packages Directory -packages/* -## TODO: If the tool you use requires repositories.config -## uncomment the next line -#!packages/repositories.config -# Enable "build/" folder in the NuGet Packages folder since -# NuGet packages use it for MSBuild targets. -# This line needs to be after the ignore of the build folder -# (and the packages folder if the line above has been uncommented) -!packages/build/ - -# Windows Azure Build Output +# TODO: Un-comment the next line if you do not want to checkin +# your web deploy settings because they may include unencrypted +# passwords +#*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output csx/ *.build.csdef +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Microsoft Azure ApplicationInsights config file +ApplicationInsights.config + # Windows Store app package directory AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ # Others -sql/ -*.Cache ClientBin/ [Ss]tyle[Cc]op.* ~$* @@ -164,6 +189,7 @@ ClientBin/ *.pfx *.publishsettings node_modules/ +orleans.codegen.cs # RIA/Silverlight projects Generated_Code/ @@ -188,17 +214,46 @@ UpgradeLog*.htm # Microsoft Fakes FakesAssemblies/ +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + # LightSwitch generated files GeneratedArtifacts/ -_Pvt_Extensions/ ModelManifest.xml -#other +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ + +# gcov/lcov +coverage.info +*.gcda +*.gcno + +# Other +*.dump +*.out +*.exe Log.txt -*.VC.opendb -*.VC.db *.exp -dxlibex/ProjectDxLibEx_v1[24]0_MultiByte_x86_d.idb -dxlibex/ProjectDxLibEx_v1[24]0_MultiByte_x86_[dr].lib -dxlibex/ProjectDxLibEx_v1[24]0_MultiByte_x64_d.idb -dxlibex/ProjectDxLibEx_v1[24]0_MultiByte_x64_[dr].lib +dxlibex/ProjectDxLibEx_v*_MultiByte_x*_[dr].idb +dxlibex/ProjectDxLibEx_v*_MultiByte_x*_[dr].lib From ed073ba0558733feea16d1356636d4d049c449b1 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 02:02:06 +0900 Subject: [PATCH 18/39] remove dead file from project --- tests/with_dxLib/with_dxLib.vcxproj.filters | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/with_dxLib/with_dxLib.vcxproj.filters b/tests/with_dxLib/with_dxLib.vcxproj.filters index 5924fa6..ff69490 100644 --- a/tests/with_dxLib/with_dxLib.vcxproj.filters +++ b/tests/with_dxLib/with_dxLib.vcxproj.filters @@ -12,8 +12,6 @@ - - ソース ファイル - + \ No newline at end of file From 9dc93c94fcf0eb5f24b3cdadb512fff23b018316 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 02:02:48 +0900 Subject: [PATCH 19/39] remove trailing space --- tests/no_dxlib/random.hpp | 2 +- tests/no_dxlib/test_point_c.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/no_dxlib/random.hpp b/tests/no_dxlib/random.hpp index 2f75a69..d11ba83 100644 --- a/tests/no_dxlib/random.hpp +++ b/tests/no_dxlib/random.hpp @@ -28,7 +28,7 @@ Distributed under the Boost Software License, Version 1.0. # include #elif defined(__linux__) # define DXLE_ARC_FOR_LINUX 1 -# include +# include # include # include namespace dxle { diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp index 3ec186a..64e1a2a 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/test_point_c.hpp @@ -130,7 +130,7 @@ IUTEST_TYPED_TEST(point_c_test, istream_operator) { ) { std::stringstream ss1; ss1 << get_rand() << ", " << get_rand(); - std::stringstream ss2; + std::stringstream ss2; ss2 << ss1.str(); type v1, v2; ss1 >> v1; @@ -153,7 +153,7 @@ IUTEST_TYPED_TEST(point_c_test, wistream_operator) { ) { std::wstringstream ss1; ss1 << get_rand() << L", " << get_rand(); - std::wstringstream ss2; + std::wstringstream ss2; ss2 << ss1.str(); type v1, v2; ss1 >> v1; From df9f9f9882543310cc2325f1671fe3991600fb81 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 02:04:50 +0900 Subject: [PATCH 20/39] use function-pointer as seed source (expect ASLR) --- tests/no_dxlib/random.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/no_dxlib/random.hpp b/tests/no_dxlib/random.hpp index d11ba83..f1318ef 100644 --- a/tests/no_dxlib/random.hpp +++ b/tests/no_dxlib/random.hpp @@ -222,6 +222,8 @@ namespace dxle { auto heap = std::make_unique(); sed_v | push_back(heap.get()); sed_v | push_back(&heap); + sed_v | push_back(time); + sed_v | push_back(create_engine); const auto end_time = std::chrono::high_resolution_clock::now(); sed_v | push_back((end_time - begin_time).count()); return sed_v; From 2dfa5839bcaac7322e94b8221d511cfe85f6855a Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 11:31:35 +0900 Subject: [PATCH 21/39] add macro DXLE_UNUSED --- dxlibex/config/compiler/clang.hpp | 8 ++++++++ dxlibex/config/compiler/gcc.hpp | 2 ++ dxlibex/config/compiler/intel.hpp | 2 ++ dxlibex/config/compiler/visualc.hpp | 7 +++++++ dxlibex/config/suffix.hpp | 12 ++++++++++++ 5 files changed, 31 insertions(+) diff --git a/dxlibex/config/compiler/clang.hpp b/dxlibex/config/compiler/clang.hpp index 24eb4f5..50922c4 100644 --- a/dxlibex/config/compiler/clang.hpp +++ b/dxlibex/config/compiler/clang.hpp @@ -72,4 +72,12 @@ Proprietary extension #define DXLE_HAS_GNU_DEPRECATED_WITH_MESSAGE_SUPPORT #endif + +/* +C++17 +*/ +#if __clang_major < 3 || (__clang_major__ == 3 && __clang_minor__ < 9) || __has_cpp_attribute(maybe_unused) < 201603 +# define DXLE_NO_CXX17_UNUSED +#endif + #endif // #ifndef DXLE_INC_CONFIG_COMPILER_CLANG_HPP_ diff --git a/dxlibex/config/compiler/gcc.hpp b/dxlibex/config/compiler/gcc.hpp index 34a4e2b..d67f2c2 100644 --- a/dxlibex/config/compiler/gcc.hpp +++ b/dxlibex/config/compiler/gcc.hpp @@ -64,4 +64,6 @@ Proprietary extension # define DXLE_HAS_GNU_DEPRECATED_WITH_MESSAGE_SUPPORT #endif +#define DXLE_NO_CXX17_UNUSED + #endif // #ifndef DXLE_INC_CONFIG_COMPILER_GCC_HPP_ diff --git a/dxlibex/config/compiler/intel.hpp b/dxlibex/config/compiler/intel.hpp index f8b5023..1d54618 100644 --- a/dxlibex/config/compiler/intel.hpp +++ b/dxlibex/config/compiler/intel.hpp @@ -47,4 +47,6 @@ # define DXLE_NO_CXX11_TEMPLATE_ALIASES #endif +#define DXLE_NO_CXX17_UNUSED + #endif // #ifndef DXLE_CONFIG_COMPILER_INTEL_HPP_ diff --git a/dxlibex/config/compiler/visualc.hpp b/dxlibex/config/compiler/visualc.hpp index 910d77d..37700d2 100644 --- a/dxlibex/config/compiler/visualc.hpp +++ b/dxlibex/config/compiler/visualc.hpp @@ -43,4 +43,11 @@ C++14 # define DXLE_NO_CXX14_UDLS_FOR_STRING_AND_CHRONO #endif +/* +C++17 +*/ +#if _MSC_FULL_VER <= 191024629 || 201402 == _MSVC_LANG +#define DXLE_NO_CXX17_UNUSED +#endif + #endif // #ifndef DXLE_INC_CONFIG_COMPILER_VISUALC_HPP_ diff --git a/dxlibex/config/suffix.hpp b/dxlibex/config/suffix.hpp index 01cc6bd..7109039 100644 --- a/dxlibex/config/suffix.hpp +++ b/dxlibex/config/suffix.hpp @@ -141,4 +141,16 @@ // #define DXLE_PREVENT_MACRO_SUBSTITUTION +#ifndef DXLE_NO_CXX17_UNUSED +# define DXLE_UNUSED [[maybe_unused]] +#elif defined(__GNUC__) +# ifndef DXLE_NO_CXX11_ATTRIBUTES +# define DXLE_UNUSED [[gnu::unused]] +# else +# define DXLE_UNUSED __attribute__((unused)) +# endif +#else +# define DXLE_UNUSED +#endif + #endif // #ifndef DXLE_INC_CONFIG_SUFFIX_HPP_ From 01133cae04fed58598dccd15c11e76621115eadb Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 11:33:25 +0900 Subject: [PATCH 22/39] use DXLE_UNUSED --- tests/no_dxlib/test_point_c.hpp | 101 ++++++-------------------------- 1 file changed, 17 insertions(+), 84 deletions(-) diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/test_point_c.hpp index 64e1a2a..788a7ed 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/test_point_c.hpp @@ -14,6 +14,9 @@ #include #include #include +#if defined(_MSC_VER) && !defined(__c2__) +# pragma warning(disable: 4189) +#endif template DXLE_CONSTEXPR bool is_l_zero(T&& val) { return static_cast(0) == val; @@ -29,12 +32,7 @@ IUTEST_TYPED_TEST(point_c_test, construct) { using type = TypeParam; dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { const auto value_x = get_rand(); const auto value_y = get_rand(); const dxle::point_c value = { value_x, value_y }; @@ -66,12 +64,7 @@ IUTEST_TYPED_TEST(point_c_test, operaotr_eq) { IUTEST_ASSERT(eq1); dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { const auto value_x = get_rand(); const auto value_y = get_rand(); const dxle::point_c value = { value_x, value_y }; @@ -82,12 +75,7 @@ IUTEST_TYPED_TEST(point_c_test, ostream_operator) { using type = TypeParam; dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { const auto x = get_rand(); const auto y = get_rand(); std::stringstream ss1; @@ -102,12 +90,7 @@ IUTEST_TYPED_TEST(point_c_test, wostream_operator) { using type = TypeParam; dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { const auto x = get_rand(); const auto y = get_rand(); std::wstringstream ss1; @@ -122,12 +105,7 @@ IUTEST_TYPED_TEST(point_c_test, istream_operator) { using type = TypeParam; dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { std::stringstream ss1; ss1 << get_rand() << ", " << get_rand(); std::stringstream ss2; @@ -145,12 +123,7 @@ IUTEST_TYPED_TEST(point_c_test, wistream_operator) { using type = TypeParam; dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { std::wstringstream ss1; ss1 << get_rand() << L", " << get_rand(); std::wstringstream ss2; @@ -170,12 +143,7 @@ IUTEST_TYPED_TEST(point_c_test, unary_operaotr_plus) { IUTEST_ASSERT(eq1); dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { const dxle::point_c value1 = { get_rand(), get_rand() }; const auto value2 = +value1; IUTEST_ASSERT(value1 == value2); @@ -195,12 +163,7 @@ namespace detail { IUTEST_ASSERT(eq1); dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { const auto x = get_rand(); const auto y = get_rand(); @@ -228,12 +191,7 @@ IUTEST_TYPED_TEST(point_c_test, operator_add) { using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { const auto value1_x = get_rand(); const auto value1_y = get_rand(); const dxle::point_c value1 = { value1_x, value1_y }; @@ -261,12 +219,7 @@ IUTEST_TYPED_TEST(point_c_test, operator_sub) { using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { const auto value1_x = get_rand(); const auto value1_y = get_rand(); const dxle::point_c value1 = { value1_x, value1_y }; @@ -325,12 +278,7 @@ IUTEST_TYPED_TEST(point_c_test, operator_mul) { using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(inferior_sqrt2(lim::min()), inferior_sqrt(lim::max())); auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { const auto value1_x = get_rand(); const auto value1_y = get_rand(); dxle::point_c value1 = { value1_x, value1_y }; @@ -371,12 +319,7 @@ T get_rand_for_div2(T n1, T n2) { return deatil::get_rand_for_div2_helper()(n IUTEST_TYPED_TEST(point_c_test, operator_div) { using type = TypeParam; using lim = std::numeric_limits; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { const auto value1_x = get_rand_for_div1(lim::min(), lim::max()); const auto value1_y = get_rand_for_div1(lim::min(), lim::max()); dxle::point_c value1 = { value1_x, value1_y }; @@ -407,12 +350,7 @@ IUTEST_TYPED_TEST(point_c_test, abs) { using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::lowest(), detail::point_c_test_abs_helper()()); auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { const auto value1_x = get_rand(); const auto value1_y = get_rand(); dxle::point_c value1 = { value1_x, value1_y }; @@ -424,12 +362,7 @@ IUTEST_TYPED_TEST(point_c_test, dot_product) { using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(inferior_sqrt2(lim::min()) / 2, inferior_sqrt(lim::max()) / 2); auto get_rand = [&dist]() { return dist(engine); }; - for ( -#ifndef DXLE_NO_CXX11_ATTRIBUTES - [[gnu::unused]] -#endif - auto i : dxle::rep(10) - ) { + for (DXLE_UNUSED auto i : dxle::rep(10)) { const dxle::point_c value1 = { get_rand(), get_rand() }; const dxle::point_c value2 = { get_rand(), get_rand() }; const auto re1 = dxle::dot(value1, value2); From 5414376aeb6b618e5fff6d614e52cc4cf46df5a8 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 11:33:38 +0900 Subject: [PATCH 23/39] fix compile error --- tests/no_dxlib/random.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/no_dxlib/random.hpp b/tests/no_dxlib/random.hpp index f1318ef..9ca2d99 100644 --- a/tests/no_dxlib/random.hpp +++ b/tests/no_dxlib/random.hpp @@ -223,12 +223,11 @@ namespace dxle { sed_v | push_back(heap.get()); sed_v | push_back(&heap); sed_v | push_back(time); - sed_v | push_back(create_engine); const auto end_time = std::chrono::high_resolution_clock::now(); sed_v | push_back((end_time - begin_time).count()); return sed_v; } - std::mt19937 create_engine() { + 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); From 5c6eecdd666cb59b6567ba13a70418d3932637f3 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 11:58:22 +0900 Subject: [PATCH 24/39] change file path --- tests/{no_dxlib => include}/random.hpp | 0 tests/no_dxlib/{test_point_c.hpp => basic_types/point2d.hpp} | 2 +- tests/no_dxlib/no_dxlib.vcxproj | 3 +-- tests/no_dxlib/no_dxlib.vcxproj.filters | 3 +-- tests/no_dxlib/no_dxlib_test.cpp | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) rename tests/{no_dxlib => include}/random.hpp (100%) rename tests/no_dxlib/{test_point_c.hpp => basic_types/point2d.hpp} (99%) diff --git a/tests/no_dxlib/random.hpp b/tests/include/random.hpp similarity index 100% rename from tests/no_dxlib/random.hpp rename to tests/include/random.hpp diff --git a/tests/no_dxlib/test_point_c.hpp b/tests/no_dxlib/basic_types/point2d.hpp similarity index 99% rename from tests/no_dxlib/test_point_c.hpp rename to tests/no_dxlib/basic_types/point2d.hpp index 788a7ed..f6ac114 100644 --- a/tests/no_dxlib/test_point_c.hpp +++ b/tests/no_dxlib/basic_types/point2d.hpp @@ -9,7 +9,7 @@ #include #include #include -#include "random.hpp" +#include #include #include #include diff --git a/tests/no_dxlib/no_dxlib.vcxproj b/tests/no_dxlib/no_dxlib.vcxproj index 4d7883f..5b89700 100644 --- a/tests/no_dxlib/no_dxlib.vcxproj +++ b/tests/no_dxlib/no_dxlib.vcxproj @@ -220,8 +220,7 @@ - - + diff --git a/tests/no_dxlib/no_dxlib.vcxproj.filters b/tests/no_dxlib/no_dxlib.vcxproj.filters index d46c1da..8ec0f5a 100644 --- a/tests/no_dxlib/no_dxlib.vcxproj.filters +++ b/tests/no_dxlib/no_dxlib.vcxproj.filters @@ -12,8 +12,7 @@ - - + ソース ファイル diff --git a/tests/no_dxlib/no_dxlib_test.cpp b/tests/no_dxlib/no_dxlib_test.cpp index aaf1c6a..62ccbc3 100644 --- a/tests/no_dxlib/no_dxlib_test.cpp +++ b/tests/no_dxlib/no_dxlib_test.cpp @@ -6,7 +6,7 @@ Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #include "../../3rd_party/iutest/include/iutest.hpp" -#include "test_point_c.hpp" +#include "basic_types/point2d.hpp" std::mt19937 engine = dxle::create_engine(); int main(int argc, char** argv) { From 467db6af0604899887e9bac9469a5ae363439773 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 12:02:20 +0900 Subject: [PATCH 25/39] specify inline --- tests/include/random.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/include/random.hpp b/tests/include/random.hpp index 9ca2d99..6bd22b4 100644 --- a/tests/include/random.hpp +++ b/tests/include/random.hpp @@ -32,7 +32,7 @@ Distributed under the Boost Software License, Version 1.0. # include # include namespace dxle { - unsigned int get_randome_from_dev_random() { + inline unsigned int get_randome_from_dev_random() { std::ifstream file("/dev/random", std::ios::binary); if (file.is_open()) { @@ -76,7 +76,7 @@ namespace dxle { uint32_t u32[3]; char str[12]; }; - regs_t get_cpuid(unsigned int level) { + 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__) @@ -86,26 +86,26 @@ namespace dxle { # endif return re; } - bool check_vender(const char* s) { + 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))); } - bool IsIntelCPU() { + inline bool IsIntelCPU() { static const auto is_intel_cpu = check_vender("GenuineIntel");//実行中にCPUは変わらないとする return is_intel_cpu; } - bool IsAMDCPU() { + inline bool IsAMDCPU() { static const auto is_amd_cpu = check_vender("AuthenticAMD"); return is_amd_cpu; } - bool IsRDRANDsupport() { + 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)); } - bool IsRDSEEDsupport() { + 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. @@ -146,7 +146,7 @@ namespace dxle { } }; template::value || std::is_arithmetic::value, std::nullptr_t> = nullptr> - void operator| (std::vector& v, vector_push_back_helper info) { + inline void operator| (std::vector& v, vector_push_back_helper info) { vector_push_back_operator_impl ()(v, info); } } @@ -155,7 +155,7 @@ namespace dxle { template dxle::detail::vector_push_back_helper push_back(T pointer) { return{ pointer }; } using seed_v_t = std::vector; - seed_v_t create_seed_v() { + 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. From 8866c921fed32032aab25e91448aa19b394c6119 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 12:44:43 +0900 Subject: [PATCH 26/39] add testcase for size_c --- tests/include/math.hpp | 52 +++++ tests/include/random.hpp | 7 +- tests/include/random_wrap.hpp | 59 +++++ tests/include/utility.hpp | 22 ++ tests/no_dxlib/basic_types/point2d.hpp | 139 +++--------- tests/no_dxlib/basic_types/size.hpp | 272 ++++++++++++++++++++++++ tests/no_dxlib/no_dxlib.vcxproj | 1 + tests/no_dxlib/no_dxlib.vcxproj.filters | 3 + tests/no_dxlib/no_dxlib_test.cpp | 1 + 9 files changed, 439 insertions(+), 117 deletions(-) create mode 100644 tests/include/math.hpp create mode 100644 tests/include/random_wrap.hpp create mode 100644 tests/include/utility.hpp create mode 100644 tests/no_dxlib/basic_types/size.hpp diff --git a/tests/include/math.hpp b/tests/include/math.hpp new file mode 100644 index 0000000..ed21633 --- /dev/null +++ b/tests/include/math.hpp @@ -0,0 +1,52 @@ +/*============================================================================= +Copyright (C) 2015-2016 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::value> + struct inferior_sqrt_helper { + T operator()(T x) { return static_cast(::std::sqrt(x)); } + }; + template + struct inferior_sqrt_helper { + T operator()(T x) { return (x < 0) ? 0 : static_cast(::std::sqrt(x)); } + }; +} +template +T inferior_sqrt(T x) { return detail::inferior_sqrt_helper()(x); } +inline std::int64_t inferior_sqrt(const std::int64_t x) +{ + return (x < 0) ? 0 : x < static_cast(std::numeric_limits::max()) ? static_cast(::std::sqrt(x)) + : static_cast(inferior_sqrt(static_cast(x))); +} +inline std::uint64_t inferior_sqrt(const std::uint64_t x) +{ + if (x < static_cast(std::numeric_limits::max())) return static_cast(::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; +} +namespace detail { + template::value> + struct inferior_sqrt2_helper { + T operator()(T x) { return inferior_sqrt(x); } + }; + template + struct inferior_sqrt2_helper { + T operator()(T x) { return (x < 0) ? -inferior_sqrt(-x) : inferior_sqrt(x); } + }; +} +template +T inferior_sqrt2(T x) { return detail::inferior_sqrt2_helper()(x); } + +#endif //DXLE_TESTS_INCLUDE_MATH_HPP_ diff --git a/tests/include/random.hpp b/tests/include/random.hpp index 6bd22b4..b3a935a 100644 --- a/tests/include/random.hpp +++ b/tests/include/random.hpp @@ -5,9 +5,8 @@ Copyright (C) 2015-2016 DxLibEx project Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#ifndef DXLE_TEST_NO_DXLIB_RANDOM_HPP_ -#define DXLE_TEST_NO_DXLIB_RANDOM_HPP_ -#pragma once +#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 @@ -239,4 +238,4 @@ namespace dxle { >; } extern std::mt19937 engine; -#endif //DXLE_TEST_NO_DXLIB_RANDOM_HPP_ +#endif //DXLE_TESTS_INCLUDE_RANDOM_HPP_ diff --git a/tests/include/random_wrap.hpp b/tests/include/random_wrap.hpp new file mode 100644 index 0000000..c15f189 --- /dev/null +++ b/tests/include/random_wrap.hpp @@ -0,0 +1,59 @@ +/*============================================================================= +Copyright (C) 2015-2016 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_WRAP_HPP_ +#define DXLE_TESTS_INCLUDE_RANDOM_WRAP_HPP_ +#include "random.hpp" +template +inline T get_rand_for_add(T n1, T n2, int modifier) +{ + using lim = std::numeric_limits; + const auto minmax = std::minmax(n1, n2); + return dxle::uniform_normal_distribution( + (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifier, + (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifier + )(engine); +} +template +T get_rand_for_sub(T n1, T n2, int modifier) +{ + using lim = std::numeric_limits; + const auto minmax = std::minmax(n1, n2); + return dxle::uniform_normal_distribution( + (minmax.first < 0) ? lim::min() : lim::min() + minmax.first + modifier, + (minmax.second > 0) ? lim::max() : lim::max() + minmax.second - modifier + )(engine); +} +template +T get_rand_for_div1(T min, T max) +{ + const auto minmax = std::minmax(min, max); + const auto re = dxle::uniform_normal_distribution(minmax.first, minmax.second)(engine); + return (0 != re) ? re : get_rand_for_div1(min, max); +} +namespace detail { + template::value> + struct get_rand_for_div2_helper { + T operator()(T n1, T n2) + { + const auto min = std::min(n1, n2); + return get_rand_for_div1(1u, min); + } + }; + template + struct get_rand_for_div2_helper { + T operator()(T n1, T n2) + { + const auto min = std::min(std::abs(n1), std::abs(n2)); + return get_rand_for_div1(1, min); + } + }; +} +template +T get_rand_for_div2(T n1, T n2) { return detail::get_rand_for_div2_helper()(n1, n2); } + +#endif //DXLE_TESTS_INCLUDE_RANDOM_WRAP_HPP_ diff --git a/tests/include/utility.hpp b/tests/include/utility.hpp new file mode 100644 index 0000000..00bb450 --- /dev/null +++ b/tests/include/utility.hpp @@ -0,0 +1,22 @@ +/*============================================================================= +Copyright (C) 2015-2016 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_UTILITY_HPP_ +#define DXLE_TESTS_INCLUDE_UTILITY_HPP_ +#include "dxlibex/config/defines.h" +template +DXLE_CONSTEXPR bool is_l_zero(T&& val) +{ + return static_cast(0) == val; +} +template +DXLE_CONSTEXPR bool is_l_zero(T&& val, Rest&&... rest) +{ + return static_cast(0) == val && is_l_zero(std::forward(rest)...); +} + +#endif //DXLE_TESTS_INCLUDE_UTILITY_HPP_ diff --git a/tests/no_dxlib/basic_types/point2d.hpp b/tests/no_dxlib/basic_types/point2d.hpp index f6ac114..b7961b2 100644 --- a/tests/no_dxlib/basic_types/point2d.hpp +++ b/tests/no_dxlib/basic_types/point2d.hpp @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -18,17 +21,9 @@ # pragma warning(disable: 4189) #endif template -DXLE_CONSTEXPR bool is_l_zero(T&& val) { - return static_cast(0) == val; -} -template -DXLE_CONSTEXPR bool is_l_zero(T&& val, Rest&&... rest) { - return static_cast(0) == val && is_l_zero(std::forward(rest)...); -} -template -struct point_c_test : public ::iutest::Test{}; -IUTEST_TYPED_TEST_CASE(point_c_test, ::iutest::Types); -IUTEST_TYPED_TEST(point_c_test, construct) { +struct basic_types_point2d : public ::iutest::Test{}; +IUTEST_TYPED_TEST_CASE(basic_types_point2d, ::iutest::Types); +IUTEST_TYPED_TEST(basic_types_point2d, construct) { using type = TypeParam; dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; @@ -47,7 +42,7 @@ IUTEST_TYPED_TEST(point_c_test, construct) { IUTEST_ASSERT(value4.x == static_cast(2)); IUTEST_ASSERT(value4.y == static_cast(12)); } -IUTEST_TYPED_TEST(point_c_test, factory) { +IUTEST_TYPED_TEST(basic_types_point2d, factory) { using type = TypeParam; const std::pair pa = { static_cast(12), static_cast(23) }; const auto po = dxle::make_point_c(pa); @@ -58,7 +53,7 @@ IUTEST_TYPED_TEST(point_c_test, factory) { IUTEST_ASSERT(po2.x == pa.first); IUTEST_ASSERT(po2.y == pa.second); } -IUTEST_TYPED_TEST(point_c_test, operaotr_eq) { +IUTEST_TYPED_TEST(basic_types_point2d, operaotr_eq) { using type = TypeParam; const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; IUTEST_ASSERT(eq1); @@ -71,7 +66,7 @@ IUTEST_TYPED_TEST(point_c_test, operaotr_eq) { IUTEST_ASSERT(value == dxle::point_c(value_x, value_y)); } } -IUTEST_TYPED_TEST(point_c_test, ostream_operator) { +IUTEST_TYPED_TEST(basic_types_point2d, ostream_operator) { using type = TypeParam; dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; @@ -86,7 +81,7 @@ IUTEST_TYPED_TEST(point_c_test, ostream_operator) { IUTEST_ASSERT_EQ(ss1.str(), ss2.str()); } } -IUTEST_TYPED_TEST(point_c_test, wostream_operator) { +IUTEST_TYPED_TEST(basic_types_point2d, wostream_operator) { using type = TypeParam; dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; @@ -101,7 +96,7 @@ IUTEST_TYPED_TEST(point_c_test, wostream_operator) { IUTEST_ASSERT_EQ(ss1.str(), ss2.str()); } } -IUTEST_TYPED_TEST(point_c_test, istream_operator) { +IUTEST_TYPED_TEST(basic_types_point2d, istream_operator) { using type = TypeParam; dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; @@ -119,7 +114,7 @@ IUTEST_TYPED_TEST(point_c_test, istream_operator) { IUTEST_ASSERT(v == dxle::point_c(v1, v2)); } } -IUTEST_TYPED_TEST(point_c_test, wistream_operator) { +IUTEST_TYPED_TEST(basic_types_point2d, wistream_operator) { using type = TypeParam; dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; @@ -137,7 +132,7 @@ IUTEST_TYPED_TEST(point_c_test, wistream_operator) { IUTEST_ASSERT(v == dxle::point_c(v1, v2)); } } -IUTEST_TYPED_TEST(point_c_test, unary_operaotr_plus) { +IUTEST_TYPED_TEST(basic_types_point2d, unary_operaotr_plus) { using type = TypeParam; const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; IUTEST_ASSERT(eq1); @@ -151,12 +146,12 @@ IUTEST_TYPED_TEST(point_c_test, unary_operaotr_plus) { } namespace detail { template::value> - struct point_c_test_unary_operaotr_minus_helper { + struct basic_types_point2d_unary_operaotr_minus_helper { using type = T; void operator()() {} }; template - struct point_c_test_unary_operaotr_minus_helper { + struct basic_types_point2d_unary_operaotr_minus_helper { using type = T; void operator()() { const bool eq1 = 0 == dxle::point_c{} && dxle::point_c{} == 0; @@ -174,19 +169,10 @@ namespace detail { } }; } -IUTEST_TYPED_TEST(point_c_test, unary_operaotr_minus) { - detail::point_c_test_unary_operaotr_minus_helper{}(); -} -template -T get_rand_for_add(T n1, T n2, int modifier) { - using lim = std::numeric_limits; - const auto minmax = std::minmax(n1, n2); - return dxle::uniform_normal_distribution( - (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifier, - (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifier - )(engine); +IUTEST_TYPED_TEST(basic_types_point2d, unary_operaotr_minus) { + detail::basic_types_point2d_unary_operaotr_minus_helper{}(); } -IUTEST_TYPED_TEST(point_c_test, operator_add) { +IUTEST_TYPED_TEST(basic_types_point2d, operator_add) { using type = TypeParam; using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); @@ -205,16 +191,7 @@ IUTEST_TYPED_TEST(point_c_test, operator_add) { IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); } } -template -T get_rand_for_sub(T n1, T n2, int modifier) { - using lim = std::numeric_limits; - const auto minmax = std::minmax(n1, n2); - return dxle::uniform_normal_distribution( - (minmax.first < 0) ? lim::min() : lim::min() + minmax.first + modifier, - (minmax.second > 0) ? lim::max() : lim::max() + minmax.second - modifier - )(engine); -} -IUTEST_TYPED_TEST(point_c_test, operator_sub) { +IUTEST_TYPED_TEST(basic_types_point2d, operator_sub) { using type = TypeParam; using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); @@ -233,47 +210,7 @@ IUTEST_TYPED_TEST(point_c_test, operator_sub) { IUTEST_ASSERT(value2.y == value1_y - first_sub_dist - second_sub_dist); } } -namespace deatil{ - template::value> - struct inferior_sqrt_helper{ - T operator()(T x){ return static_cast(::std::sqrt(x)); } - }; - template - struct inferior_sqrt_helper{ - T operator()(T x){ return (x < 0) ? 0 : static_cast(::std::sqrt(x)); } - }; -} -template -T inferior_sqrt(T x) { return deatil::inferior_sqrt_helper()(x); } -std::int64_t inferior_sqrt(const std::int64_t x) { - return (x < 0) ? 0 : x < static_cast(std::numeric_limits::max()) ? static_cast(::std::sqrt(x)) - : static_cast(inferior_sqrt(static_cast(x))); -} -std::uint64_t inferior_sqrt(const std::uint64_t x) -{ - if(x < static_cast(std::numeric_limits::max())) return static_cast(::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; -} -namespace deatil{ - template::value> - struct inferior_sqrt2_helper{ - T operator()(T x){ return inferior_sqrt(x); } - }; - template - struct inferior_sqrt2_helper{ - T operator()(T x){ return (x < 0) ? -inferior_sqrt(-x) : inferior_sqrt(x); } - }; -} -template -T inferior_sqrt2(T x) { return deatil::inferior_sqrt2_helper()(x); } -IUTEST_TYPED_TEST(point_c_test, operator_mul) { +IUTEST_TYPED_TEST(basic_types_point2d, operator_mul) { using type = TypeParam; using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(inferior_sqrt2(lim::min()), inferior_sqrt(lim::max())); @@ -292,31 +229,7 @@ IUTEST_TYPED_TEST(point_c_test, operator_mul) { IUTEST_ASSERT(value3 == value1); } } -template -T get_rand_for_div1(T min, T max) { - const auto minmax = std::minmax(min, max); - const auto re = dxle::uniform_normal_distribution(minmax.first, minmax.second)(engine); - return (0 != re) ? re : get_rand_for_div1(min, max); -} -namespace deatil{ - template::value> - struct get_rand_for_div2_helper{ - T operator()(T n1, T n2) { - const auto min = std::min(n1, n2); - return get_rand_for_div1(1u, min); - } - }; - template - struct get_rand_for_div2_helper{ - T operator()(T n1, T n2) { - const auto min = std::min(std::abs(n1), std::abs(n2)); - return get_rand_for_div1(1, min); - } - }; -} -template -T get_rand_for_div2(T n1, T n2) { return deatil::get_rand_for_div2_helper()(n1, n2); } -IUTEST_TYPED_TEST(point_c_test, operator_div) { +IUTEST_TYPED_TEST(basic_types_point2d, operator_div) { using type = TypeParam; using lim = std::numeric_limits; for (DXLE_UNUSED auto i : dxle::rep(10)) { @@ -333,22 +246,22 @@ IUTEST_TYPED_TEST(point_c_test, operator_div) { } namespace detail { template::value> - struct point_c_test_abs_helper { + struct basic_types_point2d_abs_helper { using type = T; using lim = std::numeric_limits; type operator()() { return lim::max(); } }; template - struct point_c_test_abs_helper { + struct basic_types_point2d_abs_helper { using type = T; using lim = std::numeric_limits; type operator()() { return -1; } }; } -IUTEST_TYPED_TEST(point_c_test, abs) { +IUTEST_TYPED_TEST(basic_types_point2d, abs) { using type = TypeParam; using lim = std::numeric_limits; - dxle::uniform_normal_distribution dist(lim::lowest(), detail::point_c_test_abs_helper()()); + dxle::uniform_normal_distribution dist(lim::lowest(), detail::basic_types_point2d_abs_helper()()); auto get_rand = [&dist]() { return dist(engine); }; for (DXLE_UNUSED auto i : dxle::rep(10)) { const auto value1_x = get_rand(); @@ -357,7 +270,7 @@ IUTEST_TYPED_TEST(point_c_test, abs) { IUTEST_ASSERT(dxle::point_c(dxle::abs(value1_x), dxle::abs(value1_y)) == dxle::abs(value1)); } } -IUTEST_TYPED_TEST(point_c_test, dot_product) { +IUTEST_TYPED_TEST(basic_types_point2d, dot_product) { using type = TypeParam; using lim = std::numeric_limits; dxle::uniform_normal_distribution dist(inferior_sqrt2(lim::min()) / 2, inferior_sqrt(lim::max()) / 2); diff --git a/tests/no_dxlib/basic_types/size.hpp b/tests/no_dxlib/basic_types/size.hpp new file mode 100644 index 0000000..5d97ac7 --- /dev/null +++ b/tests/no_dxlib/basic_types/size.hpp @@ -0,0 +1,272 @@ +/*============================================================================= + Copyright (C) 2015-2016 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) +=============================================================================*/ +#include "../../3rd_party/iutest/include/iutest.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(_MSC_VER) && !defined(__c2__) +# pragma warning(disable: 4189) +#endif +template +struct basic_types_size : public ::iutest::Test{}; +IUTEST_TYPED_TEST_CASE(basic_types_size, ::iutest::Types); +IUTEST_TYPED_TEST(basic_types_size, construct) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value_width = get_rand(); + const auto value_height = get_rand(); + const dxle::size_c value = { value_width, value_height }; + IUTEST_ASSERT(value.width == value_width); + IUTEST_ASSERT(value.height == value_height); + } + const dxle::size_c value1 = {}; + const auto value2 = value1; + const auto value3 = std::move(value1); + IUTEST_ASSERT(is_l_zero(value1.width, value1.height, value2.width, value2.height, value3.width, value3.height)); + const dxle::size_c value4 = { 2, 12 }; + IUTEST_ASSERT(value4.width == static_cast(2)); + IUTEST_ASSERT(value4.height == static_cast(12)); +} +IUTEST_TYPED_TEST(basic_types_size, factory) { + using type = TypeParam; + const std::pair pa = { static_cast(12), static_cast(23) }; + const auto po = dxle::make_size_c(pa); + static_assert(std::is_same::value, "err"); + IUTEST_ASSERT(po.width == pa.first); + IUTEST_ASSERT(po.height == pa.second); + const auto po2 = dxle::make_size_c(std::pair(pa)); + IUTEST_ASSERT(po2.width == pa.first); + IUTEST_ASSERT(po2.height == pa.second); +} +IUTEST_TYPED_TEST(basic_types_size, operaotr_eq) { + using type = TypeParam; + const bool eq1 = 0 == dxle::size_c{} && dxle::size_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value_width = get_rand(); + const auto value_height = get_rand(); + const dxle::size_c value = { value_width, value_height }; + IUTEST_ASSERT(value == dxle::size_c(value_width, value_height)); + } +} +IUTEST_TYPED_TEST(basic_types_size, ostream_operator) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto x = get_rand(); + const auto y = get_rand(); + std::stringstream ss1; + ss1 << x << ", " << y; + const dxle::size_c value = { x, y }; + std::stringstream ss2; + ss2 << value; + IUTEST_ASSERT_EQ(ss1.str(), ss2.str()); + } +} +IUTEST_TYPED_TEST(basic_types_size, wostream_operator) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto x = get_rand(); + const auto y = get_rand(); + std::wstringstream ss1; + ss1 << x << L", " << y; + const dxle::size_c value = { x, y }; + std::wstringstream ss2; + ss2 << value; + IUTEST_ASSERT_EQ(ss1.str(), ss2.str()); + } +} +IUTEST_TYPED_TEST(basic_types_size, istream_operator) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + std::stringstream ss1; + ss1 << get_rand() << ", " << get_rand(); + std::stringstream ss2; + ss2 << ss1.str(); + type v1, v2; + ss1 >> v1; + ss1.ignore((std::numeric_limits::max)(), ','); + ss1 >> v2; + dxle::size_c v; + ss2 >> v; + IUTEST_ASSERT(v == dxle::size_c(v1, v2)); + } +} +IUTEST_TYPED_TEST(basic_types_size, wistream_operator) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + std::wstringstream ss1; + ss1 << get_rand() << L", " << get_rand(); + std::wstringstream ss2; + ss2 << ss1.str(); + type v1, v2; + ss1 >> v1; + ss1.ignore((std::numeric_limits::max)(), L','); + ss1 >> v2; + dxle::size_c v; + ss2 >> v; + IUTEST_ASSERT(v == dxle::size_c(v1, v2)); + } +} +IUTEST_TYPED_TEST(basic_types_size, unary_operaotr_plus) { + using type = TypeParam; + const bool eq1 = 0 == dxle::size_c{} && dxle::size_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const dxle::size_c value1 = { get_rand(), get_rand() }; + const auto value2 = +value1; + IUTEST_ASSERT(value1 == value2); + } +} +namespace detail { + template::value> + struct basic_types_size_unary_operaotr_minus_helper { + using type = T; + void operator()() {} + }; + template + struct basic_types_size_unary_operaotr_minus_helper { + using type = T; + void operator()() { + const bool eq1 = 0 == dxle::size_c{} && dxle::size_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto x = get_rand(); + const auto y = get_rand(); + + const dxle::size_c value1 = { x, y }; + const auto value2 = -value1; + IUTEST_ASSERT(value2 == dxle::size_c(-x, -y)); + } + } + }; +} +IUTEST_TYPED_TEST(basic_types_size, unary_operaotr_minus) { + detail::basic_types_size_unary_operaotr_minus_helper{}(); +} +IUTEST_TYPED_TEST(basic_types_size, operator_add) { + using type = TypeParam; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value1_width = get_rand(); + const auto value1_height = get_rand(); + const dxle::size_c value1 = { value1_width, value1_height }; + const auto first_add_dist = get_rand_for_add(value1_width, value1_height, 1); + auto value2 = value1 + dxle::size_c{first_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.width == value1_width + first_add_dist); + IUTEST_ASSERT(value2.height == value1_height + first_add_dist); + const auto second_add_dist = get_rand_for_add(value2.width, value2.height, 0); + value2 += dxle::size_c{second_add_dist, second_add_dist}; + IUTEST_ASSERT(value2.width == value1_width + first_add_dist + second_add_dist); + IUTEST_ASSERT(value2.height == value1_height + first_add_dist + second_add_dist); + } +} +IUTEST_TYPED_TEST(basic_types_size, operator_sub) { + using type = TypeParam; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value1_width = get_rand(); + const auto value1_height = get_rand(); + const dxle::size_c value1 = { value1_width, value1_height }; + const auto first_sub_dist = get_rand_for_sub(value1_width, value1_height, 1); + auto value2 = value1 - dxle::size_c{first_sub_dist, first_sub_dist}; + IUTEST_ASSERT(value2.width == value1_width - first_sub_dist); + IUTEST_ASSERT(value2.height == value1_height - first_sub_dist); + const auto second_sub_dist = get_rand_for_sub(value2.width, value2.height, 0); + value2 -= dxle::size_c{second_sub_dist, second_sub_dist}; + IUTEST_ASSERT(value2.width == value1_width - first_sub_dist - second_sub_dist); + IUTEST_ASSERT(value2.height == value1_height - first_sub_dist - second_sub_dist); + } +} +IUTEST_TYPED_TEST(basic_types_size, operator_mul) { + using type = TypeParam; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(inferior_sqrt2(lim::min()), inferior_sqrt(lim::max())); + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value1_width = get_rand(); + const auto value1_height = get_rand(); + dxle::size_c value1 = { value1_width, value1_height }; + const auto first_mul_num = get_rand(); + auto value2 = value1 * first_mul_num; + IUTEST_ASSERT(value2.width == value1_width * first_mul_num); + IUTEST_ASSERT(value2.height == value1_height * first_mul_num); + auto value3 = first_mul_num * value1; + IUTEST_ASSERT(value2 == value3); + value1 *= first_mul_num; + IUTEST_ASSERT(value3 == value1); + } +} +IUTEST_TYPED_TEST(basic_types_size, operator_div) { + using type = TypeParam; + using lim = std::numeric_limits; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value1_width = get_rand_for_div1(lim::min(), lim::max()); + const auto value1_height = get_rand_for_div1(lim::min(), lim::max()); + dxle::size_c value1 = { value1_width, value1_height }; + const auto first_div_num = get_rand_for_div2(value1_width, value1_height); + auto value2 = value1 / first_div_num; + IUTEST_ASSERT(value2.width == value1_width / first_div_num); + IUTEST_ASSERT(value2.height == value1_height / first_div_num); + value1 /= first_div_num; + IUTEST_ASSERT(value2 == value1); + } +} +namespace detail { + template::value> + struct basic_types_size_abs_helper { + using type = T; + using lim = std::numeric_limits; + type operator()() { return lim::max(); } + }; + template + struct basic_types_size_abs_helper { + using type = T; + using lim = std::numeric_limits; + type operator()() { return -1; } + }; +} +IUTEST_TYPED_TEST(basic_types_size, abs) { + using type = TypeParam; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::lowest(), detail::basic_types_size_abs_helper()()); + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value1_width = get_rand(); + const auto value1_height = get_rand(); + dxle::size_c value1 = { value1_width, value1_height }; + IUTEST_ASSERT(dxle::size_c(dxle::abs(value1_width), dxle::abs(value1_height)) == dxle::abs(value1)); + } +} diff --git a/tests/no_dxlib/no_dxlib.vcxproj b/tests/no_dxlib/no_dxlib.vcxproj index 5b89700..07ceeb5 100644 --- a/tests/no_dxlib/no_dxlib.vcxproj +++ b/tests/no_dxlib/no_dxlib.vcxproj @@ -221,6 +221,7 @@ + diff --git a/tests/no_dxlib/no_dxlib.vcxproj.filters b/tests/no_dxlib/no_dxlib.vcxproj.filters index 8ec0f5a..3a7e19c 100644 --- a/tests/no_dxlib/no_dxlib.vcxproj.filters +++ b/tests/no_dxlib/no_dxlib.vcxproj.filters @@ -15,5 +15,8 @@ ソース ファイル + + ソース ファイル + \ No newline at end of file diff --git a/tests/no_dxlib/no_dxlib_test.cpp b/tests/no_dxlib/no_dxlib_test.cpp index 62ccbc3..1b1a3ed 100644 --- a/tests/no_dxlib/no_dxlib_test.cpp +++ b/tests/no_dxlib/no_dxlib_test.cpp @@ -7,6 +7,7 @@ Distributed under the Boost Software License, Version 1.0. =============================================================================*/ #include "../../3rd_party/iutest/include/iutest.hpp" #include "basic_types/point2d.hpp" +#include "basic_types/size.hpp" std::mt19937 engine = dxle::create_engine(); int main(int argc, char** argv) { From 10aec5ac696ad2453d069230df0389a8585446ee Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 12:54:05 +0900 Subject: [PATCH 27/39] =?UTF-8?q?=E8=A6=8B=E3=81=9F=E7=9B=AE=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/include/math.hpp | 11 +++++------ tests/include/random_wrap.hpp | 5 ++--- tests/include/utility.hpp | 1 - 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/include/math.hpp b/tests/include/math.hpp index ed21633..7ed90fa 100644 --- a/tests/include/math.hpp +++ b/tests/include/math.hpp @@ -19,11 +19,6 @@ namespace detail { } template T inferior_sqrt(T x) { return detail::inferior_sqrt_helper()(x); } -inline std::int64_t inferior_sqrt(const std::int64_t x) -{ - return (x < 0) ? 0 : x < static_cast(std::numeric_limits::max()) ? static_cast(::std::sqrt(x)) - : static_cast(inferior_sqrt(static_cast(x))); -} inline std::uint64_t inferior_sqrt(const std::uint64_t x) { if (x < static_cast(std::numeric_limits::max())) return static_cast(::std::sqrt(x)); @@ -36,6 +31,11 @@ inline std::uint64_t inferior_sqrt(const std::uint64_t x) } while (s < t); return t; } +inline std::int64_t inferior_sqrt(const std::int64_t x) +{ + return (x < 0) ? 0 : x < static_cast(std::numeric_limits::max()) ? static_cast(::std::sqrt(x)) + : static_cast(inferior_sqrt(static_cast(x))); +} namespace detail { template::value> struct inferior_sqrt2_helper { @@ -48,5 +48,4 @@ namespace detail { } template T inferior_sqrt2(T x) { return detail::inferior_sqrt2_helper()(x); } - #endif //DXLE_TESTS_INCLUDE_MATH_HPP_ diff --git a/tests/include/random_wrap.hpp b/tests/include/random_wrap.hpp index c15f189..fe69436 100644 --- a/tests/include/random_wrap.hpp +++ b/tests/include/random_wrap.hpp @@ -16,7 +16,7 @@ inline T get_rand_for_add(T n1, T n2, int modifier) return dxle::uniform_normal_distribution( (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifier, (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifier - )(engine); + )(engine); } template T get_rand_for_sub(T n1, T n2, int modifier) @@ -26,7 +26,7 @@ T get_rand_for_sub(T n1, T n2, int modifier) return dxle::uniform_normal_distribution( (minmax.first < 0) ? lim::min() : lim::min() + minmax.first + modifier, (minmax.second > 0) ? lim::max() : lim::max() + minmax.second - modifier - )(engine); + )(engine); } template T get_rand_for_div1(T min, T max) @@ -55,5 +55,4 @@ namespace detail { } template T get_rand_for_div2(T n1, T n2) { return detail::get_rand_for_div2_helper()(n1, n2); } - #endif //DXLE_TESTS_INCLUDE_RANDOM_WRAP_HPP_ diff --git a/tests/include/utility.hpp b/tests/include/utility.hpp index 00bb450..fe00557 100644 --- a/tests/include/utility.hpp +++ b/tests/include/utility.hpp @@ -18,5 +18,4 @@ DXLE_CONSTEXPR bool is_l_zero(T&& val, Rest&&... rest) { return static_cast(0) == val && is_l_zero(std::forward(rest)...); } - #endif //DXLE_TESTS_INCLUDE_UTILITY_HPP_ From 8d9d4464107f779553ba21c13c5b1b9b9ecfcf2e Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 17:18:07 +0900 Subject: [PATCH 28/39] fix compile error --- dxlibex/config/compiler/clang.hpp | 4 +++- tests/no_dxlib/basic_types/point2d.hpp | 26 +++++++++++++++++++++++++- tests/no_dxlib/basic_types/size.hpp | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/dxlibex/config/compiler/clang.hpp b/dxlibex/config/compiler/clang.hpp index 50922c4..cec7774 100644 --- a/dxlibex/config/compiler/clang.hpp +++ b/dxlibex/config/compiler/clang.hpp @@ -76,7 +76,9 @@ Proprietary extension /* C++17 */ -#if __clang_major < 3 || (__clang_major__ == 3 && __clang_minor__ < 9) || __has_cpp_attribute(maybe_unused) < 201603 +#if __clang_major < 3 || (__clang_major__ == 3 && __clang_minor__ < 9) || !defined(__has_cpp_attribute) +# define DXLE_NO_CXX17_UNUSED +#elif __has_cpp_attribute(maybe_unused) < 201603 # define DXLE_NO_CXX17_UNUSED #endif diff --git a/tests/no_dxlib/basic_types/point2d.hpp b/tests/no_dxlib/basic_types/point2d.hpp index b7961b2..245a9a5 100644 --- a/tests/no_dxlib/basic_types/point2d.hpp +++ b/tests/no_dxlib/basic_types/point2d.hpp @@ -5,7 +5,7 @@ Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#include "../../3rd_party/iutest/include/iutest.hpp" +#include <3rd_party/iutest/include/iutest.hpp> #include #include #include @@ -270,6 +270,24 @@ IUTEST_TYPED_TEST(basic_types_point2d, abs) { IUTEST_ASSERT(dxle::point_c(dxle::abs(value1_x), dxle::abs(value1_y)) == dxle::abs(value1)); } } +namespace detail { + template::value> + struct basic_types_point2d_dot_helper { + using type = T; + void operator()() {} + }; + template + struct basic_types_point2d_dot_helper { + using type = T; + void operator()() + { + const dxle::point_c a = { 2, 1 }; + const dxle::point_c b = { 1, 1 }; + IUTEST_ASSERT(type(-4) == (dxle::dot((-2 * a + 3 * b), (4 * a - 7 * b)))); + } + }; + +} IUTEST_TYPED_TEST(basic_types_point2d, dot_product) { using type = TypeParam; using lim = std::numeric_limits; @@ -282,4 +300,10 @@ IUTEST_TYPED_TEST(basic_types_point2d, dot_product) { const auto re2 = value1.x * value2.x + value1.y * value2.y; IUTEST_ASSERT(re1 == re2); } + detail::basic_types_point2d_dot_helper{}(); + const dxle::point_c ex = { 1, 0 }; + const dxle::point_c ey = { 0, 1 }; + IUTEST_ASSERT_EQ(type(0), dxle::dot(ex, ey)); + IUTEST_ASSERT_EQ(type(1), dxle::dot(ex, ex)); + IUTEST_ASSERT_EQ(type(1), dxle::dot(ey, ey)); } diff --git a/tests/no_dxlib/basic_types/size.hpp b/tests/no_dxlib/basic_types/size.hpp index 5d97ac7..b9f5091 100644 --- a/tests/no_dxlib/basic_types/size.hpp +++ b/tests/no_dxlib/basic_types/size.hpp @@ -5,7 +5,7 @@ Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#include "../../3rd_party/iutest/include/iutest.hpp" +#include <3rd_party/iutest/include/iutest.hpp> #include #include #include From 21ffdb2e5a79c9bbcb3551442727d947c3920dd6 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 17:18:42 +0900 Subject: [PATCH 29/39] add testcase for point3d --- .../basic_types/distance_result_type_t.hpp | 2 +- dxlibex/basic_types/point3d.hpp | 4 +- tests/include/random_wrap.hpp | 45 ++- tests/no_dxlib/basic_types/point3d.hpp | 309 ++++++++++++++++++ tests/no_dxlib/no_dxlib.vcxproj | 1 + tests/no_dxlib/no_dxlib.vcxproj.filters | 3 + tests/no_dxlib/no_dxlib_test.cpp | 1 + 7 files changed, 359 insertions(+), 6 deletions(-) create mode 100644 tests/no_dxlib/basic_types/point3d.hpp diff --git a/dxlibex/basic_types/distance_result_type_t.hpp b/dxlibex/basic_types/distance_result_type_t.hpp index 846493d..638ea06 100644 --- a/dxlibex/basic_types/distance_result_type_t.hpp +++ b/dxlibex/basic_types/distance_result_type_t.hpp @@ -16,7 +16,7 @@ namespace dxle { template struct distance_result_type_impl { typedef T type; - }; + }; template struct distance_result_type_impl { typedef double type;//If any argument has integral type, it is cast to double. diff --git a/dxlibex/basic_types/point3d.hpp b/dxlibex/basic_types/point3d.hpp index 33b9003..85fcc97 100644 --- a/dxlibex/basic_types/point3d.hpp +++ b/dxlibex/basic_types/point3d.hpp @@ -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(), std::declval(), std::declval()))) { return dxle::detail::operator_bool_helper(this->x, this->y, this->z); @@ -640,7 +640,7 @@ namespace dxle { \~japanese @return 計算結果。 \~english @return Computed result. */ - template + template distance_result_type_t distance(const point3d_c& p1, const point3d_c& p2) DXLE_NOEXCEPT_IF_EXPR(hypot(safe_dist(std::declval(), std::declval()), safe_dist(std::declval(), std::declval()))) { diff --git a/tests/include/random_wrap.hpp b/tests/include/random_wrap.hpp index fe69436..e96b899 100644 --- a/tests/include/random_wrap.hpp +++ b/tests/include/random_wrap.hpp @@ -19,6 +19,16 @@ inline T get_rand_for_add(T n1, T n2, int modifier) )(engine); } template +inline T get_rand_for_add(T n1, T n2, T n3, int modifier) +{ + using lim = std::numeric_limits; + const auto minmax = std::minmax({ n1, n2, n3 }); + return dxle::uniform_normal_distribution( + (minmax.first > 0) ? lim::min() : lim::min() - minmax.first + modifier, + (minmax.second < 0) ? lim::max() : lim::max() - minmax.second - modifier + )(engine); +} +template T get_rand_for_sub(T n1, T n2, int modifier) { using lim = std::numeric_limits; @@ -29,11 +39,28 @@ T get_rand_for_sub(T n1, T n2, int modifier) )(engine); } template -T get_rand_for_div1(T min, T max) +T get_rand_for_sub(T n1, T n2, T n3, int modifier) +{ + using lim = std::numeric_limits; + const auto minmax = std::minmax({ n1, n2, n3 }); + return dxle::uniform_normal_distribution( + (minmax.first < 0) ? lim::min() : lim::min() + minmax.first + modifier, + (minmax.second > 0) ? lim::max() : lim::max() + minmax.second - modifier + )(engine); +} +template +T get_rand_for_div1(T n1, T n2) +{ + const auto minmax = std::minmax(n1, n2); + const auto re = dxle::uniform_normal_distribution(minmax.first, minmax.second)(engine); + return (0 != re) ? re : get_rand_for_div1(n1, n2); +} +template +T get_rand_for_div1(T n1, T n2, T n3) { - const auto minmax = std::minmax(min, max); + const auto minmax = std::minmax({ n1, n2, n3 }); const auto re = dxle::uniform_normal_distribution(minmax.first, minmax.second)(engine); - return (0 != re) ? re : get_rand_for_div1(min, max); + return (0 != re) ? re : get_rand_for_div1(n1, n2, n3); } namespace detail { template::value> @@ -43,6 +70,11 @@ namespace detail { const auto min = std::min(n1, n2); return get_rand_for_div1(1u, min); } + T operator()(T n1, T n2, T n3) + { + const auto min = std::min({ n1, n2, n3 }); + return get_rand_for_div1(1u, min); + } }; template struct get_rand_for_div2_helper { @@ -51,8 +83,15 @@ namespace detail { const auto min = std::min(std::abs(n1), std::abs(n2)); return get_rand_for_div1(1, min); } + T operator()(T n1, T n2, T n3) + { + const auto min = std::min({ std::abs(n1), std::abs(n2), std::abs(n3) }); + return get_rand_for_div1(1, min); + } }; } template T get_rand_for_div2(T n1, T n2) { return detail::get_rand_for_div2_helper()(n1, n2); } +template +T get_rand_for_div2(T n1, T n2, T n3) { return detail::get_rand_for_div2_helper()(n1, n2, n3); } #endif //DXLE_TESTS_INCLUDE_RANDOM_WRAP_HPP_ diff --git a/tests/no_dxlib/basic_types/point3d.hpp b/tests/no_dxlib/basic_types/point3d.hpp new file mode 100644 index 0000000..8052629 --- /dev/null +++ b/tests/no_dxlib/basic_types/point3d.hpp @@ -0,0 +1,309 @@ +/*============================================================================= + Copyright (C) 2015-2016 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) +=============================================================================*/ +#include <3rd_party/iutest/include/iutest.hpp> +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(_MSC_VER) && !defined(__c2__) +# pragma warning(disable: 4189) +#endif +template +struct basic_types_point3d : public ::iutest::Test{}; +IUTEST_TYPED_TEST_CASE(basic_types_point3d, ::iutest::Types); +IUTEST_TYPED_TEST(basic_types_point3d, construct) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const auto value_z = get_rand(); + const dxle::point3d_c value = { value_x, value_y, value_z }; + IUTEST_ASSERT(value.x == value_x); + IUTEST_ASSERT(value.y == value_y); + IUTEST_ASSERT(value.z == value_z); + } + const dxle::point3d_c value1 = {}; + const auto value2 = value1; + const auto value3 = std::move(value1); + IUTEST_ASSERT(is_l_zero(value1.x, value1.y, value1.z, value2.x, value2.y, value2.z, value3.x, value3.y, value3.z)); + const dxle::point3d_c value4 = { 2, 12, 22 }; + IUTEST_ASSERT(value4.x == static_cast(2)); + IUTEST_ASSERT(value4.y == static_cast(12)); + IUTEST_ASSERT(value4.z == static_cast(22)); +} +IUTEST_TYPED_TEST(basic_types_point3d, factory) { + using type = TypeParam; + const std::tuple pa = { static_cast(12), static_cast(23), static_cast(34) }; + const auto po = dxle::make_point3d_c(pa); + static_assert(std::is_same::value, "err"); + IUTEST_ASSERT(po.x == std::get<0>(pa)); + IUTEST_ASSERT(po.y == std::get<1>(pa)); + IUTEST_ASSERT(po.z == std::get<2>(pa)); + const auto po2 = dxle::make_point3d_c(std::tuple(pa)); + IUTEST_ASSERT(po2.x == std::get<0>(pa)); + IUTEST_ASSERT(po2.y == std::get<1>(pa)); + IUTEST_ASSERT(po2.z == std::get<2>(pa)); +} +IUTEST_TYPED_TEST(basic_types_point3d, operaotr_eq) { + using type = TypeParam; + const bool eq1 = 0 == dxle::point3d_c{} && dxle::point3d_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value_x = get_rand(); + const auto value_y = get_rand(); + const auto value_z = get_rand(); + const dxle::point3d_c value = { value_x, value_y, value_z }; + IUTEST_ASSERT(value == dxle::point3d_c(value_x, value_y, value_z)); + } +} +IUTEST_TYPED_TEST(basic_types_point3d, ostream_operator) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto x = get_rand(); + const auto y = get_rand(); + const auto z = get_rand(); + std::stringstream ss1; + ss1 << x << ", " << y << ", " << z; + const dxle::point3d_c value = { x, y, z }; + std::stringstream ss2; + ss2 << value; + IUTEST_ASSERT_EQ(ss1.str(), ss2.str()); + } +} +IUTEST_TYPED_TEST(basic_types_point3d, wostream_operator) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto x = get_rand(); + const auto y = get_rand(); + const auto z = get_rand(); + std::wstringstream ss1; + ss1 << x << L", " << y << L", " << z; + const dxle::point3d_c value = { x, y, z }; + std::wstringstream ss2; + ss2 << value; + IUTEST_ASSERT_EQ(ss1.str(), ss2.str()); + } +} +IUTEST_TYPED_TEST(basic_types_point3d, istream_operator) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + std::stringstream ss1; + ss1 << get_rand() << ", " << get_rand() << ", " << get_rand(); + std::stringstream ss2; + ss2 << ss1.str(); + type v1, v2, v3; + ss1 >> v1; + ss1.ignore((std::numeric_limits::max)(), ','); + ss1 >> v2; + ss1.ignore((std::numeric_limits::max)(), ','); + ss1 >> v3; + dxle::point3d_c v; + ss2 >> v; + IUTEST_ASSERT(v == dxle::point3d_c(v1, v2, v3)); + } +} +IUTEST_TYPED_TEST(basic_types_point3d, wistream_operator) { + using type = TypeParam; + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + std::wstringstream ss1; + ss1 << get_rand() << L", " << get_rand() << L", " << get_rand(); + std::wstringstream ss2; + ss2 << ss1.str(); + type v1, v2, v3; + ss1 >> v1; + ss1.ignore((std::numeric_limits::max)(), L','); + ss1 >> v2; + ss1.ignore((std::numeric_limits::max)(), L','); + ss1 >> v3; + dxle::point3d_c v; + ss2 >> v; + IUTEST_ASSERT(v == dxle::point3d_c(v1, v2, v3)); + } +} +IUTEST_TYPED_TEST(basic_types_point3d, unary_operaotr_plus) { + using type = TypeParam; + const bool eq1 = 0 == dxle::point3d_c{} && dxle::point3d_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const dxle::point3d_c value1 = { get_rand(), get_rand(), get_rand() }; + const auto value2 = +value1; + IUTEST_ASSERT(value1 == value2); + } +} +namespace detail { + template::value> + struct basic_types_point3d_unary_operaotr_minus_helper { + using type = T; + void operator()() {} + }; + template + struct basic_types_point3d_unary_operaotr_minus_helper { + using type = T; + void operator()() { + const bool eq1 = 0 == dxle::point3d_c{} && dxle::point3d_c{} == 0; + IUTEST_ASSERT(eq1); + dxle::uniform_normal_distribution dist; + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto x = get_rand(); + const auto y = get_rand(); + const auto z = get_rand(); + + const dxle::point3d_c value1 = { x, y, z }; + const auto value2 = -value1; + IUTEST_ASSERT(value2 == dxle::point3d_c(-x, -y, -z)); + } + } + }; +} +IUTEST_TYPED_TEST(basic_types_point3d, unary_operaotr_minus) { + detail::basic_types_point3d_unary_operaotr_minus_helper{}(); +} +IUTEST_TYPED_TEST(basic_types_point3d, operator_add) { + using type = TypeParam; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const auto value1_z = get_rand(); + const dxle::point3d_c value1 = { value1_x, value1_y, value1_z }; + const auto first_add_dist = get_rand_for_add(value1_x, value1_y, value1_z, 1); + auto value2 = value1 + dxle::point3d_c{first_add_dist, first_add_dist, first_add_dist }; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist); + IUTEST_ASSERT(value2.z == value1_z + first_add_dist); + const auto second_add_dist = get_rand_for_add(value2.x, value2.y, value2.z, 0); + value2 += dxle::point3d_c{second_add_dist, second_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); + IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); + IUTEST_ASSERT(value2.z == value1_z + first_add_dist + second_add_dist); + } +} +IUTEST_TYPED_TEST(basic_types_point3d, operator_sub) { + using type = TypeParam; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::min() + 2, lim::max() - 2); + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const auto value1_z = get_rand(); + const dxle::point3d_c value1 = { value1_x, value1_y, value1_z }; + const auto first_add_dist = get_rand_for_sub(value1_x, value1_y, value1_z, 1); + auto value2 = value1 - dxle::point3d_c{first_add_dist, first_add_dist, first_add_dist }; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist); + IUTEST_ASSERT(value2.z == value1_z - first_add_dist); + const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, value2.z, 0); + value2 -= dxle::point3d_c{second_add_dist, second_add_dist, first_add_dist}; + IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); + IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); + IUTEST_ASSERT(value2.z == value1_z - first_add_dist - second_add_dist); + } +} +IUTEST_TYPED_TEST(basic_types_point3d, operator_mul) { + using type = TypeParam; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(inferior_sqrt2(lim::min()), inferior_sqrt(lim::max())); + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const auto value1_z = get_rand(); + dxle::point3d_c value1 = { value1_x, value1_y, value1_z }; + const auto first_mul_num = get_rand(); + auto value2 = value1 * first_mul_num; + IUTEST_ASSERT(value2.x == value1_x * first_mul_num); + IUTEST_ASSERT(value2.y == value1_y * first_mul_num); + IUTEST_ASSERT(value2.z == value1_z * first_mul_num); + auto value3 = first_mul_num * value1; + IUTEST_ASSERT(value2 == value3); + value1 *= first_mul_num; + IUTEST_ASSERT(value3 == value1); + } +} +IUTEST_TYPED_TEST(basic_types_point3d, operator_div) { + using type = TypeParam; + using lim = std::numeric_limits; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value1_x = get_rand_for_div1(lim::min(), lim::max()); + const auto value1_y = get_rand_for_div1(lim::min(), lim::max()); + const auto value1_z = get_rand_for_div1(lim::min(), lim::max()); + dxle::point3d_c value1 = { value1_x, value1_y, value1_z }; + const auto first_div_num = get_rand_for_div2(value1_x, value1_y, value1_z); + auto value2 = value1 / first_div_num; + IUTEST_ASSERT(value2.x == value1_x / first_div_num); + IUTEST_ASSERT(value2.y == value1_y / first_div_num); + IUTEST_ASSERT(value2.z == value1_z / first_div_num); + value1 /= first_div_num; + IUTEST_ASSERT(value2 == value1); + } +} +namespace detail { + template::value> + struct basic_types_point3d_abs_helper { + using type = T; + using lim = std::numeric_limits; + type operator()() { return lim::max(); } + }; + template + struct basic_types_point3d_abs_helper { + using type = T; + using lim = std::numeric_limits; + type operator()() { return -1; } + }; +} +IUTEST_TYPED_TEST(basic_types_point3d, abs) { + using type = TypeParam; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(lim::lowest(), detail::basic_types_point3d_abs_helper()()); + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const auto value1_x = get_rand(); + const auto value1_y = get_rand(); + const auto value1_z = get_rand(); + dxle::point3d_c value1 = { value1_x, value1_y, value1_z }; + IUTEST_ASSERT(dxle::point3d_c(dxle::abs(value1_x), dxle::abs(value1_y), dxle::abs(value1_z)) == dxle::abs(value1)); + } +} +IUTEST_TYPED_TEST(basic_types_point3d, dot_product) { + using type = TypeParam; + using lim = std::numeric_limits; + dxle::uniform_normal_distribution dist(inferior_sqrt2(lim::min()) / 2, inferior_sqrt(lim::max()) / 2); + auto get_rand = [&dist]() { return dist(engine); }; + for (DXLE_UNUSED auto i : dxle::rep(10)) { + const dxle::point3d_c value1 = { get_rand(), get_rand(), get_rand() }; + const dxle::point3d_c value2 = { get_rand(), get_rand(), get_rand() }; + const auto re1 = dxle::dot(value1, value2); + const auto re2 = value1.x * value2.x + value1.y * value2.y + value1.z * value2.z; + IUTEST_ASSERT(re1 == re2); + } +} diff --git a/tests/no_dxlib/no_dxlib.vcxproj b/tests/no_dxlib/no_dxlib.vcxproj index 07ceeb5..2c768e8 100644 --- a/tests/no_dxlib/no_dxlib.vcxproj +++ b/tests/no_dxlib/no_dxlib.vcxproj @@ -221,6 +221,7 @@ + diff --git a/tests/no_dxlib/no_dxlib.vcxproj.filters b/tests/no_dxlib/no_dxlib.vcxproj.filters index 3a7e19c..6703d62 100644 --- a/tests/no_dxlib/no_dxlib.vcxproj.filters +++ b/tests/no_dxlib/no_dxlib.vcxproj.filters @@ -18,5 +18,8 @@ ソース ファイル + + ソース ファイル + \ No newline at end of file diff --git a/tests/no_dxlib/no_dxlib_test.cpp b/tests/no_dxlib/no_dxlib_test.cpp index 1b1a3ed..4c6aa46 100644 --- a/tests/no_dxlib/no_dxlib_test.cpp +++ b/tests/no_dxlib/no_dxlib_test.cpp @@ -7,6 +7,7 @@ Distributed under the Boost Software License, Version 1.0. =============================================================================*/ #include "../../3rd_party/iutest/include/iutest.hpp" #include "basic_types/point2d.hpp" +#include "basic_types/point3d.hpp" #include "basic_types/size.hpp" std::mt19937 engine = dxle::create_engine(); int main(int argc, char** argv) From 18c825cb97dabb5b2762a056addbf72a267cff2a Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 17:33:29 +0900 Subject: [PATCH 30/39] point3d: fix operator==(nullptr_t, this) --- dxlibex/basic_types/point3d.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dxlibex/basic_types/point3d.hpp b/dxlibex/basic_types/point3d.hpp index 85fcc97..5ca4c86 100644 --- a/dxlibex/basic_types/point3d.hpp +++ b/dxlibex/basic_types/point3d.hpp @@ -573,7 +573,7 @@ namespace dxle { template DXLE_CONSTEXPR bool operator ==(nullptr_t, const point3d_c& p) DXLE_NOEXCEPT_IF_EXPR(static_cast(p)) { - return static_cast(p); + return !static_cast(p); } /** From ce7685ca12562d381abf7b69ed29799ad9f21691 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 17:33:49 +0900 Subject: [PATCH 31/39] fix testcase --- tests/no_dxlib/basic_types/point3d.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/no_dxlib/basic_types/point3d.hpp b/tests/no_dxlib/basic_types/point3d.hpp index 8052629..29901d4 100644 --- a/tests/no_dxlib/basic_types/point3d.hpp +++ b/tests/no_dxlib/basic_types/point3d.hpp @@ -60,7 +60,9 @@ IUTEST_TYPED_TEST(basic_types_point3d, factory) { } IUTEST_TYPED_TEST(basic_types_point3d, operaotr_eq) { using type = TypeParam; - const bool eq1 = 0 == dxle::point3d_c{} && dxle::point3d_c{} == 0; + const bool eq1 = 0 == dxle::point3d_c{}; + const bool eq2 = dxle::point3d_c{} == 0; + IUTEST_ASSERT(eq1); IUTEST_ASSERT(eq1); dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; @@ -201,7 +203,7 @@ IUTEST_TYPED_TEST(basic_types_point3d, operator_add) { IUTEST_ASSERT(value2.y == value1_y + first_add_dist); IUTEST_ASSERT(value2.z == value1_z + first_add_dist); const auto second_add_dist = get_rand_for_add(value2.x, value2.y, value2.z, 0); - value2 += dxle::point3d_c{second_add_dist, second_add_dist, first_add_dist}; + value2 += dxle::point3d_c{second_add_dist, second_add_dist, second_add_dist}; IUTEST_ASSERT(value2.x == value1_x + first_add_dist + second_add_dist); IUTEST_ASSERT(value2.y == value1_y + first_add_dist + second_add_dist); IUTEST_ASSERT(value2.z == value1_z + first_add_dist + second_add_dist); @@ -223,7 +225,7 @@ IUTEST_TYPED_TEST(basic_types_point3d, operator_sub) { IUTEST_ASSERT(value2.y == value1_y - first_add_dist); IUTEST_ASSERT(value2.z == value1_z - first_add_dist); const auto second_add_dist = get_rand_for_sub(value2.x, value2.y, value2.z, 0); - value2 -= dxle::point3d_c{second_add_dist, second_add_dist, first_add_dist}; + value2 -= dxle::point3d_c{second_add_dist, second_add_dist, second_add_dist}; IUTEST_ASSERT(value2.x == value1_x - first_add_dist - second_add_dist); IUTEST_ASSERT(value2.y == value1_y - first_add_dist - second_add_dist); IUTEST_ASSERT(value2.z == value1_z - first_add_dist - second_add_dist); From f96267cb71c95c03ad1327ef95431d4a0da4411d Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 17:36:00 +0900 Subject: [PATCH 32/39] point3d: fix operator*(T1, this) --- dxlibex/basic_types/point3d.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dxlibex/basic_types/point3d.hpp b/dxlibex/basic_types/point3d.hpp index 5ca4c86..c3b7c20 100644 --- a/dxlibex/basic_types/point3d.hpp +++ b/dxlibex/basic_types/point3d.hpp @@ -408,7 +408,7 @@ namespace dxle { DXLE_CONSTEXPR auto operator *(T1 l, const point3d_c& r) DXLE_NOEXCEPT_IF_EXPR(l + r.x) ->point3d_c>() * std::declval>())> { - return { l + r.x, l + r.y, l + r.z }; + return { l * r.x, l * r.y, l * r.z }; } /** From 92dc867e08e51cd74f56adb3ddab04f3dc91a27e Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 18:37:41 +0900 Subject: [PATCH 33/39] project setting: support vs2017 Clang CodeGen --- ProjectDxLibEx.sln | 16 +-- ProjectDxLibEx.vcxproj | 60 ++++++++- samples/Color/Color.vcxproj | 8 +- .../calc_coordinate/calc_coordinate.vcxproj | 20 ++- .../constant_range/constant_range.vcxproj | 12 -- .../picture_draw/picture_draw.vcxproj | 32 ++--- samples/timer/timer.vcxproj | 124 ++++++++++++++++++ vcxcompat.props | 10 +- 8 files changed, 221 insertions(+), 61 deletions(-) diff --git a/ProjectDxLibEx.sln b/ProjectDxLibEx.sln index e05e79f..a488353 100644 --- a/ProjectDxLibEx.sln +++ b/ProjectDxLibEx.sln @@ -33,8 +33,8 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A7FFFCCD-08A6-4826-84D4-B46438389B66}.clang_Debug|Win32.ActiveCfg = Debug|Win32 - {A7FFFCCD-08A6-4826-84D4-B46438389B66}.clang_Debug|Win32.Build.0 = Debug|Win32 + {A7FFFCCD-08A6-4826-84D4-B46438389B66}.clang_Debug|Win32.ActiveCfg = clang_Debug|Win32 + {A7FFFCCD-08A6-4826-84D4-B46438389B66}.clang_Debug|Win32.Build.0 = clang_Debug|Win32 {A7FFFCCD-08A6-4826-84D4-B46438389B66}.clang_Debug|x64.ActiveCfg = Release|Win32 {A7FFFCCD-08A6-4826-84D4-B46438389B66}.clang_Debug|x64.Build.0 = Release|Win32 {A7FFFCCD-08A6-4826-84D4-B46438389B66}.clang_Release|Win32.ActiveCfg = Release|Win32 @@ -95,8 +95,8 @@ Global {D0B701B2-9FFB-45DC-A26E-4C9012E0D237}.Release|Win32.Build.0 = Release|Win32 {D0B701B2-9FFB-45DC-A26E-4C9012E0D237}.Release|x64.ActiveCfg = Release|x64 {D0B701B2-9FFB-45DC-A26E-4C9012E0D237}.Release|x64.Build.0 = Release|x64 - {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Debug|Win32.ActiveCfg = Debug|Win32 - {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Debug|Win32.Build.0 = Debug|Win32 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Debug|Win32.ActiveCfg = clang_Debug|Win32 + {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Debug|Win32.Build.0 = clang_Debug|Win32 {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Debug|x64.ActiveCfg = Debug|Win32 {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Release|Win32.ActiveCfg = Release|Win32 {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.clang_Release|Win32.Build.0 = Release|Win32 @@ -107,8 +107,8 @@ Global {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.Release|Win32.ActiveCfg = Release|Win32 {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.Release|Win32.Build.0 = Release|Win32 {44682BAF-4F62-42D9-90EB-D7F46CD21B95}.Release|x64.ActiveCfg = Release|Win32 - {280349E1-6523-4483-97DB-2D16B0716396}.clang_Debug|Win32.ActiveCfg = Debug|Win32 - {280349E1-6523-4483-97DB-2D16B0716396}.clang_Debug|Win32.Build.0 = Debug|Win32 + {280349E1-6523-4483-97DB-2D16B0716396}.clang_Debug|Win32.ActiveCfg = clang_Debug|Win32 + {280349E1-6523-4483-97DB-2D16B0716396}.clang_Debug|Win32.Build.0 = clang_Debug|Win32 {280349E1-6523-4483-97DB-2D16B0716396}.clang_Debug|x64.ActiveCfg = Release|Win32 {280349E1-6523-4483-97DB-2D16B0716396}.clang_Debug|x64.Build.0 = Release|Win32 {280349E1-6523-4483-97DB-2D16B0716396}.clang_Release|Win32.ActiveCfg = Release|Win32 @@ -121,8 +121,8 @@ Global {280349E1-6523-4483-97DB-2D16B0716396}.Release|Win32.ActiveCfg = Release|Win32 {280349E1-6523-4483-97DB-2D16B0716396}.Release|Win32.Build.0 = Release|Win32 {280349E1-6523-4483-97DB-2D16B0716396}.Release|x64.ActiveCfg = Release|Win32 - {110FD38D-D53F-4B0D-AF4C-C321A1CD4C7A}.clang_Debug|Win32.ActiveCfg = Debug|Win32 - {110FD38D-D53F-4B0D-AF4C-C321A1CD4C7A}.clang_Debug|Win32.Build.0 = Debug|Win32 + {110FD38D-D53F-4B0D-AF4C-C321A1CD4C7A}.clang_Debug|Win32.ActiveCfg = clang_Debug|Win32 + {110FD38D-D53F-4B0D-AF4C-C321A1CD4C7A}.clang_Debug|Win32.Build.0 = clang_Debug|Win32 {110FD38D-D53F-4B0D-AF4C-C321A1CD4C7A}.clang_Debug|x64.ActiveCfg = Release|Win32 {110FD38D-D53F-4B0D-AF4C-C321A1CD4C7A}.clang_Debug|x64.Build.0 = Release|Win32 {110FD38D-D53F-4B0D-AF4C-C321A1CD4C7A}.clang_Release|Win32.ActiveCfg = Release|Win32 diff --git a/ProjectDxLibEx.vcxproj b/ProjectDxLibEx.vcxproj index ccbedcd..e7aaadc 100644 --- a/ProjectDxLibEx.vcxproj +++ b/ProjectDxLibEx.vcxproj @@ -1,6 +1,22 @@  + + clang_Debug + Win32 + + + clang_Debug + x64 + + + clang_Release + Win32 + + + clang_Release + x64 + Debug Win32 @@ -148,7 +164,7 @@ Disabled - ./;./$(ProjectName);$(DXLIB_ROOT);DxLib;%(AdditionalIncludeDirectories) + ./;./$(ProjectName);$(DXLIB_ROOT);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true EnableFastChecks @@ -203,7 +219,7 @@ Full true - ./;./$(ProjectName);$(DXLIB_ROOT);DxLib;%(AdditionalIncludeDirectories) + ./;./$(ProjectName);$(DXLIB_ROOT);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreaded true @@ -255,7 +271,45 @@ + + + -Wextra %(AdditionalOptions) + true + MaxSpeed + ./;./$(ProjectName);$(DXLIB_ROOT);%(AdditionalIncludeDirectories) + MultiThreaded + + + + + -Wextra %(AdditionalOptions) + true + MaxSpeed + ./;./$(ProjectName);$(DXLIB_ROOT);%(AdditionalIncludeDirectories) + MultiThreaded + + + + + -Wextra %(AdditionalOptions) + true + Disabled + FullDebug + ./;./$(ProjectName);$(DXLIB_ROOT);%(AdditionalIncludeDirectories) + MultiThreadedDebug + + + + + -Wextra %(AdditionalOptions) + true + Disabled + FullDebug + ./;./$(ProjectName);$(DXLIB_ROOT);%(AdditionalIncludeDirectories) + MultiThreadedDebug + + - + \ No newline at end of file diff --git a/samples/Color/Color.vcxproj b/samples/Color/Color.vcxproj index 178e710..c482ea8 100644 --- a/samples/Color/Color.vcxproj +++ b/samples/Color/Color.vcxproj @@ -50,7 +50,6 @@ Application true - v140_clang_c2 MultiByte @@ -62,7 +61,6 @@ Application false - v140_clang_c2 false MultiByte @@ -74,7 +72,6 @@ Application true - v140_clang_c2 Unicode @@ -86,7 +83,6 @@ Application false - v140_clang_c2 false Unicode @@ -180,6 +176,7 @@ MultiThreadedDebug Enabled true + -Wextra %(AdditionalOptions) Windows @@ -216,6 +213,7 @@ ..\..\;$(DXLIB_ROOT); MultiThreadedDebug true + -Wextra %(AdditionalOptions) Windows @@ -257,6 +255,7 @@ MultiThreaded Enabled true + -Wextra %(AdditionalOptions) Windows @@ -301,6 +300,7 @@ ..\..\;$(DXLIB_ROOT); MultiThreaded true + -Wextra %(AdditionalOptions) Windows diff --git a/samples/calc_coordinate/calc_coordinate/calc_coordinate.vcxproj b/samples/calc_coordinate/calc_coordinate/calc_coordinate.vcxproj index 662accd..3d9eb81 100644 --- a/samples/calc_coordinate/calc_coordinate/calc_coordinate.vcxproj +++ b/samples/calc_coordinate/calc_coordinate/calc_coordinate.vcxproj @@ -64,18 +64,6 @@ true Unicode - - v140_clang_c2 - - - v140_clang_c2 - - - v140_clang_c2 - - - v140_clang_c2 - @@ -179,6 +167,8 @@ ..\..\..\ Enabled c++1y + -Wextra %(AdditionalOptions) + MaxSpeed @@ -187,6 +177,8 @@ Enabled c++1y Disabled + -Wextra %(AdditionalOptions) + FullDebug @@ -194,6 +186,8 @@ ..\..\..\ Enabled c++1y + -Wextra %(AdditionalOptions) + MaxSpeed @@ -202,6 +196,8 @@ Enabled c++1y Disabled + -Wextra %(AdditionalOptions) + FullDebug diff --git a/samples/constant_range/constant_range/constant_range.vcxproj b/samples/constant_range/constant_range/constant_range.vcxproj index 5e86654..11717e3 100644 --- a/samples/constant_range/constant_range/constant_range.vcxproj +++ b/samples/constant_range/constant_range/constant_range.vcxproj @@ -64,18 +64,6 @@ true Unicode - - v140_clang_c2 - - - v140_clang_c2 - - - v140_clang_c2 - - - v140_clang_c2 - diff --git a/samples/picture_draw/picture_draw/picture_draw.vcxproj b/samples/picture_draw/picture_draw/picture_draw.vcxproj index 8ba2191..58988b9 100644 --- a/samples/picture_draw/picture_draw/picture_draw.vcxproj +++ b/samples/picture_draw/picture_draw/picture_draw.vcxproj @@ -64,24 +64,6 @@ true MultiByte - - v140_clang_c2 - MultiByte - - - v140_clang_c2 - MultiByte - - - v140_clang_c2 - true - MultiByte - - - v140_clang_c2 - true - MultiByte - @@ -137,7 +119,7 @@ Disabled _DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(DXLIB_ROOT);../../../; + ../../../;$(DXLIB_ROOT); MultiThreadedDebug @@ -190,10 +172,12 @@ - $(DXLIB_ROOT);../../../;%(AdditionalIncludeDirectories) + ../../../;$(DXLIB_ROOT); Enabled MultiThreaded true + -Wextra %(AdditionalOptions) + MaxSpeed ../../../;$(DXLIB_ROOT); @@ -206,6 +190,9 @@ Enabled MultiThreadedDebug true + -Wextra %(AdditionalOptions) + Disabled + FullDebug .../../../;$(DXLIB_ROOT); @@ -217,6 +204,8 @@ Enabled MultiThreaded true + -Wextra %(AdditionalOptions) + MaxSpeed ../../../;$(DXLIB_ROOT); @@ -229,6 +218,9 @@ Enabled MultiThreadedDebug true + -Wextra %(AdditionalOptions) + Disabled + FullDebug ../../../;$(DXLIB_ROOT); diff --git a/samples/timer/timer.vcxproj b/samples/timer/timer.vcxproj index 029a714..080c812 100644 --- a/samples/timer/timer.vcxproj +++ b/samples/timer/timer.vcxproj @@ -1,19 +1,44 @@  + + clang_Debug + Win32 + + + clang_Debug + x64 + + + clang_Release + Win32 + + + clang_Release + x64 + Debug Win32 + + Debug + x64 + Release Win32 + + Release + x64 + {110FD38D-D53F-4B0D-AF4C-C321A1CD4C7A} Win32Proj timer + 8.1 @@ -22,28 +47,51 @@ true MultiByte + + Application + true + MultiByte + Application false true MultiByte + + Application + false + true + MultiByte + + + + + + + true + + true + false + + false + @@ -61,6 +109,23 @@ $(DXLIB_ROOT);%(AdditionalLibraryDirectories) + + + + + Level4 + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + $(DXLIB_ROOT);../../;%(AdditionalIncludeDirectories) + MultiThreadedDebug + + + Windows + true + $(DXLIB_ROOT);%(AdditionalLibraryDirectories) + + Level4 @@ -82,6 +147,65 @@ $(DXLIB_ROOT);%(AdditionalLibraryDirectories) + + + Level4 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + $(DXLIB_ROOT);../../;%(AdditionalIncludeDirectories) + MultiThreaded + + + Windows + true + true + true + $(DXLIB_ROOT);%(AdditionalLibraryDirectories) + + + + + $(DXLIB_ROOT);../../;%(AdditionalIncludeDirectories) + FullDebug + Disabled + true + -Wextra %(AdditionalOptions) + MultiThreadedDebug + + + + + $(DXLIB_ROOT);../../;%(AdditionalIncludeDirectories) + MaxSpeed + true + -Wextra %(AdditionalOptions) + MultiThreaded + + + + + $(DXLIB_ROOT);../../;%(AdditionalIncludeDirectories) + FullDebug + Disabled + true + -Wextra %(AdditionalOptions) + MultiThreadedDebug + + + + + $(DXLIB_ROOT);../../;%(AdditionalIncludeDirectories) + MaxSpeed + true + -Wextra %(AdditionalOptions) + MultiThreaded + + diff --git a/vcxcompat.props b/vcxcompat.props index 9e7cee8..730f606 100644 --- a/vcxcompat.props +++ b/vcxcompat.props @@ -3,10 +3,16 @@ v120 - + v140 - + + v140_clang_c2 + + v141 + + v141_clang_c2 + From 10e91837ecc9faafee5610b85d204041dc0f3ba7 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 18:37:48 +0900 Subject: [PATCH 34/39] project setting: more support vs2017 Clang CodeGen --- tests/no_dxlib/no_dxlib.vcxproj | 14 +------ tests/with_dxLib/with_dxLib.vcxproj | 59 ++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/tests/no_dxlib/no_dxlib.vcxproj b/tests/no_dxlib/no_dxlib.vcxproj index 2c768e8..b94b4d3 100644 --- a/tests/no_dxlib/no_dxlib.vcxproj +++ b/tests/no_dxlib/no_dxlib.vcxproj @@ -64,18 +64,6 @@ true MultiByte - - v140_clang_c2 - - - v140_clang_c2 - - - v140_clang_c2 - - - v140_clang_c2 - @@ -207,6 +195,7 @@ ..\..\; true -Wextra %(AdditionalOptions) + MaxSpeed @@ -214,6 +203,7 @@ ..\..\; true -Wextra %(AdditionalOptions) + MaxSpeed diff --git a/tests/with_dxLib/with_dxLib.vcxproj b/tests/with_dxLib/with_dxLib.vcxproj index ad6e9e0..72cf9d4 100644 --- a/tests/with_dxLib/with_dxLib.vcxproj +++ b/tests/with_dxLib/with_dxLib.vcxproj @@ -1,6 +1,22 @@  + + clang_Debug + Win32 + + + clang_Debug + x64 + + + clang_Release + Win32 + + + clang_Release + x64 + Debug Win32 @@ -22,6 +38,7 @@ {280349E1-6523-4483-97DB-2D16B0716396} Win32Proj with_dxLib + 8.1 @@ -119,7 +136,7 @@ true WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - ..\..\;$(DXLIB_ROOT);%(AdditionalIncludeDirectories) + ..\..\;$(DXLIB_ROOT); MultiThreaded @@ -140,7 +157,7 @@ true WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - ..\..\;$(DXLIB_ROOT);%(AdditionalIncludeDirectories) + ..\..\;$(DXLIB_ROOT); MultiThreaded @@ -151,6 +168,44 @@ ..\..\;$(DXLIB_ROOT); + + + ..\..\;$(DXLIB_ROOT); + FullDebug + Disabled + true + -Wextra %(AdditionalOptions) + MultiThreadedDebug + + + + + ..\..\;$(DXLIB_ROOT); + MaxSpeed + true + -Wextra %(AdditionalOptions) + MultiThreaded + + + + + ..\..\;$(DXLIB_ROOT); + FullDebug + Disabled + true + -Wextra %(AdditionalOptions) + MultiThreadedDebug + + + + + ..\..\;$(DXLIB_ROOT); + MaxSpeed + true + -Wextra %(AdditionalOptions) + MultiThreaded + + From d209cd628f2b44e410681c91a76934dceefec56f Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 19:54:54 +0900 Subject: [PATCH 35/39] point3d_c: dot: add testcase --- tests/no_dxlib/basic_types/point3d.hpp | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/no_dxlib/basic_types/point3d.hpp b/tests/no_dxlib/basic_types/point3d.hpp index 29901d4..58d1b82 100644 --- a/tests/no_dxlib/basic_types/point3d.hpp +++ b/tests/no_dxlib/basic_types/point3d.hpp @@ -296,6 +296,25 @@ IUTEST_TYPED_TEST(basic_types_point3d, abs) { IUTEST_ASSERT(dxle::point3d_c(dxle::abs(value1_x), dxle::abs(value1_y), dxle::abs(value1_z)) == dxle::abs(value1)); } } +namespace detail { + template::value> + struct basic_types_point3d_dot_helper { + using type = T; + void operator()() {} + }; + template + struct basic_types_point3d_dot_helper { + using type = T; + void operator()() + { + const dxle::point3d_c a = { -3, 1, 2 }; + const dxle::point3d_c b = { -2, 3, 1 }; + const dxle::point3d_c c = { -1, 2, 3 }; + IUTEST_ASSERT(type(3) == (dxle::dot(b - a, c- a))); + } + }; + +} IUTEST_TYPED_TEST(basic_types_point3d, dot_product) { using type = TypeParam; using lim = std::numeric_limits; @@ -307,5 +326,15 @@ IUTEST_TYPED_TEST(basic_types_point3d, dot_product) { const auto re1 = dxle::dot(value1, value2); const auto re2 = value1.x * value2.x + value1.y * value2.y + value1.z * value2.z; IUTEST_ASSERT(re1 == re2); + detail::basic_types_point3d_dot_helper{}(); + const dxle::point3d_c ex = { 1, 0, 0 }; + const dxle::point3d_c ey = { 0, 1, 0 }; + const dxle::point3d_c ez = { 0, 0, 1 }; + IUTEST_ASSERT_EQ(type(0), dxle::dot(ex, ey)); + IUTEST_ASSERT_EQ(type(0), dxle::dot(ey, ez)); + IUTEST_ASSERT_EQ(type(0), dxle::dot(ez, ex)); + IUTEST_ASSERT_EQ(type(1), dxle::dot(ex, ex)); + IUTEST_ASSERT_EQ(type(1), dxle::dot(ey, ey)); + IUTEST_ASSERT_EQ(type(1), dxle::dot(ez, ez)); } } From 287d87499edddc911bb917048fdaec5291f0b4c9 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 27 Nov 2016 21:32:28 +0900 Subject: [PATCH 36/39] point3d_c: cross: add testcase --- tests/no_dxlib/basic_types/point3d.hpp | 61 +++++++++++++++++++++----- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/tests/no_dxlib/basic_types/point3d.hpp b/tests/no_dxlib/basic_types/point3d.hpp index 58d1b82..4c1a4af 100644 --- a/tests/no_dxlib/basic_types/point3d.hpp +++ b/tests/no_dxlib/basic_types/point3d.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #if defined(_MSC_VER) && !defined(__c2__) @@ -63,7 +64,7 @@ IUTEST_TYPED_TEST(basic_types_point3d, operaotr_eq) { const bool eq1 = 0 == dxle::point3d_c{}; const bool eq2 = dxle::point3d_c{} == 0; IUTEST_ASSERT(eq1); - IUTEST_ASSERT(eq1); + IUTEST_ASSERT(eq2); dxle::uniform_normal_distribution dist; auto get_rand = [&dist]() { return dist(engine); }; for (DXLE_UNUSED auto i : dxle::rep(10)) { @@ -313,7 +314,6 @@ namespace detail { IUTEST_ASSERT(type(3) == (dxle::dot(b - a, c- a))); } }; - } IUTEST_TYPED_TEST(basic_types_point3d, dot_product) { using type = TypeParam; @@ -326,15 +326,52 @@ IUTEST_TYPED_TEST(basic_types_point3d, dot_product) { const auto re1 = dxle::dot(value1, value2); const auto re2 = value1.x * value2.x + value1.y * value2.y + value1.z * value2.z; IUTEST_ASSERT(re1 == re2); - detail::basic_types_point3d_dot_helper{}(); - const dxle::point3d_c ex = { 1, 0, 0 }; - const dxle::point3d_c ey = { 0, 1, 0 }; - const dxle::point3d_c ez = { 0, 0, 1 }; - IUTEST_ASSERT_EQ(type(0), dxle::dot(ex, ey)); - IUTEST_ASSERT_EQ(type(0), dxle::dot(ey, ez)); - IUTEST_ASSERT_EQ(type(0), dxle::dot(ez, ex)); - IUTEST_ASSERT_EQ(type(1), dxle::dot(ex, ex)); - IUTEST_ASSERT_EQ(type(1), dxle::dot(ey, ey)); - IUTEST_ASSERT_EQ(type(1), dxle::dot(ez, ez)); } + detail::basic_types_point3d_dot_helper{}(); + const dxle::point3d_c ex = { 1, 0, 0 }; + const dxle::point3d_c ey = { 0, 1, 0 }; + const dxle::point3d_c ez = { 0, 0, 1 }; + IUTEST_ASSERT_EQ(type(0), dxle::dot(ex, ey)); + IUTEST_ASSERT_EQ(type(0), dxle::dot(ey, ez)); + IUTEST_ASSERT_EQ(type(0), dxle::dot(ez, ex)); + IUTEST_ASSERT_EQ(type(1), dxle::dot(ex, ex)); + IUTEST_ASSERT_EQ(type(1), dxle::dot(ey, ey)); + IUTEST_ASSERT_EQ(type(1), dxle::dot(ez, ez)); +} +namespace detail { + template::value> + struct basic_types_point3d_cross_helper { + using type = T; + void operator()() {} + }; + template + struct basic_types_point3d_cross_helper { + using type = T; + void operator()() + { + static const std::array, 3> check_list[] = { + {{ { 1, 3, 2 }, { -1, 1, 2 }, { 4, -4, 4 } }}, + {{ { 1, 1, 2 }, { 3, 6, 9 }, { -3, -3, 3 } }}, + {{ { 6, 3, 3 }, { -7, -3, 10 }, { 39, -81, 3 } }}, + {{ { 0, -1, 2 }, { -1, 0, 5 }, { -5, -2, -1 } }} + }; + for (auto&& i : check_list) { + IUTEST_ASSERT(i[2] == (dxle::cross(i[0], i[1]))); + } + } + }; +} +IUTEST_TYPED_TEST(basic_types_point3d, cross_product){ + using type = TypeParam; + using lim = std::numeric_limits; + detail::basic_types_point3d_cross_helper{}(); + const dxle::point3d_c ex = { 1, 0, 0 }; + const dxle::point3d_c ey = { 0, 1, 0 }; + const dxle::point3d_c ez = { 0, 0, 1 }; + IUTEST_ASSERT_EQ(ez, dxle::cross(ex, ey)); + IUTEST_ASSERT_EQ(ex, dxle::cross(ey, ez)); + IUTEST_ASSERT_EQ(ey, dxle::cross(ez, ex)); + IUTEST_ASSERT((0 == dxle::cross(ex, ex))); + IUTEST_ASSERT((0 == dxle::cross(ey, ey))); + IUTEST_ASSERT((0 == dxle::cross(ez, ez))); } From 1651c242b3a3cf19cdd27c6d0cb23e3bc95da9d6 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 28 Nov 2016 17:58:15 +0900 Subject: [PATCH 37/39] point_c/point3d_c: distance: add testcase --- dxlibex/basic_types/point2d.hpp | 4 ++-- tests/no_dxlib/basic_types/point2d.hpp | 10 ++++++++++ tests/no_dxlib/basic_types/point3d.hpp | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/dxlibex/basic_types/point2d.hpp b/dxlibex/basic_types/point2d.hpp index 0c5d38d..02def97 100644 --- a/dxlibex/basic_types/point2d.hpp +++ b/dxlibex/basic_types/point2d.hpp @@ -637,7 +637,7 @@ namespace dxle { \~english @return Computed result. */ template - DXLE_CONSTEXPR double cross(const point_c& p1, const point_c& p2) + DXLE_CONSTEXPR double cross(const point_c& p1, const point_c& p2) DXLE_NOEXCEPT_IF_EXPR(( static_cast_if::value>(std::declval()) * std::declval() + static_cast_if::value>(std::declval()) * std::declval() @@ -657,7 +657,7 @@ namespace dxle { \~english @return Computed result. */ template - distance_result_type_t distance(const point_c& p1, const point_c& p2) + distance_result_type_t distance(const point_c& p1, const point_c& p2) DXLE_NOEXCEPT_IF_EXPR(hypot(safe_dist(std::declval(), std::declval()), safe_dist(std::declval(), std::declval()))) { return hypot(safe_dist(p1.x, p2.x), safe_dist(p1.y, p2.y)); diff --git a/tests/no_dxlib/basic_types/point2d.hpp b/tests/no_dxlib/basic_types/point2d.hpp index 245a9a5..b2b1885 100644 --- a/tests/no_dxlib/basic_types/point2d.hpp +++ b/tests/no_dxlib/basic_types/point2d.hpp @@ -307,3 +307,13 @@ IUTEST_TYPED_TEST(basic_types_point2d, dot_product) { IUTEST_ASSERT_EQ(type(1), dxle::dot(ex, ex)); IUTEST_ASSERT_EQ(type(1), dxle::dot(ey, ey)); } +IUTEST_TYPED_TEST(basic_types_point2d, distance) { + using type = TypeParam; + const dxle::point_c zero = {}; + const dxle::point_c a = { 3, 4 }; + IUTEST_ASSERT(type(5) == dxle::distance(zero, a)); + const dxle::point_c ex = { 1, 0 }; + IUTEST_ASSERT(type(1) == dxle::distance(zero, ex)); + const dxle::point_c ey = { 0, 1 }; + IUTEST_ASSERT(type(1) == dxle::distance(zero, ey)); +} diff --git a/tests/no_dxlib/basic_types/point3d.hpp b/tests/no_dxlib/basic_types/point3d.hpp index 4c1a4af..c64f66c 100644 --- a/tests/no_dxlib/basic_types/point3d.hpp +++ b/tests/no_dxlib/basic_types/point3d.hpp @@ -361,9 +361,8 @@ namespace detail { } }; } -IUTEST_TYPED_TEST(basic_types_point3d, cross_product){ +IUTEST_TYPED_TEST(basic_types_point3d, cross_product) { using type = TypeParam; - using lim = std::numeric_limits; detail::basic_types_point3d_cross_helper{}(); const dxle::point3d_c ex = { 1, 0, 0 }; const dxle::point3d_c ey = { 0, 1, 0 }; @@ -375,3 +374,19 @@ IUTEST_TYPED_TEST(basic_types_point3d, cross_product){ IUTEST_ASSERT((0 == dxle::cross(ey, ey))); IUTEST_ASSERT((0 == dxle::cross(ez, ez))); } +IUTEST_TYPED_TEST(basic_types_point3d, distance) { + using type = TypeParam; + const dxle::point3d_c zero = {}; + const dxle::point3d_c a = { 12, 15, 16 }; + IUTEST_ASSERT(type(25) == dxle::distance(zero, a)); + static const dxle::point3d_c b[] = { { 3, 4, 0 }, { 0, 3, 4 }, { 4, 0, 3 } }; + for (auto&& i : b) { + IUTEST_ASSERT(type(5) == dxle::distance(zero, i)); + } + const dxle::point3d_c ex = { 1, 0, 0 }; + IUTEST_ASSERT(type(1) == dxle::distance(zero, ex)); + const dxle::point3d_c ey = { 0, 1, 0 }; + IUTEST_ASSERT(type(1) == dxle::distance(zero, ey)); + const dxle::point3d_c ez = { 0, 0, 1 }; + IUTEST_ASSERT(type(1) == dxle::distance(zero, ez)); +} From 7e0919224c6fdffd3b0d791a8736af44f47c7882 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Wed, 7 Dec 2016 12:29:43 +0900 Subject: [PATCH 38/39] update iutest --- 3rd_party/iutest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rd_party/iutest b/3rd_party/iutest index 85a76d4..8ebf87d 160000 --- a/3rd_party/iutest +++ b/3rd_party/iutest @@ -1 +1 @@ -Subproject commit 85a76d4d843fd93d3bd00f45975bc137160aada2 +Subproject commit 8ebf87da8dce295b0d7539652edb90abcc56c89d From f6677d10998953029b476577e6d5a2b9a594d243 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 1 Jan 2017 10:42:57 +0900 Subject: [PATCH 39/39] A HAPPY NEW YEAR! s/2015-2016/2015-2017/ --- tests/include/math.hpp | 2 +- tests/include/random.hpp | 2 +- tests/include/random_wrap.hpp | 2 +- tests/include/utility.hpp | 2 +- tests/no_dxlib/basic_types/point2d.hpp | 2 +- tests/no_dxlib/basic_types/point3d.hpp | 2 +- tests/no_dxlib/basic_types/size.hpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/include/math.hpp b/tests/include/math.hpp index 7ed90fa..af789c7 100644 --- a/tests/include/math.hpp +++ b/tests/include/math.hpp @@ -1,5 +1,5 @@ /*============================================================================= -Copyright (C) 2015-2016 DxLibEx project +Copyright (C) 2015-2017 DxLibEx project https://github.com/Nagarei/DxLibEx/ Distributed under the Boost Software License, Version 1.0. diff --git a/tests/include/random.hpp b/tests/include/random.hpp index b3a935a..798c724 100644 --- a/tests/include/random.hpp +++ b/tests/include/random.hpp @@ -1,5 +1,5 @@ /*============================================================================= -Copyright (C) 2015-2016 DxLibEx project +Copyright (C) 2015-2017 DxLibEx project https://github.com/Nagarei/DxLibEx/ Distributed under the Boost Software License, Version 1.0. diff --git a/tests/include/random_wrap.hpp b/tests/include/random_wrap.hpp index e96b899..603a0ae 100644 --- a/tests/include/random_wrap.hpp +++ b/tests/include/random_wrap.hpp @@ -1,5 +1,5 @@ /*============================================================================= -Copyright (C) 2015-2016 DxLibEx project +Copyright (C) 2015-2017 DxLibEx project https://github.com/Nagarei/DxLibEx/ Distributed under the Boost Software License, Version 1.0. diff --git a/tests/include/utility.hpp b/tests/include/utility.hpp index fe00557..040eec6 100644 --- a/tests/include/utility.hpp +++ b/tests/include/utility.hpp @@ -1,5 +1,5 @@ /*============================================================================= -Copyright (C) 2015-2016 DxLibEx project +Copyright (C) 2015-2017 DxLibEx project https://github.com/Nagarei/DxLibEx/ Distributed under the Boost Software License, Version 1.0. diff --git a/tests/no_dxlib/basic_types/point2d.hpp b/tests/no_dxlib/basic_types/point2d.hpp index b2b1885..aa78b35 100644 --- a/tests/no_dxlib/basic_types/point2d.hpp +++ b/tests/no_dxlib/basic_types/point2d.hpp @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (C) 2015-2016 DxLibEx project + Copyright (C) 2015-2017 DxLibEx project https://github.com/Nagarei/DxLibEx/ Distributed under the Boost Software License, Version 1.0. diff --git a/tests/no_dxlib/basic_types/point3d.hpp b/tests/no_dxlib/basic_types/point3d.hpp index c64f66c..77d5892 100644 --- a/tests/no_dxlib/basic_types/point3d.hpp +++ b/tests/no_dxlib/basic_types/point3d.hpp @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (C) 2015-2016 DxLibEx project + Copyright (C) 2015-2017 DxLibEx project https://github.com/Nagarei/DxLibEx/ Distributed under the Boost Software License, Version 1.0. diff --git a/tests/no_dxlib/basic_types/size.hpp b/tests/no_dxlib/basic_types/size.hpp index b9f5091..0e0c7de 100644 --- a/tests/no_dxlib/basic_types/size.hpp +++ b/tests/no_dxlib/basic_types/size.hpp @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (C) 2015-2016 DxLibEx project + Copyright (C) 2015-2017 DxLibEx project https://github.com/Nagarei/DxLibEx/ Distributed under the Boost Software License, Version 1.0.