test.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include <iostream>
  2. #include "levenshtein.hpp"
  3. #define FAILED { std::cerr << "test failed at " << __LINE__ << std::endl; exit(EXIT_FAILURE); }
  4. int main()
  5. {
  6. if (levenshtein("abcdef", "abcdef", 6, 6) != 0)
  7. FAILED;
  8. if (levenshtein("abcdef", "abcdf", 6, 5) != 1)
  9. FAILED;
  10. if (levenshtein("abcdf", "abcdef", 5, 6) != 1)
  11. FAILED;
  12. if (levenshtein("abcdf", "abcef", 5, 5) != 1)
  13. FAILED;
  14. if (levenshtein("abcf", "abdcf", 4, 5) != 1)
  15. FAILED;
  16. if (levenshtein("lorem", "liroem", 5, 6) != 2)
  17. FAILED;
  18. if (levenshtein<std::string, int>("abcdef", "abcdef", 6, 6) != 0)
  19. FAILED;
  20. if (levenshtein<std::string, int>("abcdef", "abcdf", 6, 5) != 1)
  21. FAILED;
  22. if (levenshtein<std::string, int>("abcdf", "abcdef", 5, 6) != 1)
  23. FAILED;
  24. if (levenshtein<std::string, int>("abcdf", "abcef", 5, 5) != 1)
  25. FAILED;
  26. if (levenshtein<std::string, int>("abcf", "abdcf", 4, 5) != 1)
  27. FAILED;
  28. if (levenshtein<std::string, int>("lorem", "liroem", 5, 6) != 2)
  29. FAILED;
  30. std::cout << "success" << std::endl;
  31. }