test_long_id.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include <cmath>
00003 
00004 #include <megatree/long_id.h>
00005 #include <megatree/storage_factory.h>
00006 #include <megatree/tree_functions.h>
00007 
00008 using namespace megatree;
00009 
00010 
00011 TEST(LongId, TreeLevel)
00012 {
00013   EXPECT_EQ(0, 0);
00014   EXPECT_EQ(0, IdType(0).level());
00015   EXPECT_EQ(1, IdType(01).level());
00016   EXPECT_EQ(2, IdType(012).level());
00017   EXPECT_EQ(3, IdType(0123).level());
00018   EXPECT_EQ(4, IdType(01234).level());
00019 
00020   IdType id(1);
00021   EXPECT_TRUE(id.isRoot());
00022   EXPECT_EQ(1, id.level());
00023   EXPECT_TRUE(id.isValid());
00024 
00025   EXPECT_EQ(IdType(0).level(), 0);
00026   EXPECT_EQ(IdType(0).level(), 0);
00027   EXPECT_EQ(IdType(0), id.getParent());
00028   EXPECT_EQ(0, id.getParent().level());
00029   EXPECT_EQ(IdType(014), id.getChild(4));  
00030   EXPECT_EQ(IdType(01572), id.getChild(5).getChild(7).getChild(2));
00031 
00032   id = id.getChild(5).getChild(7).getChild(2);
00033   EXPECT_EQ(4, id.level());
00034   EXPECT_EQ(3, id.getParent().level());
00035   EXPECT_EQ(0, id.getBit(X_BIT));
00036   EXPECT_EQ(0, id.getBit(Z_BIT));
00037   EXPECT_EQ(1, id.getBit(Y_BIT));
00038 
00039   EXPECT_EQ(id.toString(), "01572");
00040   EXPECT_EQ(IdType(0).toString(), "0");
00041   EXPECT_EQ(IdType().toString(), "0");
00042 }
00043 
00044 
00045 TEST(LongId, Subtree)
00046 {
00047   IdType root, id;
00048   ShortId short_id;
00049   std::vector<double> center(3, 0);
00050   boost::shared_ptr<TempDir> tree_path(createTempDir("subtree", true));
00051   double tree_size = 10.0;
00052   unsigned subtree_width = 5;
00053   unsigned subfolder_depth = 8;
00054   boost::shared_ptr<Storage> storage(openStorage(tree_path->getPath()));
00055   MegaTree tree(storage, center, tree_size, subtree_width, subfolder_depth, 10000000);
00056 
00057   id = IdType(01);
00058   root = tree.getFileId(id);
00059   short_id = tree.getShortId(id);
00060   EXPECT_EQ(1, id.level());
00061   EXPECT_EQ(0, root.level());
00062   EXPECT_EQ(1, short_id);
00063   EXPECT_EQ("0", root.toString());
00064 
00065   id = IdType(010);
00066   root = tree.getFileId(id);
00067   short_id = tree.getShortId(id);
00068   EXPECT_EQ(2, id.level());
00069   EXPECT_EQ(0, root.level());
00070   EXPECT_EQ(1*8+0, short_id);
00071   EXPECT_EQ("0", root.toString());
00072 
00073   id = IdType(0100);
00074   root = tree.getFileId(id);
00075   short_id = tree.getShortId(id);
00076   EXPECT_EQ(3, id.level());
00077   EXPECT_EQ(0, root.level());
00078   EXPECT_EQ(1*8*8+0*8+0, short_id);
00079   EXPECT_EQ("0", root.toString());
00080 
00081   id = IdType(01603);
00082   root = tree.getFileId(id);
00083   short_id = tree.getShortId(id);
00084   EXPECT_EQ(4, id.level());
00085   EXPECT_EQ(0, root.level());
00086   EXPECT_EQ(1*8*8*8+6*8*8+0*8+3, short_id);
00087   EXPECT_EQ("0", root.toString());
00088 
00089   id = IdType(016066);
00090   root = tree.getFileId(id);
00091   short_id = tree.getShortId(id);
00092   EXPECT_EQ(5, id.level());
00093   EXPECT_EQ(0, root.level());
00094   EXPECT_EQ(1*8*8*8*8+6*8*8*8+0*8*8+6*8+6, short_id);
00095   EXPECT_EQ("0", root.toString());
00096 
00097   id = IdType(0166333);
00098   root = tree.getFileId(id);
00099   short_id = tree.getShortId(id);
00100   EXPECT_EQ(6, id.level());
00101   EXPECT_EQ(1, root.level());
00102   EXPECT_EQ(6*8*8*8*8+6*8*8*8+3*8*8+3*8+3, short_id);
00103   EXPECT_EQ("01", root.toString());
00104 
00105   id = IdType(01663337);
00106   root = tree.getFileId(id);
00107   short_id = tree.getShortId(id);
00108   EXPECT_EQ(7, id.level());
00109   EXPECT_EQ(2, root.level());
00110   EXPECT_EQ(6*8*8*8*8+3*8*8*8+3*8*8+3*8+7, short_id);
00111   EXPECT_EQ("016", root.toString());
00112 
00113   id = IdType(016633366);
00114   root = tree.getFileId(id);
00115   short_id = tree.getShortId(id);
00116   EXPECT_EQ(8, id.level());
00117   EXPECT_EQ(3, root.level());
00118   EXPECT_EQ(3*8*8*8*8+3*8*8*8+3*8*8+6*8+6, short_id);
00119   EXPECT_EQ("0166", root.toString());
00120 
00121   id = IdType(0166333333);
00122   root = tree.getFileId(id);
00123   short_id = tree.getShortId(id);
00124   EXPECT_EQ(9, id.level());
00125   EXPECT_EQ(4, root.level());
00126   EXPECT_EQ(3*8*8*8*8+3*8*8*8+3*8*8+3*8+3, short_id);
00127   EXPECT_EQ("01663", root.toString());
00128 }
00129 
00130 
00131 // Run all the tests that were declared with TEST()
00132 int main(int argc, char **argv){
00133   testing::InitGoogleTest(&argc, argv);
00134   return RUN_ALL_TESTS();
00135 }


megatree_cpp
Author(s): Stuart Glaser
autogenerated on Thu Nov 28 2013 11:30:34