-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
40 lines (30 loc) · 1.1 KB
/
test.cpp
File metadata and controls
40 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// Created by alexander on 12/4/21.
//
#include <gtest/gtest.h>
#include "rabin-karp.h"
#include "knuth_morris_pratt.h"
// TODO add fixture usage in order to avoid code duplication
TEST(BasicTests, KnuthMorrisPratt)
{
// simple test with one pattern match
std::vector<int> gt_answers;
gt_answers.push_back(1);
EXPECT_EQ(gt_answers, SubstringSearchKnuthMorrisPratt("ABCD", "BC"));
// several pattern match
gt_answers.insert(gt_answers.end(), {4, 7});
EXPECT_EQ(gt_answers, SubstringSearchKnuthMorrisPratt("ABCDBCgBC", "BC"));
std::vector<int> empty_answers;
EXPECT_EQ(empty_answers, SubstringSearchKnuthMorrisPratt("ABCDBCgBC", "empty"));
}
TEST(BasicTests, RabinKarp)
{
std::vector<int> gt_answers;
gt_answers.push_back(1);
EXPECT_EQ(gt_answers, SubstringSearchRabinKarp("ABCD", "BC"));
// several pattern match
gt_answers.insert(gt_answers.end(), {4, 7});
EXPECT_EQ(gt_answers, SubstringSearchKnuthMorrisPratt("ABCDBCgBC", "BC"));
std::vector<int> empty_answers;
EXPECT_EQ(empty_answers, SubstringSearchKnuthMorrisPratt("ABCDBCgBC", "empty"));
}