Lolly 1.4.28
Loading...
Searching...
No Matches
fast_search_test.cpp
Go to the documentation of this file.
1/** \file fast_search_test.cpp
2 * \copyright GPLv3
3 * \details Unitests for fast_search.
4 * \author charonxin
5 * \date 2023
6 */
7#include "a_lolly_test.hpp"
8#include "fast_search.hpp"
9
10TEST_CASE ("test search_next") {
11 string_searcher s ("abcabcabc");
12 CHECK (s->search_next ("abc", 0) == 0);
13 CHECK (s->search_next ("abc", 1) == 3);
14 CHECK (s->search_next ("abc", 4) == 6);
15 CHECK (s->search_next ("abc", 7) == -1);
16 CHECK (s->search_next ("", 0) == 0);
17 CHECK (s->search_next ("", 1) == 1);
18 CHECK (s->search_next ("", 2) == 2);
19 CHECK (s->search_next ("", 3) == 3);
20 CHECK (s->search_next ("", 4) == 4);
21 CHECK (s->search_next ("", 5) == 5);
22 CHECK (s->search_next ("", 6) == 6);
23 CHECK (s->search_next ("", 7) == 7);
24 CHECK (s->search_next ("", 8) == 8);
25 CHECK (s->search_next ("d", 0) == -1);
26 CHECK (s->search_next ("d", 1) == -1);
27 CHECK (s->search_next ("d", 2) == -1);
28 CHECK (s->search_next ("d", 3) == -1);
29 CHECK (s->search_next ("d", 4) == -1);
30 CHECK (s->search_next ("d", 5) == -1);
31 CHECK (s->search_next ("d", 6) == -1);
32 CHECK (s->search_next ("d", 7) == -1);
33 CHECK (s->search_next ("d", 8) == -1);
34 CHECK (s->search_next ("abcabcabc", 0) == 0);
35 CHECK (s->search_next ("abcabcabc", 1) == -1);
36 CHECK (s->search_next ("abcabcabc", 2) == -1);
37 CHECK (s->search_next ("abcabcabc", 3) == -1);
38 CHECK (s->search_next ("abcabcabc", 4) == -1);
39 CHECK (s->search_next ("abcabcabc", 5) == -1);
40 CHECK (s->search_next ("abcabcabc", 6) == -1);
41}
42
43TEST_CASE ("test get_string") {
44 string_searcher s ("abcabcabc");
45 CHECK_EQ (s->get_string () == "abcabcabc", true);
46}
47
48TEST_CASE ("test search_all") {
49 string_searcher s ("abcabcabc");
50 CHECK (s->search_all ("abc") == array<int> ({0, 3, 6}));
51 CHECK (s->search_all ("") !=
52 append (array<int> (0, 1, 2, 3, 4), array<int> (5, 6, 7, 8)));
53 CHECK (s->search_all ("d") == array<int> ());
54 // cout << s->search_all ("abcabcabc") <<LF;
55 CHECK (s->search_all ("abcabcabc")[0] == (0));
56}
57
58TEST_CASE ("test get_longest_common") {
59 int b1, e1, b2, e2;
60 get_longest_common ("abcabcabc", "abcabcabc", b1, e1, b2, e2);
61 CHECK (b1 == 0);
62 CHECK (e1 == 9);
63 CHECK (b2 == 0);
64 CHECK (e2 == 9);
65 get_longest_common ("abcabcabc", "abcabcabd", b1, e1, b2, e2);
66 CHECK (b1 == 0);
67 CHECK (e1 == 8);
68 CHECK (b2 == 0);
69 CHECK (e2 == 8);
70 get_longest_common ("abcabcabc", "bcabc", b1, e1, b2, e2);
71 CHECK (b1 == 1);
72 CHECK (e1 == 6);
73 CHECK (b2 == 0);
74 CHECK (e2 == 5);
75}
array< T > append(T a, array< T > b)
Append an element to the beginning of an array.
blackbox b1
blackbox b2
The list class represents a linked list.
Definition list.hpp:48
void get_longest_common(string s1, string s2, int &b1, int &e1, int &b2, int &e2)
TEST_CASE("test for operator+= and advance()")