diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /tests/gtests/blenlib/BLI_heap_simple_test.cc | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'tests/gtests/blenlib/BLI_heap_simple_test.cc')
-rw-r--r-- | tests/gtests/blenlib/BLI_heap_simple_test.cc | 151 |
1 files changed, 78 insertions, 73 deletions
diff --git a/tests/gtests/blenlib/BLI_heap_simple_test.cc b/tests/gtests/blenlib/BLI_heap_simple_test.cc index 9c97163f337..16e1ecbf9cf 100644 --- a/tests/gtests/blenlib/BLI_heap_simple_test.cc +++ b/tests/gtests/blenlib/BLI_heap_simple_test.cc @@ -15,104 +15,109 @@ extern "C" { #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; - } + float *array_pt = array_tar + (size - 1); + int i = size; + while (i--) { + *(array_pt--) = (float)i; + } } TEST(heap, SimpleEmpty) { - HeapSimple *heap; + 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); + 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); + 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); + 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); + 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); + 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) +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); + 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); } +TEST(heap, SimpleRand1) +{ + random_heapsimple_helper(1, 1234); +} +TEST(heap, SimpleRand2) +{ + random_heapsimple_helper(2, 1234); +} +TEST(heap, SimpleRand100) +{ + random_heapsimple_helper(100, 4321); +} |