string_util_test.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SuperTux
  2. // Copyright (C) 2015 Ingo Ruhnke <grumbel@gmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include <gtest/gtest.h>
  17. #include <algorithm>
  18. #include <fstream>
  19. #include <iostream>
  20. #include <vector>
  21. #include "util/string_util.hpp"
  22. TEST(StringUtilTest, numeric_sort_test)
  23. {
  24. std::vector<std::string> unsorted_lst =
  25. {
  26. "B1235",
  27. "A123",
  28. "A123",
  29. "A12",
  30. "B12323423A233",
  31. "B12323423A1231",
  32. "Z1",
  33. "A1A123",
  34. "A1A1",
  35. "A1A12"
  36. };
  37. /* FIXME: this is the result from 'sort -n', which is different from
  38. what StringUtil::numeric_less produces.
  39. std::vector<std::string> sorted_lst =
  40. {
  41. "A12",
  42. "A123",
  43. "A123",
  44. "A1A1",
  45. "A1A12"
  46. "A1A123",
  47. "B12323423A1231",
  48. "B12323423A233",
  49. "B1235",
  50. "Z1",
  51. };
  52. */
  53. std::vector<std::string> actual_lst =
  54. {
  55. "A1A1",
  56. "A1A12",
  57. "A1A123",
  58. "A12",
  59. "A123",
  60. "A123",
  61. "B1235",
  62. "B12323423A233",
  63. "B12323423A1231",
  64. "Z1"
  65. };
  66. std::sort(unsorted_lst.begin(), unsorted_lst.end(), StringUtil::numeric_less);
  67. ASSERT_EQ(actual_lst, unsorted_lst);
  68. }
  69. /* EOF */