Main.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include <iostream>
  2. #include <array>
  3. #include "common/utils/SplitString.h"
  4. #include "common/utils/List.h"
  5. #include "client/math/Vector.h"
  6. #include "client/math/Matrix.h"
  7. #include <limits.h>
  8. typedef List<const char*, 16> StringList;
  9. const char* RED = "\033[0;31m";
  10. const char* GREEN = "\033[0;32m";
  11. uint tests = 0;
  12. uint successTests = 0;
  13. void finalizeTest() {
  14. std::cout << ((successTests == tests) ? GREEN : RED);
  15. std::cout << successTests << " / " << tests << " succeeded\n";
  16. tests = 0;
  17. successTests = 0;
  18. }
  19. template<typename T>
  20. void checkEqual(const T& wanted, const T& actual, const char* text) {
  21. if(wanted == actual) {
  22. tests++;
  23. successTests++;
  24. std::cout << GREEN << tests << ": " << text << "\n";
  25. } else {
  26. tests++;
  27. std::cout << RED << tests << ": " << text << " - ";
  28. std::cout << RED << "expected '" << wanted << "' got '" << actual << "'\n";
  29. }
  30. }
  31. void checkCommandParser(const char* rawCommand, const StringList& result, const char* text) {
  32. SplitString split(rawCommand);
  33. checkEqual(result.getLength(), split.getLength(), text);
  34. for(uint i = 0; i < result.getLength() && i < split.getLength(); i++) {
  35. checkEqual(String(result[i]), String(split[i]), text);
  36. }
  37. }
  38. void testCommandParser() {
  39. StringList list;
  40. list.clear().add("test");
  41. checkCommandParser("test", list, "command without arguments");
  42. list.clear().add("test").add("aaa");
  43. checkCommandParser("test aaa", list, "command with one argument");
  44. list.clear().add("test").add("aaa").add("bbbb");
  45. checkCommandParser("test aaa bbbb", list, "command with two arguments");
  46. list.clear().add("test").add("aaa").add("bbbb").add("ccccc");
  47. checkCommandParser("test aaa bbbb ccccc", list, "command with three arguments");
  48. list.clear().add("test");
  49. checkCommandParser("test ", list, "command with spaces");
  50. list.clear().add("test").add("aaa").add("bbbb");
  51. checkCommandParser("test aaa bbbb", list, "command with arguments and spaces");
  52. list.clear().add("test").add("aaa bbbb");
  53. checkCommandParser("test \"aaa bbbb\"", list, "command with one argument and quotation marks");
  54. list.clear().add("test").add("aaa bbbb").add("ccc");
  55. checkCommandParser("test \"aaa bbbb\" ccc", list, "command with two arguments and quotation marks");
  56. list.clear().add("test").add("ddd").add("aaa bbbb").add("ccc");
  57. checkCommandParser("test ddd \"aaa bbbb\" ccc", list, "command with tree arguments and quotation marks");
  58. list.clear().add("test").add("");
  59. checkCommandParser("test \"\"", list, "command with empty argument");
  60. list.clear();
  61. checkCommandParser("test \"", list, "command syntax exception 1");
  62. checkCommandParser("test aaa\"", list, "command syntax exception 2");
  63. checkCommandParser("test aaa\"bbb\"", list, "command syntax exception 3");
  64. checkCommandParser("test aaa \"bbb\"ccc", list, "command syntax exception 4");
  65. finalizeTest();
  66. }
  67. long getNanos() {
  68. struct timespec time;
  69. clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time);
  70. return time.tv_nsec + time.tv_sec * 1000000000;
  71. }
  72. int main() {
  73. //testCommandParser();
  74. //Matrix m;
  75. float f;
  76. long* l = (long*) (&f);
  77. *l = 1016003125;
  78. std::cout << f << "\n";
  79. return 0;
  80. }