]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: modernize all occurrences of rand_choose().
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 30 Jul 2020 14:41:48 +0000 (16:41 +0200)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 1 Dec 2020 12:22:15 +0000 (13:22 +0100)
We should consider deduplication as well.

Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/test/ObjectMap/test_object_map.cc
src/test/objectstore/test_idempotent.cc
src/test/osd/RadosModel.h
src/test/test_snap_mapper.cc
src/test/xattr_bench.cc

index ad2c56e5a03c487a70538b4dbfb281e782f3c2d7..db19c17e8cd1ed6c17e4046442f641aa64da8261 100644 (file)
@@ -1,4 +1,5 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+#include <iterator>
 #include <map>
 #include <set>
 #include <boost/scoped_ptr.hpp>
@@ -20,14 +21,10 @@ using namespace std;
 
 template <typename T>
 typename T::iterator rand_choose(T &cont) {
-  if (cont.size() == 0) {
-    return cont.end();
+  if (std::empty(cont)) {
+    return std::end(cont);
   }
-  int index = rand() % cont.size();
-  typename T::iterator retval = cont.begin();
-
-  for (; index > 0; --index) ++retval;
-  return retval;
+  return std::next(std::begin(cont), rand() % cont.size());
 }
 
 string num_str(unsigned i) {
index c89ea9b70fe55904ea0220d70f31b1cbcfed50dc..0889375ed17f0deafe731e6a140a6e9ad2ae8196 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include <iostream>
+#include <iterator>
 #include <sstream>
 #include <boost/scoped_ptr.hpp>
 #include "os/filestore/FileStore.h"
@@ -31,14 +32,10 @@ void usage(const string &name) {
 
 template <typename T>
 typename T::iterator rand_choose(T &cont) {
-  if (cont.size() == 0) {
-    return cont.end();
+  if (std::empty(cont)) {
+    return std::end(cont);
   }
-  int index = rand() % cont.size();
-  typename T::iterator retval = cont.begin();
-
-  for (; index > 0; --index) ++retval;
-  return retval;
+  return std::next(std::begin(cont), rand() % cont.size());
 }
 
 int main(int argc, char **argv) {
index b2e2496fd2139c525683882e25f6cf78aea438db..d5689f6067af7b687040645032189bb12f4e2761 100644 (file)
@@ -6,6 +6,7 @@
 #include "include/rados/librados.hpp"
 
 #include <iostream>
+#include <iterator>
 #include <sstream>
 #include <map>
 #include <set>
@@ -32,14 +33,10 @@ class TestOpStat;
 
 template <typename T>
 typename T::iterator rand_choose(T &cont) {
-  if (cont.size() == 0) {
-    return cont.end();
+  if (std::empty(cont)) {
+    return std::end(cont);
   }
-  int index = rand() % cont.size();
-  typename T::iterator retval = cont.begin();
-
-  for (; index > 0; --index) ++retval;
-  return retval;
+  return std::next(std::begin(cont), rand() % cont.size());
 }
 
 enum TestOpType {
index 9b6dbdd2b0c59db43f956656624755cb25aced15..50730080d8dc7387dc52755cef827f3c5c9c05af 100644 (file)
@@ -1,4 +1,5 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+#include <iterator>
 #include <map>
 #include <set>
 #include <boost/scoped_ptr.hpp>
@@ -16,14 +17,10 @@ using namespace std;
 
 template <typename T>
 typename T::iterator rand_choose(T &cont) {
-  if (cont.size() == 0) {
-    return cont.end();
+  if (std::empty(cont)) {
+    return std::end(cont);
   }
-  int index = rand() % cont.size();
-  typename T::iterator retval = cont.begin();
-
-  for (; index > 0; --index) ++retval;
-  return retval;
+  return std::next(std::begin(cont), rand() % cont.size());
 }
 
 string random_string(size_t size)
index edbfae25bef89bdbf556042e42ed241e11066e76..7fac235be4916e63fb42efc523468be9c79b63a5 100644 (file)
@@ -16,6 +16,7 @@
 #include <time.h>
 #include <string.h>
 #include <iostream>
+#include <iterator>
 #include <sstream>
 #include "os/filestore/FileStore.h"
 #include "include/Context.h"
@@ -40,14 +41,10 @@ const int THREADS = 5;
 
 template <typename T>
 typename T::iterator rand_choose(T &cont) {
-  if (cont.size() == 0) {
-    return cont.end();
+  if (std::empty(cont) == 0) {
+    return std::end(cont);
   }
-  int index = rand() % cont.size();
-  typename T::iterator retval = cont.begin();
-
-  for (; index > 0; --index) ++retval;
-  return retval;
+  return std::next(std::begin(cont), rand() % cont.size());
 }
 
 class OnApplied : public Context {