소스 검색

test: minor changes

Michele Caini 1 년 전
부모
커밋
cc1a71ec9d
1개의 변경된 파일25개의 추가작업 그리고 12개의 파일을 삭제
  1. 25 12
      test/entt/core/algorithm.cpp

+ 25 - 12
test/entt/core/algorithm.cpp

@@ -11,8 +11,9 @@ TEST(Algorithm, StdSort) {
 
     sort(arr.begin(), arr.end());
 
-    for(auto it = arr.begin(), last = (arr.end() - 1u); it != last; ++it) {
-        ASSERT_LT(*it, *(it + 1u));
+    for(auto it = arr.begin(), last = --arr.end(); it != last;) {
+        const auto &curr = *(it++);
+        ASSERT_LT(curr, *it);
     }
 }
 
@@ -25,19 +26,28 @@ TEST(Algorithm, StdSortBoxedInt) {
         return lhs.value > rhs.value;
     });
 
-    for(auto it = arr.begin(), last = (arr.end() - 1u); it != last; ++it) {
-        ASSERT_GT(it->value, (it + 1u)->value);
+    for(auto it = arr.begin(), last = --arr.end(); it != last;) {
+        const auto curr = it++;
+        ASSERT_GT(curr->value, it->value);
     }
 }
 
+TEST(Algorithm, StdSortEmptyContainer) {
+    std::vector<int> vec{};
+    const entt::std_sort sort;
+    // this should crash with asan enabled if we break the constraint
+    sort(vec.begin(), vec.end());
+}
+
 TEST(Algorithm, InsertionSort) {
     std::array arr{4, 1, 3, 2, 0};
     const entt::insertion_sort sort;
 
     sort(arr.begin(), arr.end());
 
-    for(auto it = arr.begin(), last = (arr.end() - 1u); it != last; ++it) {
-        ASSERT_LT(*it, *(it + 1u));
+    for(auto it = arr.begin(), last = --arr.end(); it != last;) {
+        const auto &curr = *(it++);
+        ASSERT_LT(curr, *it);
     }
 }
 
@@ -49,8 +59,9 @@ TEST(Algorithm, InsertionSortBoxedInt) {
         return lhs.value > rhs.value;
     });
 
-    for(auto it = arr.begin(), last = (arr.end() - 1u); it != last; ++it) {
-        ASSERT_GT(it->value, (it + 1u)->value);
+    for(auto it = arr.begin(), last = --arr.end(); it != last;) {
+        const auto curr = it++;
+        ASSERT_GT(curr->value, it->value);
     }
 }
 
@@ -69,8 +80,9 @@ TEST(Algorithm, RadixSort) {
         return value;
     });
 
-    for(auto it = arr.begin(), last = (arr.end() - 1u); it != last; ++it) {
-        ASSERT_LT(*it, *(it + 1u));
+    for(auto it = arr.begin(), last = --arr.end(); it != last;) {
+        const auto &curr = *(it++);
+        ASSERT_LT(curr, *it);
     }
 }
 
@@ -82,8 +94,9 @@ TEST(Algorithm, RadixSortBoxedInt) {
         return instance.value;
     });
 
-    for(auto it = arr.begin(), last = (arr.end() - 1u); it != last; ++it) {
-        ASSERT_GT(it->value, (it + 1u)->value);
+    for(auto it = arr.begin(), last = --arr.end(); it != last;) {
+        const auto curr = it++;
+        ASSERT_GT(curr->value, it->value);
     }
 }