]> git.treefish.org Git - phys/latlib.git/commitdiff
wrote neigh test routine
authorAlex Schmidt <alex@treefish.org>
Wed, 10 Oct 2012 10:32:03 +0000 (12:32 +0200)
committerAlex Schmidt <alex@treefish.org>
Wed, 10 Oct 2012 10:32:03 +0000 (12:32 +0200)
.gitignore
CMakeLists.txt
neigh_test.cpp [new file with mode: 0644]

index 382dfaaf3f90a130bc22a092ce1f554da610e03c..9ed9ae97876083206c3fec3dc9d14537fc54a08e 100644 (file)
@@ -4,3 +4,4 @@ cmake_install.cmake
 Makefile
 *.a
 *~
+neigh_test
index 5b5abad1bc42c2150fc8db2c11d7dbb47980beaf..2f0439b2ecc689c230c28b29bde6917b51ad100f 100644 (file)
@@ -6,3 +6,6 @@ target_link_libraries(lat_configcache boost_iostreams)
 add_library(lat_neigh neigh.cpp)
 
 add_library(lat_writeout writeout.cpp)
+
+add_executable(neigh_test neigh_test.cpp)
+target_link_libraries(neigh_test lat_neigh)
\ No newline at end of file
diff --git a/neigh_test.cpp b/neigh_test.cpp
new file mode 100644 (file)
index 0000000..38a74ec
--- /dev/null
@@ -0,0 +1,49 @@
+#include "neigh.h"
+#include <time.h>
+#include <stdlib.h>
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+  neigh *n;
+  srand(time(NULL));
+
+  while( true )
+    {
+      int l[] = { rand()%10 + 1, rand()%10 + 1, rand()%10 + 1 , rand()%10 + 1 };
+
+      n = new neigh(4,l[0],l[1],l[2],l[3]);
+
+      cout << l[0] << "x" << l[1] << "x" << l[2] << "x" << l[3] << endl; 
+
+      for(int itry=0; itry<100000; itry++)
+       {
+         int dir0 = rand()%4;
+         int dir1 = rand()%3;
+         if(dir0 <= dir1) dir1++;
+
+         int l0 = rand()%(3*l[dir0]);
+         int l1 = rand()%(3*l[dir1]);
+
+         int startpos = rand()%l[0] + (rand()%l[1])*l[0] + (rand()%l[2])*l[0]*l[1] + (rand()%l[3])*l[0]*l[1]*l[2];
+
+         int pos = startpos;
+
+         for(int istep=0; istep<l0; istep++) pos = (*n)[pos*8+dir0];     
+         for(int istep=0; istep<l1; istep++) pos = (*n)[pos*8+dir1];
+         for(int istep=0; istep<l0; istep++) pos = (*n)[pos*8+dir0+4];
+         for(int istep=0; istep<l1; istep++) pos = (*n)[pos*8+dir1+4];
+
+         if( pos != startpos ) {
+           cout << "OHOH!!!" << endl;
+           exit(1);
+         }
+       }
+
+      delete n;
+    }
+
+  return 0;
+}