Files
C-Plus-Plus/da/d0d/longest__common__string_8cpp_source.html
2025-05-19 11:38:33 +00:00

269 lines
30 KiB
HTML

<!-- HTML header for doxygen 1.12.0-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.13.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>TheAlgorithms/C++: dynamic_programming/longest_common_string.cpp Source File</title>
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpack-3rd-party/doxygen-awesome-css@2.2.0-1/doxygen-awesome-darkmode-toggle.js"></script>
<script type="text/javascript">
DoxygenAwesomeDarkModeToggle.init()
</script>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../cookie.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript">
window.MathJax = {
options: {
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process'
},
loader: {
load: ['[tex]/ams']
},
tex: {
macros: {},
packages: ['base','configmacros','ams']
}
};
</script>
<script type="text/javascript" id="MathJax-script" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectlogo"><img alt="Logo" src="../../project_logo.png"/></td>
<td id="projectalign">
<div id="projectname">TheAlgorithms/C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">All the algorithms implemented in C++</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.13.2 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(1); });
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('../../',true,false,'search.php','Search',true);
$(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){initNavTree('da/d0d/longest__common__string_8cpp_source.html','../../'); initResizable(true); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="headertitle"><div class="title">longest_common_string.cpp</div></div>
</div><!--header-->
<div class="contents">
<a href="../../da/d0d/longest__common__string_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"> 12</span> </div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"> 13</span><span class="preprocessor">#include &lt;cassert&gt;</span> </div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span><span class="preprocessor">#include &lt;iostream&gt;</span> </div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span><span class="preprocessor">#include &lt;string&gt;</span> </div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span><span class="preprocessor">#include &lt;utility&gt;</span> </div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span><span class="preprocessor">#include &lt;vector&gt;</span> </div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"> 18</span></div>
<div class="foldopen" id="foldopen00028" data-start="{" data-end="}">
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"><a class="line" href="../../da/d0d/longest__common__string_8cpp.html#aa38b6b17bc5d46ed88acdd8414e18fa5"> 28</a></span>std::size_t <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#aa38b6b17bc5d46ed88acdd8414e18fa5">longest_common_string_length</a>(<span class="keyword">const</span> std::string&amp; string_a,</div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span> <span class="keyword">const</span> std::string&amp; string_b) {</div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span> <span class="keyword">const</span> <span class="keyword">auto</span> size_a = string_a.size();</div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span> <span class="keyword">const</span> <span class="keyword">auto</span> size_b = string_b.size();</div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> std::vector&lt;std::vector&lt;std::size_t&gt;&gt; sub_sols(</div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span> size_a + 1, std::vector&lt;std::size_t&gt;(size_b + 1, 0));</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span> </div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span> <span class="keyword">const</span> <span class="keyword">auto</span> limit = <span class="keyword">static_cast&lt;</span>std::size_t<span class="keyword">&gt;</span>(-1);</div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> <span class="keywordflow">for</span> (std::size_t pos_a = size_a - 1; pos_a != limit; --pos_a) {</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> <span class="keywordflow">for</span> (std::size_t pos_b = size_b - 1; pos_b != limit; --pos_b) {</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> <span class="keywordflow">if</span> (string_a[pos_a] == string_b[pos_b]) {</div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span> sub_sols[pos_a][pos_b] = 1 + sub_sols[pos_a + 1][pos_b + 1];</div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> } <span class="keywordflow">else</span> {</div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span> sub_sols[pos_a][pos_b] = std::max(sub_sols[pos_a + 1][pos_b],</div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span> sub_sols[pos_a][pos_b + 1]);</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> }</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> }</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> }</div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> </div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> <span class="keywordflow">return</span> sub_sols[0][0];</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span>}</div>
</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span></div>
<div class="foldopen" id="foldopen00054" data-start="{" data-end="};">
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"><a class="line" href="../../da/d86/struct_test_case.html"> 54</a></span><span class="keyword">struct </span>TestCase {</div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> <span class="keyword">const</span> std::string string_a;</div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> <span class="keyword">const</span> std::string string_b;</div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> <span class="keyword">const</span> std::size_t common_string_len;</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> </div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> TestCase(std::string string_a, std::string string_b,</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> <span class="keyword">const</span> std::size_t in_common_string_len)</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> : string_a(std::move(string_a)),</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> string_b(std::move(string_b)),</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> common_string_len(in_common_string_len) {}</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span>};</div>
</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span></div>
<div class="foldopen" id="foldopen00069" data-start="{" data-end="}">
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"><a class="line" href="../../da/d0d/longest__common__string_8cpp.html#a967854a526bc15403d783a033155fc5c"> 69</a></span>std::vector&lt;TestCase&gt; <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#a967854a526bc15403d783a033155fc5c">get_test_cases</a>() {</div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> <span class="keywordflow">return</span> {<a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;&quot;</span>, <span class="stringliteral">&quot;&quot;</span>, 0),</div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> <a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;ab&quot;</span>, <span class="stringliteral">&quot;ab&quot;</span>, 2),</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> <a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;ab&quot;</span>, <span class="stringliteral">&quot;ba&quot;</span>, 1),</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> <a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;&quot;</span>, <span class="stringliteral">&quot;xyz&quot;</span>, 0),</div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> <a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;abcde&quot;</span>, <span class="stringliteral">&quot;ace&quot;</span>, 3),</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> <a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;BADANA&quot;</span>, <span class="stringliteral">&quot;ANADA&quot;</span>, 3),</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> <a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;BADANA&quot;</span>, <span class="stringliteral">&quot;CANADAS&quot;</span>, 3),</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> <a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;a1a234a5aaaa6&quot;</span>, <span class="stringliteral">&quot;A1AAAA234AAA56AAAAA&quot;</span>, 6),</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> <a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;123x&quot;</span>, <span class="stringliteral">&quot;123&quot;</span>, 3),</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> <a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;12x3x&quot;</span>, <span class="stringliteral">&quot;123&quot;</span>, 3),</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> <a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;1x2x3x&quot;</span>, <span class="stringliteral">&quot;123&quot;</span>, 3),</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> <a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;x1x2x3x&quot;</span>, <span class="stringliteral">&quot;123&quot;</span>, 3),</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> <a class="code hl_struct" href="../../da/d86/struct_test_case.html">TestCase</a>(<span class="stringliteral">&quot;x12x3x&quot;</span>, <span class="stringliteral">&quot;123&quot;</span>, 3)};</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span>}</div>
</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span></div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span><span class="keyword">template</span> &lt;<span class="keyword">typename</span> TestCases&gt;</div>
<div class="foldopen" id="foldopen00091" data-start="{" data-end="}">
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"><a class="line" href="../../da/d0d/longest__common__string_8cpp.html#a9b229daad982a186a4d8d90aa8f38561"> 91</a></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#a9b229daad982a186a4d8d90aa8f38561">test_longest_common_string_length</a>(<span class="keyword">const</span> <a class="code hl_class" href="../../d5/d58/class_test_cases.html">TestCases</a>&amp; test_cases) {</div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span>&amp; cur_tc : test_cases) {</div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> assert(<a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#aa38b6b17bc5d46ed88acdd8414e18fa5">longest_common_string_length</a>(cur_tc.string_a, cur_tc.string_b) ==</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> cur_tc.common_string_len);</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span> }</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span>}</div>
</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span></div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span><span class="keyword">template</span> &lt;<span class="keyword">typename</span> TestCases&gt;</div>
<div class="foldopen" id="foldopen00105" data-start="{" data-end="}">
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"><a class="line" href="../../da/d0d/longest__common__string_8cpp.html#ad1e613c1b85cc04ed931b6c745fec155"> 105</a></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#ad1e613c1b85cc04ed931b6c745fec155">test_longest_common_string_length_is_symmetric</a>(</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span> <span class="keyword">const</span> <a class="code hl_class" href="../../d5/d58/class_test_cases.html">TestCases</a>&amp; test_cases) {</div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span>&amp; cur_tc : test_cases) {</div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"> 108</span> assert(<a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#aa38b6b17bc5d46ed88acdd8414e18fa5">longest_common_string_length</a>(cur_tc.string_b, cur_tc.string_a) ==</div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span> cur_tc.common_string_len);</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"> 110</span> }</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno"> 111</span>}</div>
</div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span></div>
<div class="foldopen" id="foldopen00119" data-start="{" data-end="}">
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"><a class="line" href="../../da/d0d/longest__common__string_8cpp.html#acb03dbbcee6d607db471021168be8541"> 119</a></span>std::string <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#acb03dbbcee6d607db471021168be8541">reverse_str</a>(<span class="keyword">const</span> std::string&amp; in_str) {</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span> <span class="keywordflow">return</span> {in_str.rbegin(), in_str.rend()};</div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno"> 121</span>}</div>
</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno"> 122</span></div>
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno"> 129</span><span class="keyword">template</span> &lt;<span class="keyword">typename</span> TestCases&gt;</div>
<div class="foldopen" id="foldopen00130" data-start="{" data-end="}">
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno"><a class="line" href="../../da/d0d/longest__common__string_8cpp.html#a23ab67b0d9600697695fc8679462d8fe"> 130</a></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#a23ab67b0d9600697695fc8679462d8fe">test_longest_common_string_length_for_reversed_inputs</a>(</div>
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno"> 131</span> <span class="keyword">const</span> <a class="code hl_class" href="../../d5/d58/class_test_cases.html">TestCases</a>&amp; test_cases) {</div>
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno"> 132</span> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span>&amp; cur_tc : test_cases) {</div>
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno"> 133</span> assert(<a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#aa38b6b17bc5d46ed88acdd8414e18fa5">longest_common_string_length</a>(<a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#acb03dbbcee6d607db471021168be8541">reverse_str</a>(cur_tc.string_a),</div>
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno"> 134</span> <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#acb03dbbcee6d607db471021168be8541">reverse_str</a>(cur_tc.string_b)) ==</div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno"> 135</span> cur_tc.common_string_len);</div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno"> 136</span> }</div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno"> 137</span>}</div>
</div>
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno"> 138</span></div>
<div class="foldopen" id="foldopen00142" data-start="{" data-end="}">
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno"><a class="line" href="../../da/d0d/longest__common__string_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e"> 142</a></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e">tests</a>() {</div>
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno"> 143</span> <span class="keyword">const</span> <span class="keyword">auto</span> test_cases = <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#a967854a526bc15403d783a033155fc5c">get_test_cases</a>();</div>
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno"> 144</span> assert(test_cases.size() &gt; 0);</div>
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno"> 145</span> <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#a9b229daad982a186a4d8d90aa8f38561">test_longest_common_string_length</a>(test_cases);</div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno"> 146</span> <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#ad1e613c1b85cc04ed931b6c745fec155">test_longest_common_string_length_is_symmetric</a>(test_cases);</div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno"> 147</span> <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#a23ab67b0d9600697695fc8679462d8fe">test_longest_common_string_length_for_reversed_inputs</a>(test_cases);</div>
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno"> 148</span> </div>
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno"> 149</span> std::cout &lt;&lt; <span class="stringliteral">&quot;All tests have successfully passed!\n&quot;</span>;</div>
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno"> 150</span>}</div>
</div>
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno"> 151</span></div>
<div class="foldopen" id="foldopen00156" data-start="{" data-end="}">
<div class="line"><a id="l00156" name="l00156"></a><span class="lineno"><a class="line" href="../../da/d0d/longest__common__string_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4"> 156</a></span><span class="keywordtype">int</span> <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a>() {</div>
<div class="line"><a id="l00157" name="l00157"></a><span class="lineno"> 157</span> <a class="code hl_function" href="../../da/d0d/longest__common__string_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e">tests</a>();</div>
<div class="line"><a id="l00158" name="l00158"></a><span class="lineno"> 158</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><a id="l00159" name="l00159"></a><span class="lineno"> 159</span>}</div>
</div>
<div class="ttc" id="aclass_test_cases_html"><div class="ttname"><a href="../../d5/d58/class_test_cases.html">TestCases</a></div><div class="ttdoc">class encapsulating the necessary test cases</div><div class="ttdef"><b>Definition</b> <a href="../../d4/d32/inorder__successor__of__bst_8cpp_source.html#l00225">inorder_successor_of_bst.cpp:225</a></div></div>
<div class="ttc" id="alongest__common__string_8cpp_html_a23ab67b0d9600697695fc8679462d8fe"><div class="ttname"><a href="../../da/d0d/longest__common__string_8cpp.html#a23ab67b0d9600697695fc8679462d8fe">test_longest_common_string_length_for_reversed_inputs</a></div><div class="ttdeci">static void test_longest_common_string_length_for_reversed_inputs(const TestCases &amp;test_cases)</div><div class="ttdoc">checks if the function longest_common_string_length returns the same result when its inputs are rever...</div><div class="ttdef"><b>Definition</b> <a href="#l00130">longest_common_string.cpp:130</a></div></div>
<div class="ttc" id="alongest__common__string_8cpp_html_a483bb8ccf42aaf7375a83e91490eda1e"><div class="ttname"><a href="../../da/d0d/longest__common__string_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e">tests</a></div><div class="ttdeci">static void tests()</div><div class="ttdoc">runs all tests for longest_common_string_length funcion</div><div class="ttdef"><b>Definition</b> <a href="#l00142">longest_common_string.cpp:142</a></div></div>
<div class="ttc" id="alongest__common__string_8cpp_html_a967854a526bc15403d783a033155fc5c"><div class="ttname"><a href="../../da/d0d/longest__common__string_8cpp.html#a967854a526bc15403d783a033155fc5c">get_test_cases</a></div><div class="ttdeci">std::vector&lt; TestCase &gt; get_test_cases()</div><div class="ttdef"><b>Definition</b> <a href="#l00069">longest_common_string.cpp:69</a></div></div>
<div class="ttc" id="alongest__common__string_8cpp_html_a9b229daad982a186a4d8d90aa8f38561"><div class="ttname"><a href="../../da/d0d/longest__common__string_8cpp.html#a9b229daad982a186a4d8d90aa8f38561">test_longest_common_string_length</a></div><div class="ttdeci">static void test_longest_common_string_length(const TestCases &amp;test_cases)</div><div class="ttdoc">checks the function longest_common_string_length agains example data</div><div class="ttdef"><b>Definition</b> <a href="#l00091">longest_common_string.cpp:91</a></div></div>
<div class="ttc" id="alongest__common__string_8cpp_html_aa38b6b17bc5d46ed88acdd8414e18fa5"><div class="ttname"><a href="../../da/d0d/longest__common__string_8cpp.html#aa38b6b17bc5d46ed88acdd8414e18fa5">longest_common_string_length</a></div><div class="ttdeci">std::size_t longest_common_string_length(const std::string &amp;string_a, const std::string &amp;string_b)</div><div class="ttdoc">computes the length of the longest common string created from input strings</div><div class="ttdef"><b>Definition</b> <a href="#l00028">longest_common_string.cpp:28</a></div></div>
<div class="ttc" id="alongest__common__string_8cpp_html_acb03dbbcee6d607db471021168be8541"><div class="ttname"><a href="../../da/d0d/longest__common__string_8cpp.html#acb03dbbcee6d607db471021168be8541">reverse_str</a></div><div class="ttdeci">std::string reverse_str(const std::string &amp;in_str)</div><div class="ttdoc">reverses a given string</div><div class="ttdef"><b>Definition</b> <a href="#l00119">longest_common_string.cpp:119</a></div></div>
<div class="ttc" id="alongest__common__string_8cpp_html_ad1e613c1b85cc04ed931b6c745fec155"><div class="ttname"><a href="../../da/d0d/longest__common__string_8cpp.html#ad1e613c1b85cc04ed931b6c745fec155">test_longest_common_string_length_is_symmetric</a></div><div class="ttdeci">static void test_longest_common_string_length_is_symmetric(const TestCases &amp;test_cases)</div><div class="ttdoc">checks if the function longest_common_string_length returns the same result when its argument are fli...</div><div class="ttdef"><b>Definition</b> <a href="#l00105">longest_common_string.cpp:105</a></div></div>
<div class="ttc" id="alongest__common__string_8cpp_html_ae66f6b31b5ad750f1fe042a706a4e3d4"><div class="ttname"><a href="../../da/d0d/longest__common__string_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a></div><div class="ttdeci">int main()</div><div class="ttdoc">Main function.</div><div class="ttdef"><b>Definition</b> <a href="#l00156">longest_common_string.cpp:156</a></div></div>
<div class="ttc" id="astruct_test_case_html"><div class="ttname"><a href="../../da/d86/struct_test_case.html">TestCase</a></div><div class="ttdoc">represents single example inputs and expected output of the function longest_common_string_length</div><div class="ttdef"><b>Definition</b> <a href="#l00054">longest_common_string.cpp:54</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_8a20dd5bfd5341a725342bf72b6b686f.html">dynamic_programming</a></li><li class="navelem"><a class="el" href="../../da/d0d/longest__common__string_8cpp.html">longest_common_string.cpp</a></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.13.2 </li>
</ul>
</div>
</body>
</html>