@@ -58,10 +58,25 @@ class Challenge:
5858
5959 """
6060
61- sample = 'sample'
62- """Holds a minimal example of the input.
61+ sample = '''
62+ sample
63+ sample
64+ '''
65+ """Holds a minimal example of the input with additional whitespace.
6366
6467 This class variable should always be preset with a tiny sample of input.
68+ Whitespace surrounding lines is for readability. It typically needs to be
69+ stripped to get the actual sample.
70+ """
71+
72+ expect = '''
73+ expected result
74+ expected result
75+ '''
76+ """Holds the expected result with additional leading whitespace.
77+
78+ Whitespace surrounding lines is for readability. It typically needs to be
79+ stripped to get the actual expactation.
6580 """
6681
6782 br = '\n '
@@ -135,8 +150,7 @@ def read(self):
135150
136151 Typically this method can be used as is.
137152 """
138- lines = self .sample .strip ().splitlines ()
139- self .lines = [line .strip () for line in lines ]
153+ self .lines = self .example ().splitlines ()
140154
141155 def build (self ):
142156 """Set up the model from the input lines.
@@ -171,13 +185,36 @@ def format(self):
171185 self .output = str (self .result )
172186
173187 # --------------------------------------------------
174- # Accessing lines
188+ # Accessing example and expectation
189+ # --------------------------------------------------
190+
191+ def example (self ):
192+ """Get the sample, with heading whitespace trimmed"""
193+ lines = self .sample .strip ().splitlines ()
194+ return '\n ' .join (line .strip () for line in lines )
195+
196+ def expectation (self ):
197+ """Get the expecation, with heading whitespace trimmed"""
198+ lines = self .expect .strip ().splitlines ()
199+ return '\n ' .join (line .strip () for line in lines )
200+
201+ # --------------------------------------------------
202+ # Accessing input lines
175203 # --------------------------------------------------
176204
177205 def line (self , number ):
178206 """ Return one line by the given number. """
179207 return self .lines [number ]
180208
209+ def line_to_words (self , line_nr ):
210+ """ Split one line into a list of words.
211+
212+ The number of the line is selected by line_nr.
213+ The split behaviour can be adjusted by changing self.split_pattern.
214+ """
215+
216+ return list (re .compile (self .split_pattern ).split (self .line (line_nr )))
217+
181218 def line_to_integers (self , line_nr ):
182219 """ Split one line into a list of integers.
183220
@@ -188,6 +225,14 @@ def line_to_integers(self, line_nr):
188225 return [int (i ) for i in
189226 re .compile (self .split_pattern ).split (self .line (line_nr ))]
190227
228+ def line_to_integer (self , line_nr ):
229+ """ Return line as integer.
230+
231+ The number of the line is selected by line_nr.
232+ """
233+
234+ return int (self .line (line_nr ))
235+
191236 def line_to_floats (self , line_nr ):
192237 """ Split one line into a list of floats.
193238
@@ -271,6 +316,12 @@ def fasta(self, start=0, stop=None):
271316 # Yield final sequence
272317 yield name , sequence
273318
319+ def fasta_strands (self , start = 0 , stop = None ):
320+ """ Get the strands of a fasta read as list.
321+
322+ Takes the same arguments as self.fasta() and delegates to it.
323+ """
324+ return list (dict (self .fasta (start , stop )).values ())
274325
275326 # noinspection PyMethodMayBeStatic
276327 def _to_edge (self , match ):
0 commit comments