1
+ using System ;
2
+ using Algorithms . Strings . Search ;
3
+ using Xunit ;
4
+ using Xunit . Abstractions ;
5
+
6
+ namespace AlgorithmsUnitTest . Strings . Search
7
+ {
8
+ public class KnuthMorrisPrattUnitTest
9
+ {
10
+
11
+ private ITestOutputHelper console ;
12
+
13
+ public KnuthMorrisPrattUnitTest ( ITestOutputHelper console )
14
+ {
15
+ this . console = console ;
16
+ }
17
+
18
+ [ Fact ]
19
+ public void Test ( )
20
+ {
21
+ String text = "o fare thee well, poor devil of a Sub-Sub, whose commen- \n " + "tator I am. Thou belongest to that hopeless, sallow tribe \n "
22
+ + "which no wine of this world will ever warm ; and for whom \n " + "even Pale Sherry would be too rosy-strong ; but with whom \n "
23
+ + "one sometimes loves to sit, and feel poor-devilish, too ; and \n "
24
+ + "grow convivial upon tears ; and say to them bluntly with full \n " + "eyes and empty glasses, and in not altogether unpleasant \n "
25
+ + "sadness Give it up, Sub-Subs ! For by how much the more \n " + "pains ye take to please the world, by so much the more shall \n "
26
+ + "ye forever go thankless ! Would that I could clear out \n " + "Hampton Court and the Tuileries for ye ! But gulp down \n "
27
+ + "your tears and hie aloft to the royal-mast with your hearts ; \n " + "for your friends who have gone before are clearing out the \n "
28
+ + "seven-storied heavens, and making refugees of long-pampered \n " + "Gabriel, Michael, and Raphael, against your coming. Here \n "
29
+ + "ye strike but splintered hearts together there, ye shall \n " + "strike unsplinterable glasses! " ;
30
+
31
+ KnuthMorrisPratt bm = new KnuthMorrisPratt ( "the" ) ;
32
+ print ( "found at " + bm . Search ( text ) ) ;
33
+ Assert . NotEqual ( - 1 , bm . Search ( text ) ) ;
34
+ }
35
+
36
+ private void print ( String content )
37
+ {
38
+ Console . WriteLine ( content ) ;
39
+ console . WriteLine ( content ) ;
40
+ }
41
+ }
42
+ }
0 commit comments