summaryrefslogtreecommitdiffstats
path: root/3rdparty/bx/tests/sort_test.cpp
diff options
context:
space:
mode:
author Branimir Karadžić <branimirkaradzic@gmail.com>2017-03-29 17:09:40 +0200
committer Miodrag Milanovic <mmicko@gmail.com>2017-03-29 17:09:40 +0200
commit49f7c99c7786ce257fae28dfeae2f8ee5810424c (patch)
tree1bbd30dd4dd48596186846c2fc77a8dc748215d2 /3rdparty/bx/tests/sort_test.cpp
parent79f22e060b2c012d628d5d1d83288c1bb6e6acef (diff)
Update BGFX and BX (nw)
Diffstat (limited to '3rdparty/bx/tests/sort_test.cpp')
-rw-r--r--3rdparty/bx/tests/sort_test.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/3rdparty/bx/tests/sort_test.cpp b/3rdparty/bx/tests/sort_test.cpp
new file mode 100644
index 00000000000..d271a3ffa03
--- /dev/null
+++ b/3rdparty/bx/tests/sort_test.cpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
+ */
+
+#include "test.h"
+#include <bx/sort.h>
+#include <bx/string.h>
+#include <bx/rng.h>
+
+TEST_CASE("quickSort", "")
+{
+ const char* str[] =
+ {
+ "jabuka",
+ "kruska",
+ "malina",
+ "jagoda",
+ };
+
+ bx::quickSort(str, BX_COUNTOF(str), sizeof(void*)
+ , [](const void* _lhs, const void* _rhs)
+ {
+ const char* lhs = *(const char**)_lhs;
+ const char* rhs = *(const char**)_rhs;
+ return bx::strncmp(lhs, rhs);
+ });
+
+ REQUIRE(0 == bx::strncmp(str[0], "jabuka") );
+ REQUIRE(0 == bx::strncmp(str[1], "jagoda") );
+ REQUIRE(0 == bx::strncmp(str[2], "kruska") );
+ REQUIRE(0 == bx::strncmp(str[3], "malina") );
+
+ int8_t byte[128];
+ bx::RngMwc rng;
+ for (uint32_t ii = 0; ii < BX_COUNTOF(byte); ++ii)
+ {
+ byte[ii] = rng.gen()&0xff;
+ }
+
+ bx::quickSort(byte, BX_COUNTOF(byte), 1
+ , [](const void* _lhs, const void* _rhs)
+ {
+ int8_t lhs = *(const int8_t*)_lhs;
+ int8_t rhs = *(const int8_t*)_rhs;
+ return lhs - rhs;
+ });
+
+ for (uint32_t ii = 1; ii < BX_COUNTOF(byte); ++ii)
+ {
+ REQUIRE(byte[ii-1] <= byte[ii]);
+ }
+}