Facebook
From Bistre Butterfly, 1 Year ago, written in C++.
Embed
Download Paste or View Raw
Hits: 185
  1. // Ten przykład celowo łamie reguły dobrego stylu kodowania.
  2.  
  3. #include "tst.h"
  4. #include <cassert>
  5. #include <iostream>
  6. #include <stdexcept>
  7. #include <string>
  8.  
  9. void
  10. example1()
  11. {
  12.   TST <> t1;
  13.   auto t2 = t1 + "dog";
  14.   assert(t2.exist("dog"));
  15.   std::cout << "End of example 1.\n";
  16. }
  17.  
  18. void
  19. example2()
  20. {
  21.   TST<> tst;
  22.   assert(!tst.exist(""));
  23.   auto tst2 = tst + "";
  24.   assert(!tst2.exist(""));
  25.   std::cout << "End of example 2.\n";
  26. }
  27.  
  28. void
  29. example3()
  30. {
  31.   TST<> tst{"a"};
  32.   assert(tst.center().empty());
  33.   std::cout << "End of example 3.\n";
  34. }
  35.  
  36. void
  37. example4()
  38. {
  39.   TST<> tst{ std::string{ "category" } };
  40.   assert((tst + std::string{ "functor" } + std::string{ "theory" }).prefix("theology") == "theo");
  41.   assert((tst + std::string{ "functor" } + std::string{ "theory" }).prefix("cftheology") == "c");
  42.   auto tst2{ tst + std::string{ "functor" } + std::string{ "theory" } };
  43.   auto tst3{ tst + std::string{ "functor" } + std::string{ "cftheory" } };
  44.   assert(tst2.prefix("cftheology") == "c");
  45.   assert(tst3.prefix("cftheology") == "cftheo");
  46.   assert(tst2.prefix("theology") == "theo");
  47.   assert(tst3.prefix("theology").empty());
  48.   std::cout << "End of example 4.\n";
  49. }
  50.  
  51. void
  52. example5()
  53. {
  54.   TST<int> t1;
  55.   auto t2 = t1 + std::basic_string<int>{1, 2, 3};
  56.   auto t3 = t2 + std::basic_string<int>{1, 2};
  57.   assert(t2.value() == 1);
  58.   assert(t2.center().value() == 2);
  59.   assert(t2.center().center().value() == 3);
  60.   assert(t3.value() == 1);
  61.   assert(t3.center().value() == 2);
  62.   assert(t3.center().center().value() == 3);
  63.   assert(!t2.word());
  64.   assert(!t2.center().word());
  65.   assert(t2.center().center().word());
  66.   assert(!t3.word());
  67.   assert(t3.center().word());
  68.   assert(t3.center().center().word());
  69.  
  70.   assert(t2.left().empty());
  71.   assert(!t2.center().empty());
  72.   assert(t2.right().empty());
  73.   assert(t2.center().left().empty());
  74.   assert(!t2.center().center().empty());
  75.   assert(t2.center().right().empty());
  76.   assert(t2.center().center().left().empty());
  77.   assert(t2.center().center().center().empty());
  78.   assert(t2.center().center().right().empty());
  79.  
  80.  
  81.   assert(t3.left().empty());
  82.   assert(!t3.center().empty());
  83.   assert(t3.right().empty());
  84.   assert(t3.center().left().empty());
  85.   assert(!t3.center().center().empty());
  86.   assert(t3.center().right().empty());
  87.   assert(t3.center().center().left().empty());
  88.   assert(t3.center().center().center().empty());
  89.   assert(t3.center().center().right().empty());
  90.   std::cout << "End of example 5.\n";
  91. }
  92.  
  93. int
  94. main()
  95. {
  96.   example1();
  97.   example2();
  98.   example3();
  99.   example4();
  100.   example5();
  101. }
  102.