瀏覽代碼

Merge pull request #184 from MikeMirzayanov/anywany-tests

more rnd.any/wany tests
Mike Mirzayanov 7 月之前
父節點
當前提交
c6c2dbda4d
共有 4 個文件被更改,包括 15 次插入2 次删除
  1. 2 2
      testlib.h
  2. 3 0
      tests/test-003_run-rnd/refs/r1/stdout
  3. 3 0
      tests/test-003_run-rnd/refs/r2/stdout
  4. 7 0
      tests/test-003_run-rnd/src/gen.cpp

+ 2 - 2
testlib.h

@@ -1102,7 +1102,7 @@ public:
     /* Returns weighted random element from container. */
     template<typename Container>
     typename Container::value_type wany(const Container &c, int type) {
-        size_t size = c.size();
+        int size = int(c.size());
         if (size <= 0)
             __testlib_fail("random_t::wany(const Container& c, int type): c.size() must be positive");
         return *(c.begin() + wnext(size, type));
@@ -4401,7 +4401,7 @@ void registerGen(int argc, char *argv[]) {
 }
 #endif
 
-static void setAppesModeEncoding(std::string appesModeEncoding) {
+void setAppesModeEncoding(std::string appesModeEncoding) {
     static const char* const ENCODINGS[] = {"ascii", "utf-7", "utf-8", "utf-16", "utf-16le", "utf-16be", "utf-32", "utf-32le", "utf-32be", "iso-8859-1", 
 "iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8", "iso-8859-9", "iso-8859-10", "iso-8859-11", 
 "iso-8859-13", "iso-8859-14", "iso-8859-15", "iso-8859-16", "windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "windows-1255", 

+ 3 - 0
tests/test-003_run-rnd/refs/r1/stdout

@@ -51,3 +51,6 @@ vutwaahqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuz
 1880
 1973
 1850
+2116
+441
+e

+ 3 - 0
tests/test-003_run-rnd/refs/r2/stdout

@@ -141,3 +141,6 @@ clizwkchataumicxkohcrpqnyrjyzbjvsypznpembvkkkbyzvzckcmhbjbuopfbwbkntswhwsdfzabjg
 1363
 1897
 1175
+3249
+3481
+e

+ 7 - 0
tests/test-003_run-rnd/src/gen.cpp

@@ -127,4 +127,11 @@ int main(int argc, char* argv[])
     std::cout << rnd.wnext((signed long long) 42, (signed long long) 2011, 4) << std::endl;
     std::cout << rnd.wnext((signed int) 42, (signed int) 2011, 4) << std::endl;
     std::cout << rnd.wnext((signed short) 42, (signed short) 2011, 4) << std::endl;
+    
+    println(rnd.wany(a, 1));
+    println(rnd.wany(a, -1));
+    
+    set<string> b;
+    b.insert("a"); b.insert("b"); b.insert("c"); b.insert("d"); b.insert("e"); b.insert("f"); b.insert("g");
+    println(rnd.any(b));
 }