aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/lcs/lcs_via_lis_ut.cpp
diff options
context:
space:
mode:
authorRuslan Kovalev <ruslan.a.kovalev@gmail.com>2022-02-10 16:46:45 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:45 +0300
commit9123176b341b6f2658cff5132482b8237c1416c8 (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/lcs/lcs_via_lis_ut.cpp
parent59e19371de37995fcb36beb16cd6ec030af960bc (diff)
downloadydb-9123176b341b6f2658cff5132482b8237c1416c8.tar.gz
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/lcs/lcs_via_lis_ut.cpp')
-rw-r--r--library/cpp/lcs/lcs_via_lis_ut.cpp114
1 files changed, 57 insertions, 57 deletions
diff --git a/library/cpp/lcs/lcs_via_lis_ut.cpp b/library/cpp/lcs/lcs_via_lis_ut.cpp
index 4d90dd400e..f6ad5152b6 100644
--- a/library/cpp/lcs/lcs_via_lis_ut.cpp
+++ b/library/cpp/lcs/lcs_via_lis_ut.cpp
@@ -1,64 +1,64 @@
-#include <util/generic/utility.h>
-#include <util/string/util.h>
+#include <util/generic/utility.h>
+#include <util/string/util.h>
#include <library/cpp/testing/unittest/registar.h>
-#include "lcs_via_lis.h"
-
-class TLCSTest: public TTestBase {
+#include "lcs_via_lis.h"
+
+class TLCSTest: public TTestBase {
UNIT_TEST_SUITE(TLCSTest);
UNIT_TEST(LCSTest);
UNIT_TEST_SUITE_END();
-private:
- size_t Length(TStringBuf s1, TStringBuf s2) {
+private:
+ size_t Length(TStringBuf s1, TStringBuf s2) {
TVector<TVector<size_t>> c;
- c.resize(s1.size() + 1);
-
- for (size_t i = 0; i < c.size(); ++i) {
- c[i].resize(s2.size() + 1);
- }
-
- for (size_t i = 0; i < s1.size(); ++i) {
- for (size_t j = 0; j < s2.size(); ++j) {
- if (s1[i] == s2[j])
- c[i + 1][j + 1] = c[i][j] + 1;
- else
- c[i + 1][j + 1] = Max(c[i + 1][j], c[i][j + 1]);
- }
- }
-
- return c[s1.size()][s2.size()];
- }
-
- void CheckLCSLength(TStringBuf s1, TStringBuf s2, size_t size) {
- size_t len = NLCS::MeasureLCS<char>(s1, s2);
-
- UNIT_ASSERT_VALUES_EQUAL(len, Length(s1, s2));
- UNIT_ASSERT_VALUES_EQUAL(len, size);
- }
-
- void CheckLCSString(TStringBuf s1, TStringBuf s2, TStringBuf reflcs) {
+ c.resize(s1.size() + 1);
+
+ for (size_t i = 0; i < c.size(); ++i) {
+ c[i].resize(s2.size() + 1);
+ }
+
+ for (size_t i = 0; i < s1.size(); ++i) {
+ for (size_t j = 0; j < s2.size(); ++j) {
+ if (s1[i] == s2[j])
+ c[i + 1][j + 1] = c[i][j] + 1;
+ else
+ c[i + 1][j + 1] = Max(c[i + 1][j], c[i][j + 1]);
+ }
+ }
+
+ return c[s1.size()][s2.size()];
+ }
+
+ void CheckLCSLength(TStringBuf s1, TStringBuf s2, size_t size) {
+ size_t len = NLCS::MeasureLCS<char>(s1, s2);
+
+ UNIT_ASSERT_VALUES_EQUAL(len, Length(s1, s2));
+ UNIT_ASSERT_VALUES_EQUAL(len, size);
+ }
+
+ void CheckLCSString(TStringBuf s1, TStringBuf s2, TStringBuf reflcs) {
TString lcs;
- size_t len = NLCS::MakeLCS<char>(s1, s2, &lcs);
+ size_t len = NLCS::MakeLCS<char>(s1, s2, &lcs);
const char* comment = Sprintf("%s & %s = %s", s1.data(), s2.data(), reflcs.data()).c_str();
-
- UNIT_ASSERT_VALUES_EQUAL_C(Length(s1, s2), len, comment);
+
+ UNIT_ASSERT_VALUES_EQUAL_C(Length(s1, s2), len, comment);
UNIT_ASSERT_VALUES_EQUAL_C(lcs.size(), len, comment);
- UNIT_ASSERT_VALUES_EQUAL_C(NLCS::MeasureLCS<char>(s1, s2), len, comment);
- UNIT_ASSERT_VALUES_EQUAL_C(reflcs, TStringBuf(lcs), comment);
- }
-
- void LCSTest() {
- CheckLCSString("abacx", "baabca", "bac");
+ UNIT_ASSERT_VALUES_EQUAL_C(NLCS::MeasureLCS<char>(s1, s2), len, comment);
+ UNIT_ASSERT_VALUES_EQUAL_C(reflcs, TStringBuf(lcs), comment);
+ }
+
+ void LCSTest() {
+ CheckLCSString("abacx", "baabca", "bac");
const char* m = "mama_myla_ramu";
const char* n = "papa_lubil_mamu";
const char* s = "aa_l_amu";
- CheckLCSString(m, n, s);
- CheckLCSString(n, m, s);
- CheckLCSString(m, m, m);
- CheckLCSString(m, "", "");
- CheckLCSString("", m, "");
- CheckLCSString("", "", "");
- {
+ CheckLCSString(m, n, s);
+ CheckLCSString(n, m, s);
+ CheckLCSString(m, m, m);
+ CheckLCSString(m, "", "");
+ CheckLCSString("", m, "");
+ CheckLCSString("", "", "");
+ {
const char* s1 =
"atmwuaoccmgirveexxtbkkmioclarskvicyesddirlrgflnietcagkswbvsdnxksipfndmusnuee"
"tojygyjyobdfiutsbruuspvibmywhokxsarwbyirsqqnxxnbtkmucmdafaogwmobuuhejspgurpe"
@@ -83,9 +83,9 @@ private:
"ctsnyjleqgttcgpnhlnagxenuknpxiramgeshhjyoesupkcfcvvpwyweuvcwrawsgvfshppijuug"
"hdnujdqjtcdissmlnjgibdljjxntxrgytxlbgvsrrusatqelspeoyvndjifjqxqrpduwbyojjbhi"
"tmondbbnuuhpkglmfykeheddwkxjyapfniqoic";
- CheckLCSLength(s1, s2, 247);
- }
- {
+ CheckLCSLength(s1, s2, 247);
+ }
+ {
const char* s1 =
"ssyrtvllktbhijkyckviokukaodexiykxcvlvninoasblpuujnqnilnhmacsulaulskphkccnfop"
"jlhejqhemdpnihasouinuceugkfkaifdepvffntbkfivsddtxyslnlwiyfbbpnrwlkryetncahih"
@@ -113,8 +113,8 @@ private:
"xmfwokjskummmkaksbeoowfgjwiumpbkdujexectnghqjjuotofwuwvcgtluephymdkrscbfiaeg"
"aaypnclkstfqimisanikjxocmhcrotkntprwjbuudswuyuujfawjucwgifhqgepxeidmvcwqsqrv"
"karuvpnxhmrvdcocidgtuxasdqkwsdvijmnpmayhfiva";
- CheckLCSLength(s1, s2, 288);
- }
- }
-};
-UNIT_TEST_SUITE_REGISTRATION(TLCSTest)
+ CheckLCSLength(s1, s2, 288);
+ }
+ }
+};
+UNIT_TEST_SUITE_REGISTRATION(TLCSTest)