[Bf-blender-cvs] [aa9912ec045] blender2.8: Proper fix for new 'SimpleHeap' gtests...

Bastien Montagne noreply at git.blender.org
Tue Nov 6 16:25:33 CET 2018


Commit: aa9912ec045e3209bc87c48801fd955c59bd0908
Author: Bastien Montagne
Date:   Tue Nov 6 16:12:29 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBaa9912ec045e3209bc87c48801fd955c59bd0908

Proper fix for new 'SimpleHeap' gtests...

This reverts reverting commit rB55324b8a2e6799300, and do proper 'cleanup' (sigh)
in gtest as well.

Sorry for the noise, did not understood what had happened here
immediately. :/

===================================================================

A	tests/gtests/blenlib/BLI_heap_simple_test.cc
M	tests/gtests/blenlib/CMakeLists.txt

===================================================================

diff --git a/tests/gtests/blenlib/BLI_heap_simple_test.cc b/tests/gtests/blenlib/BLI_heap_simple_test.cc
new file mode 100644
index 00000000000..29aa8f23c49
--- /dev/null
+++ b/tests/gtests/blenlib/BLI_heap_simple_test.cc
@@ -0,0 +1,117 @@
+/* Apache License, Version 2.0 */
+
+#include "testing/testing.h"
+#include <string.h>
+
+extern "C" {
+#include "BLI_compiler_attrs.h"
+#include "BLI_heap_simple.h"
+#include "BLI_utildefines.h"
+#include "BLI_rand.h"
+
+#include "MEM_guardedalloc.h"
+};
+
+#define SIZE 1024
+
+
+static void range_fl(float *array_tar, const int size)
+{
+	float *array_pt = array_tar + (size - 1);
+	int i = size;
+	while (i--) {
+		*(array_pt--) = (float)i;
+	}
+}
+
+TEST(heap, SimpleEmpty)
+{
+	HeapSimple *heap;
+
+	heap = BLI_heapsimple_new();
+	EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
+	EXPECT_EQ(BLI_heapsimple_len(heap), 0);
+	BLI_heapsimple_free(heap, NULL);
+}
+
+TEST(heap, SimpleOne)
+{
+	HeapSimple *heap;
+	const char *in = "test";
+
+	heap = BLI_heapsimple_new();
+
+	BLI_heapsimple_insert(heap, 0.0f, (void *)in);
+	EXPECT_FALSE(BLI_heapsimple_is_empty(heap));
+	EXPECT_EQ(BLI_heapsimple_len(heap), 1);
+	EXPECT_EQ(in, BLI_heapsimple_pop_min(heap));
+	EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
+	EXPECT_EQ(BLI_heapsimple_len(heap), 0);
+	BLI_heapsimple_free(heap, NULL);
+}
+
+TEST(heap, SimpleRange)
+{
+	const int items_total = SIZE;
+	HeapSimple *heap = BLI_heapsimple_new();
+	for (int in = 0; in < items_total; in++) {
+		BLI_heapsimple_insert(heap, (float)in, POINTER_FROM_INT(in));
+	}
+	for (int out_test = 0; out_test < items_total; out_test++) {
+		EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heapsimple_pop_min(heap)));
+
+	}
+	EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
+	BLI_heapsimple_free(heap, NULL);
+}
+
+TEST(heap, SimpleRangeReverse)
+{
+	const int items_total = SIZE;
+	HeapSimple *heap = BLI_heapsimple_new();
+	for (int in = 0; in < items_total; in++) {
+		BLI_heapsimple_insert(heap, (float)-in, POINTER_FROM_INT(-in));
+	}
+	for (int out_test = items_total - 1; out_test >= 0; out_test--) {
+		EXPECT_EQ(-out_test, POINTER_AS_INT(BLI_heapsimple_pop_min(heap)));
+	}
+	EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
+	BLI_heapsimple_free(heap, NULL);
+}
+
+TEST(heap, SimpleDuplicates)
+{
+	const int items_total = SIZE;
+	HeapSimple *heap = BLI_heapsimple_new();
+	for (int in = 0; in < items_total; in++) {
+		BLI_heapsimple_insert(heap, 1.0f, 0);
+	}
+	for (int out_test = 0; out_test < items_total; out_test++) {
+		EXPECT_EQ(0, POINTER_AS_INT(BLI_heapsimple_pop_min(heap)));
+	}
+	EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
+	BLI_heapsimple_free(heap, NULL);
+}
+
+static void random_heapsimple_helper(
+        const int items_total,
+        const int random_seed)
+{
+	HeapSimple *heap = BLI_heapsimple_new();
+	float *values = (float *)MEM_mallocN(sizeof(float) * items_total, __func__);
+	range_fl(values, items_total);
+	BLI_array_randomize(values, sizeof(float), items_total, random_seed);
+	for (int i = 0; i < items_total; i++) {
+		BLI_heapsimple_insert(heap, values[i], POINTER_FROM_INT((int)values[i]));
+	}
+	for (int out_test = 0; out_test < items_total; out_test++) {
+		EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heapsimple_pop_min(heap)));
+	}
+	EXPECT_TRUE(BLI_heapsimple_is_empty(heap));
+	BLI_heapsimple_free(heap, NULL);
+	MEM_freeN(values);
+}
+
+TEST(heap, SimpleRand1)       { random_heapsimple_helper(1, 1234); }
+TEST(heap, SimpleRand2)       { random_heapsimple_helper(2, 1234); }
+TEST(heap, SimpleRand100)     { random_heapsimple_helper(100, 4321); }
diff --git a/tests/gtests/blenlib/CMakeLists.txt b/tests/gtests/blenlib/CMakeLists.txt
index 7574d42d5a1..e652fbecb36 100644
--- a/tests/gtests/blenlib/CMakeLists.txt
+++ b/tests/gtests/blenlib/CMakeLists.txt
@@ -47,6 +47,7 @@ BLENDER_TEST(BLI_expr_pylike_eval "bf_blenlib")
 BLENDER_TEST(BLI_ghash "bf_blenlib")
 BLENDER_TEST(BLI_hash_mm2a "bf_blenlib")
 BLENDER_TEST(BLI_heap "bf_blenlib")
+BLENDER_TEST(BLI_heap_simple "bf_blenlib")
 BLENDER_TEST(BLI_kdopbvh "bf_blenlib")
 BLENDER_TEST(BLI_linklist_lockfree "bf_blenlib")
 BLENDER_TEST(BLI_listbase "bf_blenlib")



More information about the Bf-blender-cvs mailing list