ddnet/src/test/str.cpp
heinrich5991 31a3e8d4c0 Add possibility to ban players by name
This uses the Unicode confusable data together with judging how close
two strings are by using the Levenshtein distance.

Adds the commands `name_ban`, `name_unban` and `name_bans`. Kicks
players who join using a banned name and doesn't allow ingame players to
change their names to the banned ones.
2018-03-09 20:30:27 +01:00

20 lines
651 B
C++

#include <gtest/gtest.h>
#include <base/system.h>
TEST(Str, Dist)
{
EXPECT_EQ(str_utf8_dist("aaa", "aaa"), 0);
EXPECT_EQ(str_utf8_dist("123", "123"), 0);
EXPECT_EQ(str_utf8_dist("", ""), 0);
EXPECT_EQ(str_utf8_dist("a", "b"), 1);
EXPECT_EQ(str_utf8_dist("", "aaa"), 3);
EXPECT_EQ(str_utf8_dist("123", ""), 3);
EXPECT_EQ(str_utf8_dist("ä", ""), 1);
EXPECT_EQ(str_utf8_dist("Hëllö", "Hello"), 2);
// https://en.wikipedia.org/w/index.php?title=Levenshtein_distance&oldid=828480025#Example
EXPECT_EQ(str_utf8_dist("kitten", "sitting"), 3);
EXPECT_EQ(str_utf8_dist("flaw", "lawn"), 2);
EXPECT_EQ(str_utf8_dist("saturday", "sunday"), 3);
}