]> git.treefish.org Git - phys/latlib.git/blobdiff - neigh_test.cpp
wrote neigh test routine
[phys/latlib.git] / neigh_test.cpp
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;
+}