#define GLM_FORCE_UNRESTRICTED_GENTYPE #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace isPowerOfTwo { template struct type { genType Value; bool Return; }; template int test_int16() { type const Data[] = { { 0x0001, true }, { 0x0002, true }, { 0x0004, true }, { 0x0080, true }, { 0x0000, true }, { 0x0003, false } }; int Error = 0; for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { glm::vec const Result = glm::isPowerOfTwo(glm::vec(Data[i].Value)); Error += glm::vec(Data[i].Return) == Result ? 0 : 1; } return Error; } template int test_uint16() { type const Data[] = { { 0x0001, true }, { 0x0002, true }, { 0x0004, true }, { 0x0000, true }, { 0x0000, true }, { 0x0003, false } }; int Error = 0; for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { glm::vec const Result = glm::isPowerOfTwo(glm::vec(Data[i].Value)); Error += glm::vec(Data[i].Return) == Result ? 0 : 1; } return Error; } template int test_int32() { type const Data[] = { { 0x00000001, true }, { 0x00000002, true }, { 0x00000004, true }, { 0x0000000f, false }, { 0x00000000, true }, { 0x00000003, false } }; int Error = 0; for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { glm::vec const Result = glm::isPowerOfTwo(glm::vec(Data[i].Value)); Error += glm::vec(Data[i].Return) == Result ? 0 : 1; } return Error; } template int test_uint32() { type const Data[] = { { 0x00000001, true }, { 0x00000002, true }, { 0x00000004, true }, { 0x80000000, true }, { 0x00000000, true }, { 0x00000003, false } }; int Error = 0; for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { glm::vec const Result = glm::isPowerOfTwo(glm::vec(Data[i].Value)); Error += glm::vec(Data[i].Return) == Result ? 0 : 1; } return Error; } int test() { int Error = 0; Error += test_int16<1>(); Error += test_int16<2>(); Error += test_int16<3>(); Error += test_int16<4>(); Error += test_uint16<1>(); Error += test_uint16<2>(); Error += test_uint16<3>(); Error += test_uint16<4>(); Error += test_int32<1>(); Error += test_int32<2>(); Error += test_int32<3>(); Error += test_int32<4>(); Error += test_uint32<1>(); Error += test_uint32<2>(); Error += test_uint32<3>(); Error += test_uint32<4>(); return Error; } }//isPowerOfTwo namespace prevPowerOfTwo { template int run() { int Error = 0; glm::vec const A = glm::prevPowerOfTwo(glm::vec(7)); Error += A == glm::vec(4) ? 0 : 1; glm::vec const B = glm::prevPowerOfTwo(glm::vec(15)); Error += B == glm::vec(8) ? 0 : 1; glm::vec const C = glm::prevPowerOfTwo(glm::vec(31)); Error += C == glm::vec(16) ? 0 : 1; glm::vec const D = glm::prevPowerOfTwo(glm::vec(32)); Error += D == glm::vec(32) ? 0 : 1; return Error; } int test() { int Error = 0; Error += run<1, glm::int8>(); Error += run<2, glm::int8>(); Error += run<3, glm::int8>(); Error += run<4, glm::int8>(); Error += run<1, glm::int16>(); Error += run<2, glm::int16>(); Error += run<3, glm::int16>(); Error += run<4, glm::int16>(); Error += run<1, glm::int32>(); Error += run<2, glm::int32>(); Error += run<3, glm::int32>(); Error += run<4, glm::int32>(); Error += run<1, glm::int64>(); Error += run<2, glm::int64>(); Error += run<3, glm::int64>(); Error += run<4, glm::int64>(); Error += run<1, glm::uint8>(); Error += run<2, glm::uint8>(); Error += run<3, glm::uint8>(); Error += run<4, glm::uint8>(); Error += run<1, glm::uint16>(); Error += run<2, glm::uint16>(); Error += run<3, glm::uint16>(); Error += run<4, glm::uint16>(); Error += run<1, glm::uint32>(); Error += run<2, glm::uint32>(); Error += run<3, glm::uint32>(); Error += run<4, glm::uint32>(); Error += run<1, glm::uint64>(); Error += run<2, glm::uint64>(); Error += run<3, glm::uint64>(); Error += run<4, glm::uint64>(); return Error; } }//namespace prevPowerOfTwo namespace nextPowerOfTwo { template int run() { int Error = 0; glm::vec const A = glm::nextPowerOfTwo(glm::vec(7)); Error += A == glm::vec(8) ? 0 : 1; glm::vec const B = glm::nextPowerOfTwo(glm::vec(15)); Error += B == glm::vec(16) ? 0 : 1; glm::vec const C = glm::nextPowerOfTwo(glm::vec(31)); Error += C == glm::vec(32) ? 0 : 1; glm::vec const D = glm::nextPowerOfTwo(glm::vec(32)); Error += D == glm::vec(32) ? 0 : 1; return Error; } int test() { int Error = 0; Error += run<1, glm::int8>(); Error += run<2, glm::int8>(); Error += run<3, glm::int8>(); Error += run<4, glm::int8>(); Error += run<1, glm::int16>(); Error += run<2, glm::int16>(); Error += run<3, glm::int16>(); Error += run<4, glm::int16>(); Error += run<1, glm::int32>(); Error += run<2, glm::int32>(); Error += run<3, glm::int32>(); Error += run<4, glm::int32>(); Error += run<1, glm::int64>(); Error += run<2, glm::int64>(); Error += run<3, glm::int64>(); Error += run<4, glm::int64>(); Error += run<1, glm::uint8>(); Error += run<2, glm::uint8>(); Error += run<3, glm::uint8>(); Error += run<4, glm::uint8>(); Error += run<1, glm::uint16>(); Error += run<2, glm::uint16>(); Error += run<3, glm::uint16>(); Error += run<4, glm::uint16>(); Error += run<1, glm::uint32>(); Error += run<2, glm::uint32>(); Error += run<3, glm::uint32>(); Error += run<4, glm::uint32>(); Error += run<1, glm::uint64>(); Error += run<2, glm::uint64>(); Error += run<3, glm::uint64>(); Error += run<4, glm::uint64>(); return Error; } }//namespace nextPowerOfTwo namespace prevMultiple { template struct type { genIUType Source; genIUType Multiple; genIUType Return; }; template int run() { type const Data[] = { { 8, 3, 6 }, { 7, 7, 7 } }; int Error = 0; for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { glm::vec const Result0 = glm::prevMultiple(glm::vec(Data[i].Source), Data[i].Multiple); Error += glm::vec(Data[i].Return) == Result0 ? 0 : 1; glm::vec const Result1 = glm::prevMultiple(glm::vec(Data[i].Source), glm::vec(Data[i].Multiple)); Error += glm::vec(Data[i].Return) == Result1 ? 0 : 1; } return Error; } int test() { int Error = 0; Error += run<1, glm::int8>(); Error += run<2, glm::int8>(); Error += run<3, glm::int8>(); Error += run<4, glm::int8>(); Error += run<1, glm::int16>(); Error += run<2, glm::int16>(); Error += run<3, glm::int16>(); Error += run<4, glm::int16>(); Error += run<1, glm::int32>(); Error += run<2, glm::int32>(); Error += run<3, glm::int32>(); Error += run<4, glm::int32>(); Error += run<1, glm::int64>(); Error += run<2, glm::int64>(); Error += run<3, glm::int64>(); Error += run<4, glm::int64>(); Error += run<1, glm::uint8>(); Error += run<2, glm::uint8>(); Error += run<3, glm::uint8>(); Error += run<4, glm::uint8>(); Error += run<1, glm::uint16>(); Error += run<2, glm::uint16>(); Error += run<3, glm::uint16>(); Error += run<4, glm::uint16>(); Error += run<1, glm::uint32>(); Error += run<2, glm::uint32>(); Error += run<3, glm::uint32>(); Error += run<4, glm::uint32>(); Error += run<1, glm::uint64>(); Error += run<2, glm::uint64>(); Error += run<3, glm::uint64>(); Error += run<4, glm::uint64>(); return Error; } }//namespace prevMultiple namespace nextMultiple { template struct type { genIUType Source; genIUType Multiple; genIUType Return; }; template int run() { type const Data[] = { { 3, 4, 4 }, { 6, 3, 6 }, { 5, 3, 6 }, { 7, 7, 7 }, { 0, 1, 0 }, { 8, 3, 9 } }; int Error = 0; for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { glm::vec const Result0 = glm::nextMultiple(glm::vec(Data[i].Source), glm::vec(Data[i].Multiple)); Error += glm::vec(Data[i].Return) == Result0 ? 0 : 1; glm::vec const Result1 = glm::nextMultiple(glm::vec(Data[i].Source), Data[i].Multiple); Error += glm::vec(Data[i].Return) == Result1 ? 0 : 1; } return Error; } int test() { int Error = 0; Error += run<1, glm::int8>(); Error += run<2, glm::int8>(); Error += run<3, glm::int8>(); Error += run<4, glm::int8>(); Error += run<1, glm::int16>(); Error += run<2, glm::int16>(); Error += run<3, glm::int16>(); Error += run<4, glm::int16>(); Error += run<1, glm::int32>(); Error += run<2, glm::int32>(); Error += run<3, glm::int32>(); Error += run<4, glm::int32>(); Error += run<1, glm::int64>(); Error += run<2, glm::int64>(); Error += run<3, glm::int64>(); Error += run<4, glm::int64>(); Error += run<1, glm::uint8>(); Error += run<2, glm::uint8>(); Error += run<3, glm::uint8>(); Error += run<4, glm::uint8>(); Error += run<1, glm::uint16>(); Error += run<2, glm::uint16>(); Error += run<3, glm::uint16>(); Error += run<4, glm::uint16>(); Error += run<1, glm::uint32>(); Error += run<2, glm::uint32>(); Error += run<3, glm::uint32>(); Error += run<4, glm::uint32>(); Error += run<1, glm::uint64>(); Error += run<2, glm::uint64>(); Error += run<3, glm::uint64>(); Error += run<4, glm::uint64>(); return Error; } }//namespace nextMultiple namespace findNSB { template struct type { T Source; int SignificantBitCount; int Return; }; template int run() { type const Data[] = { { 0x00, 1,-1 }, { 0x01, 2,-1 }, { 0x02, 2,-1 }, { 0x06, 3,-1 }, { 0x01, 1, 0 }, { 0x03, 1, 0 }, { 0x03, 2, 1 }, { 0x07, 2, 1 }, { 0x05, 2, 2 }, { 0x0D, 2, 2 } }; int Error = 0; for (std::size_t i = 0, n = sizeof(Data) / sizeof(type); i < n; ++i) { glm::vec const Result0 = glm::findNSB(glm::vec(Data[i].Source), glm::vec(Data[i].SignificantBitCount)); Error += glm::vec(Data[i].Return) == Result0 ? 0 : 1; assert(!Error); } return Error; } int test() { int Error = 0; Error += run<1, glm::uint8>(); Error += run<2, glm::uint8>(); Error += run<3, glm::uint8>(); Error += run<4, glm::uint8>(); Error += run<1, glm::uint16>(); Error += run<2, glm::uint16>(); Error += run<3, glm::uint16>(); Error += run<4, glm::uint16>(); Error += run<1, glm::uint32>(); Error += run<2, glm::uint32>(); Error += run<3, glm::uint32>(); Error += run<4, glm::uint32>(); Error += run<1, glm::uint64>(); Error += run<2, glm::uint64>(); Error += run<3, glm::uint64>(); Error += run<4, glm::uint64>(); Error += run<1, glm::int8>(); Error += run<2, glm::int8>(); Error += run<3, glm::int8>(); Error += run<4, glm::int8>(); Error += run<1, glm::int16>(); Error += run<2, glm::int16>(); Error += run<3, glm::int16>(); Error += run<4, glm::int16>(); Error += run<1, glm::int32>(); Error += run<2, glm::int32>(); Error += run<3, glm::int32>(); Error += run<4, glm::int32>(); Error += run<1, glm::int64>(); Error += run<2, glm::int64>(); Error += run<3, glm::int64>(); Error += run<4, glm::int64>(); return Error; } }//namespace findNSB template struct test_mix_entry { T x; T y; B a; T Result; }; static int test_mix() { test_mix_entry const TestBool[] = { {0, 1, false, 0}, {0, 1, true, 1}, {-1, 1, false, -1}, {-1, 1, true, 1} }; test_mix_entry const TestInt[] = { {0, 1, 0, 0}, {0, 1, 1, 1}, {-1, 1, 0, -1}, {-1, 1, 1, 1} }; test_mix_entry const TestVec2Bool[] = { {glm::ivec2(0), glm::ivec2(1), false, glm::ivec2(0)}, {glm::ivec2(0), glm::ivec2(1), true, glm::ivec2(1)}, {glm::ivec2(-1), glm::ivec2(1), false, glm::ivec2(-1)}, {glm::ivec2(-1), glm::ivec2(1), true, glm::ivec2(1)} }; test_mix_entry const TestBVec2[] = { {glm::ivec2(0), glm::ivec2(1), glm::bvec2(false), glm::ivec2(0)}, {glm::ivec2(0), glm::ivec2(1), glm::bvec2(true), glm::ivec2(1)}, {glm::ivec2(-1), glm::ivec2(1), glm::bvec2(false), glm::ivec2(-1)}, {glm::ivec2(-1), glm::ivec2(1), glm::bvec2(true), glm::ivec2(1)}, {glm::ivec2(-1), glm::ivec2(1), glm::bvec2(true, false), glm::ivec2(1, -1)} }; test_mix_entry const TestVec3Bool[] = { {glm::ivec3(0), glm::ivec3(1), false, glm::ivec3(0)}, {glm::ivec3(0), glm::ivec3(1), true, glm::ivec3(1)}, {glm::ivec3(-1), glm::ivec3(1), false, glm::ivec3(-1)}, {glm::ivec3(-1), glm::ivec3(1), true, glm::ivec3(1)} }; test_mix_entry const TestBVec3[] = { {glm::ivec3(0), glm::ivec3(1), glm::bvec3(false), glm::ivec3(0)}, {glm::ivec3(0), glm::ivec3(1), glm::bvec3(true), glm::ivec3(1)}, {glm::ivec3(-1), glm::ivec3(1), glm::bvec3(false), glm::ivec3(-1)}, {glm::ivec3(-1), glm::ivec3(1), glm::bvec3(true), glm::ivec3(1)}, {glm::ivec3(1, 2, 3), glm::ivec3(4, 5, 6), glm::bvec3(true, false, true), glm::ivec3(4, 2, 6)} }; test_mix_entry const TestVec4Bool[] = { {glm::ivec4(0), glm::ivec4(1), false, glm::ivec4(0)}, {glm::ivec4(0), glm::ivec4(1), true, glm::ivec4(1)}, {glm::ivec4(-1), glm::ivec4(1), false, glm::ivec4(-1)}, {glm::ivec4(-1), glm::ivec4(1), true, glm::ivec4(1)} }; test_mix_entry const TestBVec4[] = { {glm::ivec4(0, 0, 1, 1), glm::ivec4(2, 2, 3, 3), glm::bvec4(false, true, false, true), glm::ivec4(0, 2, 1, 3)}, {glm::ivec4(0), glm::ivec4(1), glm::bvec4(true), glm::ivec4(1)}, {glm::ivec4(-1), glm::ivec4(1), glm::bvec4(false), glm::ivec4(-1)}, {glm::ivec4(-1), glm::ivec4(1), glm::bvec4(true), glm::ivec4(1)}, {glm::ivec4(1, 2, 3, 4), glm::ivec4(5, 6, 7, 8), glm::bvec4(true, false, true, false), glm::ivec4(5, 2, 7, 4)} }; int Error = 0; // Float with bool { for(std::size_t i = 0; i < sizeof(TestBool) / sizeof(test_mix_entry); ++i) { int const Result = glm::mix(TestBool[i].x, TestBool[i].y, TestBool[i].a); Error += Result == TestBool[i].Result ? 0 : 1; } } // Float with float { for(std::size_t i = 0; i < sizeof(TestInt) / sizeof(test_mix_entry); ++i) { int const Result = glm::mix(TestInt[i].x, TestInt[i].y, TestInt[i].a); Error += Result == TestInt[i].Result ? 0 : 1; } } // vec2 with bool { for(std::size_t i = 0; i < sizeof(TestVec2Bool) / sizeof(test_mix_entry); ++i) { glm::ivec2 const Result = glm::mix(TestVec2Bool[i].x, TestVec2Bool[i].y, TestVec2Bool[i].a); Error += glm::all(glm::equal(Result, TestVec2Bool[i].Result)) ? 0 : 1; } } // vec2 with bvec2 { for(std::size_t i = 0; i < sizeof(TestBVec2) / sizeof(test_mix_entry); ++i) { glm::ivec2 const Result = glm::mix(TestBVec2[i].x, TestBVec2[i].y, TestBVec2[i].a); Error += glm::all(glm::equal(Result, TestBVec2[i].Result)) ? 0 : 1; } } // vec3 with bool { for(std::size_t i = 0; i < sizeof(TestVec3Bool) / sizeof(test_mix_entry); ++i) { glm::ivec3 const Result = glm::mix(TestVec3Bool[i].x, TestVec3Bool[i].y, TestVec3Bool[i].a); Error += glm::all(glm::equal(Result, TestVec3Bool[i].Result)) ? 0 : 1; } } // vec3 with bvec3 { for(std::size_t i = 0; i < sizeof(TestBVec3) / sizeof(test_mix_entry); ++i) { glm::ivec3 const Result = glm::mix(TestBVec3[i].x, TestBVec3[i].y, TestBVec3[i].a); Error += glm::all(glm::equal(Result, TestBVec3[i].Result)) ? 0 : 1; } } // vec4 with bool { for(std::size_t i = 0; i < sizeof(TestVec4Bool) / sizeof(test_mix_entry); ++i) { glm::ivec4 const Result = glm::mix(TestVec4Bool[i].x, TestVec4Bool[i].y, TestVec4Bool[i].a); Error += glm::all(glm::equal(Result, TestVec4Bool[i].Result)) ? 0 : 1; } } // vec4 with bvec4 { for(std::size_t i = 0; i < sizeof(TestBVec4) / sizeof(test_mix_entry); ++i) { glm::ivec4 const Result = glm::mix(TestBVec4[i].x, TestBVec4[i].y, TestBVec4[i].a); Error += glm::all(glm::equal(Result, TestBVec4[i].Result)) ? 0 : 1; } } return Error; } int main() { int Error = 0; Error += isPowerOfTwo::test(); Error += prevPowerOfTwo::test(); Error += nextPowerOfTwo::test(); Error += prevMultiple::test(); Error += nextMultiple::test(); Error += findNSB::test(); Error += test_mix(); return Error; }