table_test.hxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef TABLE_TEST_HXX
  2. #define TABLE_TEST_HXX
  3. #include "libbinom/include/variables/table.hxx"
  4. #include "libbinom/include/variables/stdoutput.hxx"
  5. #include "tester.hxx"
  6. void testTable() {
  7. RAIIPerfomanceTest test_perf("Table test: ");
  8. SEPARATOR
  9. TEST_ANNOUNCE(Table test)
  10. GRP_PUSH
  11. using namespace binom;
  12. using namespace binom::conditions;
  13. using namespace binom::literals;
  14. Table users_1 = table{
  15. { // Table header!
  16. {"ID", IndexType::unique_index},
  17. {"Name", IndexType::multi_index},
  18. {"Last name", IndexType::multi_index},
  19. {"Email", IndexType::unique_index},
  20. {"Phone number", IndexType::unique_index}
  21. },
  22. { // Rows
  23. map{
  24. {"ID", 0_ui64},
  25. {"Name", "First"},
  26. {"Last name", "User"},
  27. {"Email", "first@example.org"},
  28. {"Phone number", "+0(000)00-00-00"}
  29. },
  30. map{
  31. {"ID", 2_ui64},
  32. {"Name", "Third"},
  33. {"Last name", "User"},
  34. {"Email", "third@example.org"},
  35. {"Phone number", "+0(000)00-00-02"}
  36. },
  37. map{
  38. {"ID", 3_ui64},
  39. {"Name", "Fourth"},
  40. {"Last name", "User"},
  41. {"Email", "fourt@example.org"},
  42. {"Phone number", "+0(000)00-00-03"}
  43. }
  44. },
  45. { // Constraits
  46. { // Contains check
  47. cexp{"ID"},
  48. cexp{"Name"},
  49. cexp{"Last name"},
  50. cexp_list{
  51. cexp{"Email", rel::OR},
  52. cexp{"Phone number"}
  53. }
  54. }
  55. }
  56. };
  57. LOG(WHITE_TXT "Print table")
  58. std::cout << users_1;
  59. // for(auto field_ref : *users_1["ID"])
  60. // utils::printVariable(field_ref);
  61. LOG(WHITE_TXT "Find \"ID\" = 2_ui64")
  62. auto answer = users_1.findAndMove({cexp{"ID", op::equal, 2_ui64}});
  63. for(auto field_ref : *answer["ID"])
  64. utils::printVariable(field_ref);
  65. Table users_2 = table{
  66. { // Table header!
  67. {"ID", IndexType::unique_index},
  68. {"Name", IndexType::multi_index},
  69. {"Last name", IndexType::multi_index},
  70. {"Email", IndexType::unique_index},
  71. {"Phone number", IndexType::unique_index}
  72. },
  73. { // Rows
  74. map{
  75. {"ID", 4_ui64},
  76. {"Name", "Fivth"},
  77. {"Last name", "User"},
  78. {"Email", "fivth@example.org"},
  79. {"Phone number", "+0(000)00-00-05"}
  80. },
  81. map{
  82. {"ID", 1_ui64},
  83. {"Name", "Second"},
  84. {"Last name", "User"},
  85. {"Email", "second@example.org"},
  86. {"Phone number", "+0(000)00-00-01"}
  87. }
  88. },
  89. { // Constraits
  90. { // Contains check
  91. cexp{"ID"},
  92. cexp{"Name"},
  93. cexp{"Last name"},
  94. cexp_list{
  95. cexp{"Email", rel::OR},
  96. cexp{"Phone number"}
  97. }
  98. }
  99. }
  100. };
  101. GRP_POP
  102. }
  103. #endif // TABLE_TEST_HXX