void LSH::GetHashedShinglesOfCluster(TQuoteBase *QuoteBase, TCluster& C, TInt ShingleLen, THashSet<TMd5Sig>& HashedShingles) { TIntV QuoteIds; C.GetQuoteIds(QuoteIds); for (int qt = 0; qt < QuoteIds.Len(); qt++) { TQuote Q; QuoteBase->GetQuote(QuoteIds[qt], Q); TStr QContentStr; Q.GetContentString(QContentStr); TStr QContentStrNoPunc; TStringUtil::RemovePunctuation(QContentStr, QContentStrNoPunc); TStrV QContentV; QContentStrNoPunc.SplitOnWs(QContentV); for (int i = 0; i < QContentV.Len() - ShingleLen + 1; i++) { TStr Shingle; for (int j = 0; j < ShingleLen; j++) { if (j > 0) { Shingle.InsStr(Shingle.Len(), " "); } Shingle.InsStr(Shingle.Len(), QContentV[i + j]); } TMd5Sig ShingleMd5(Shingle); HashedShingles.AddKey(ShingleMd5); } } }
TEST(TStr, InsStr) { TStr Str = "abcda"; TStr Empty = ""; Str.InsStr(2, "xk"); EXPECT_EQ(Str, "abxkcda"); Str.InsStr(2, ""); EXPECT_EQ(Str, "abxkcda"); Str.InsStr(0, "f"); EXPECT_EQ(Str, "fabxkcda"); Str.InsStr(8, "f"); EXPECT_EQ(Str, "fabxkcdaf"); dup2(2, 1); // redirect stdout to stderr (Assert emits a printf to stdout) EXPECT_ANY_THROW(Str.InsStr(100, "kek")); EXPECT_ANY_THROW(Str.InsStr(-100, "kek")); }