trackler 2.2.1.96 → 2.2.1.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/tracks/fsharp/exercises/bowling/BowlingTest.fs +77 -42
  4. data/tracks/fsharp/generators/Generators.fs +24 -0
  5. data/tracks/go/exercises/acronym/cases_test.go +2 -6
  6. data/tracks/go/exercises/anagram/cases_test.go +2 -40
  7. data/tracks/go/exercises/hamming/.meta/gen.go +7 -5
  8. data/tracks/go/exercises/hamming/cases_test.go +2 -2
  9. data/tracks/go/exercises/largest-series-product/.meta/gen.go +6 -4
  10. data/tracks/go/exercises/largest-series-product/cases_test.go +2 -2
  11. data/tracks/go/exercises/leap/.meta/gen.go +5 -3
  12. data/tracks/go/exercises/leap/cases_test.go +2 -2
  13. data/tracks/go/exercises/nth-prime/.meta/gen.go +5 -3
  14. data/tracks/go/exercises/nth-prime/cases_test.go +2 -2
  15. data/tracks/java/exercises/allergies/.meta/hints.md +58 -0
  16. data/tracks/java/exercises/allergies/README.md +62 -0
  17. data/tracks/java/exercises/atbash-cipher/.meta/hints.md +58 -0
  18. data/tracks/java/exercises/atbash-cipher/README.md +62 -0
  19. data/tracks/java/exercises/bob/.meta/hints.md +58 -0
  20. data/tracks/java/exercises/bob/README.md +62 -0
  21. data/tracks/java/exercises/bracket-push/.meta/hints.md +58 -0
  22. data/tracks/java/exercises/bracket-push/README.md +62 -0
  23. data/tracks/java/exercises/hello-world/.meta/version +1 -0
  24. data/tracks/java/exercises/pascals-triangle/.meta/hints.md +58 -0
  25. data/tracks/java/exercises/pascals-triangle/README.md +62 -0
  26. data/tracks/java/exercises/series/.meta/hints.md +58 -0
  27. data/tracks/java/exercises/series/README.md +62 -0
  28. data/tracks/python/exercises/grep/grep_test.py +142 -79
  29. data/tracks/python/exercises/house/example.py +3 -3
  30. data/tracks/python/exercises/house/house.py +1 -1
  31. data/tracks/python/exercises/luhn/example.py +4 -4
  32. data/tracks/python/exercises/luhn/luhn.py +1 -1
  33. metadata +9 -2
@@ -3,6 +3,68 @@
3
3
  Given a string containing brackets `[]`, braces `{}` and parentheses `()`,
4
4
  verify that all the pairs are matched and nested correctly.
5
5
 
6
+ # Java Tips
7
+
8
+ Since this exercise has difficulty 5 it doesn't come with any starter implementation.
9
+ This is so that you get to practice creating classes and methods which is an important part of programming in Java.
10
+ It does mean that when you first try to run the tests, they won't compile.
11
+ They will give you an error similar to:
12
+ ```
13
+ path-to-exercism-dir\exercism\java\name-of-exercise\src\test\java\ExerciseClassNameTest.java:14: error: cannot find symbol
14
+ ExerciseClassName exerciseClassName = new ExerciseClassName();
15
+ ^
16
+ symbol: class ExerciseClassName
17
+ location: class ExerciseClassNameTest
18
+ ```
19
+ This error occurs because the test refers to a class that hasn't been created yet (`ExerciseClassName`).
20
+ To resolve the error you need to add a file matching the class name in the error to the `src/main/java` directory.
21
+ For example, for the error above you would add a file called `ExerciseClassName.java`.
22
+
23
+ When you try to run the tests again you will get slightly different errors.
24
+ You might get an error similar to:
25
+ ```
26
+ constructor ExerciseClassName in class ExerciseClassName cannot be applied to given types;
27
+ ExerciseClassName exerciseClassName = new ExerciseClassName("some argument");
28
+ ^
29
+ required: no arguments
30
+ found: String
31
+ reason: actual and formal argument lists differ in length
32
+ ```
33
+ This error means that you need to add a [constructor](https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html) to your new class.
34
+ If you don't add a constructor, Java will add a default one for you.
35
+ This default constructor takes no arguments.
36
+ So if the tests expect your class to have a constructor which takes arguments, then you need to create this constructor yourself.
37
+ In the example above you could add:
38
+ ```
39
+ ExerciseClassName(String input) {
40
+
41
+ }
42
+ ```
43
+ That should make the error go away, though you might need to add some more code to your constructor to make the test pass!
44
+
45
+ You might also get an error similar to:
46
+ ```
47
+ error: cannot find symbol
48
+ assertEquals(expectedOutput, exerciseClassName.someMethod());
49
+ ^
50
+ symbol: method someMethod()
51
+ location: variable exerciseClassName of type ExerciseClassName
52
+ ```
53
+ This error means that you need to add a method called `someMethod` to your new class.
54
+ In the example above you would add:
55
+ ```
56
+ String someMethod() {
57
+ return "";
58
+ }
59
+ ```
60
+ Make sure the return type matches what the test is expecting.
61
+ You can find out which return type it should have by looking at the type of object it's being compared to in the tests.
62
+ Or you could set your method to return some random type (e.g. `void`), and run the tests again.
63
+ The new error should tell you which type it's expecting.
64
+
65
+ After having resolved these errors you should be ready to start making the tests pass!
66
+
67
+
6
68
  # Running the tests
7
69
 
8
70
  You can run all the tests for an exercise by entering
@@ -0,0 +1,58 @@
1
+ Since this exercise has difficulty 5 it doesn't come with any starter implementation.
2
+ This is so that you get to practice creating classes and methods which is an important part of programming in Java.
3
+ It does mean that when you first try to run the tests, they won't compile.
4
+ They will give you an error similar to:
5
+ ```
6
+ path-to-exercism-dir\exercism\java\name-of-exercise\src\test\java\ExerciseClassNameTest.java:14: error: cannot find symbol
7
+ ExerciseClassName exerciseClassName = new ExerciseClassName();
8
+ ^
9
+ symbol: class ExerciseClassName
10
+ location: class ExerciseClassNameTest
11
+ ```
12
+ This error occurs because the test refers to a class that hasn't been created yet (`ExerciseClassName`).
13
+ To resolve the error you need to add a file matching the class name in the error to the `src/main/java` directory.
14
+ For example, for the error above you would add a file called `ExerciseClassName.java`.
15
+
16
+ When you try to run the tests again you will get slightly different errors.
17
+ You might get an error similar to:
18
+ ```
19
+ constructor ExerciseClassName in class ExerciseClassName cannot be applied to given types;
20
+ ExerciseClassName exerciseClassName = new ExerciseClassName("some argument");
21
+ ^
22
+ required: no arguments
23
+ found: String
24
+ reason: actual and formal argument lists differ in length
25
+ ```
26
+ This error means that you need to add a [constructor](https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html) to your new class.
27
+ If you don't add a constructor, Java will add a default one for you.
28
+ This default constructor takes no arguments.
29
+ So if the tests expect your class to have a constructor which takes arguments, then you need to create this constructor yourself.
30
+ In the example above you could add:
31
+ ```
32
+ ExerciseClassName(String input) {
33
+
34
+ }
35
+ ```
36
+ That should make the error go away, though you might need to add some more code to your constructor to make the test pass!
37
+
38
+ You might also get an error similar to:
39
+ ```
40
+ error: cannot find symbol
41
+ assertEquals(expectedOutput, exerciseClassName.someMethod());
42
+ ^
43
+ symbol: method someMethod()
44
+ location: variable exerciseClassName of type ExerciseClassName
45
+ ```
46
+ This error means that you need to add a method called `someMethod` to your new class.
47
+ In the example above you would add:
48
+ ```
49
+ String someMethod() {
50
+ return "";
51
+ }
52
+ ```
53
+ Make sure the return type matches what the test is expecting.
54
+ You can find out which return type it should have by looking at the type of object it's being compared to in the tests.
55
+ Or you could set your method to return some random type (e.g. `void`), and run the tests again.
56
+ The new error should tell you which type it's expecting.
57
+
58
+ After having resolved these errors you should be ready to start making the tests pass!
@@ -14,6 +14,68 @@ the right and left of the current position in the previous row.
14
14
  # ... etc
15
15
  ```
16
16
 
17
+ # Java Tips
18
+
19
+ Since this exercise has difficulty 5 it doesn't come with any starter implementation.
20
+ This is so that you get to practice creating classes and methods which is an important part of programming in Java.
21
+ It does mean that when you first try to run the tests, they won't compile.
22
+ They will give you an error similar to:
23
+ ```
24
+ path-to-exercism-dir\exercism\java\name-of-exercise\src\test\java\ExerciseClassNameTest.java:14: error: cannot find symbol
25
+ ExerciseClassName exerciseClassName = new ExerciseClassName();
26
+ ^
27
+ symbol: class ExerciseClassName
28
+ location: class ExerciseClassNameTest
29
+ ```
30
+ This error occurs because the test refers to a class that hasn't been created yet (`ExerciseClassName`).
31
+ To resolve the error you need to add a file matching the class name in the error to the `src/main/java` directory.
32
+ For example, for the error above you would add a file called `ExerciseClassName.java`.
33
+
34
+ When you try to run the tests again you will get slightly different errors.
35
+ You might get an error similar to:
36
+ ```
37
+ constructor ExerciseClassName in class ExerciseClassName cannot be applied to given types;
38
+ ExerciseClassName exerciseClassName = new ExerciseClassName("some argument");
39
+ ^
40
+ required: no arguments
41
+ found: String
42
+ reason: actual and formal argument lists differ in length
43
+ ```
44
+ This error means that you need to add a [constructor](https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html) to your new class.
45
+ If you don't add a constructor, Java will add a default one for you.
46
+ This default constructor takes no arguments.
47
+ So if the tests expect your class to have a constructor which takes arguments, then you need to create this constructor yourself.
48
+ In the example above you could add:
49
+ ```
50
+ ExerciseClassName(String input) {
51
+
52
+ }
53
+ ```
54
+ That should make the error go away, though you might need to add some more code to your constructor to make the test pass!
55
+
56
+ You might also get an error similar to:
57
+ ```
58
+ error: cannot find symbol
59
+ assertEquals(expectedOutput, exerciseClassName.someMethod());
60
+ ^
61
+ symbol: method someMethod()
62
+ location: variable exerciseClassName of type ExerciseClassName
63
+ ```
64
+ This error means that you need to add a method called `someMethod` to your new class.
65
+ In the example above you would add:
66
+ ```
67
+ String someMethod() {
68
+ return "";
69
+ }
70
+ ```
71
+ Make sure the return type matches what the test is expecting.
72
+ You can find out which return type it should have by looking at the type of object it's being compared to in the tests.
73
+ Or you could set your method to return some random type (e.g. `void`), and run the tests again.
74
+ The new error should tell you which type it's expecting.
75
+
76
+ After having resolved these errors you should be ready to start making the tests pass!
77
+
78
+
17
79
  # Running the tests
18
80
 
19
81
  You can run all the tests for an exercise by entering
@@ -0,0 +1,58 @@
1
+ Since this exercise has difficulty 5 it doesn't come with any starter implementation.
2
+ This is so that you get to practice creating classes and methods which is an important part of programming in Java.
3
+ It does mean that when you first try to run the tests, they won't compile.
4
+ They will give you an error similar to:
5
+ ```
6
+ path-to-exercism-dir\exercism\java\name-of-exercise\src\test\java\ExerciseClassNameTest.java:14: error: cannot find symbol
7
+ ExerciseClassName exerciseClassName = new ExerciseClassName();
8
+ ^
9
+ symbol: class ExerciseClassName
10
+ location: class ExerciseClassNameTest
11
+ ```
12
+ This error occurs because the test refers to a class that hasn't been created yet (`ExerciseClassName`).
13
+ To resolve the error you need to add a file matching the class name in the error to the `src/main/java` directory.
14
+ For example, for the error above you would add a file called `ExerciseClassName.java`.
15
+
16
+ When you try to run the tests again you will get slightly different errors.
17
+ You might get an error similar to:
18
+ ```
19
+ constructor ExerciseClassName in class ExerciseClassName cannot be applied to given types;
20
+ ExerciseClassName exerciseClassName = new ExerciseClassName("some argument");
21
+ ^
22
+ required: no arguments
23
+ found: String
24
+ reason: actual and formal argument lists differ in length
25
+ ```
26
+ This error means that you need to add a [constructor](https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html) to your new class.
27
+ If you don't add a constructor, Java will add a default one for you.
28
+ This default constructor takes no arguments.
29
+ So if the tests expect your class to have a constructor which takes arguments, then you need to create this constructor yourself.
30
+ In the example above you could add:
31
+ ```
32
+ ExerciseClassName(String input) {
33
+
34
+ }
35
+ ```
36
+ That should make the error go away, though you might need to add some more code to your constructor to make the test pass!
37
+
38
+ You might also get an error similar to:
39
+ ```
40
+ error: cannot find symbol
41
+ assertEquals(expectedOutput, exerciseClassName.someMethod());
42
+ ^
43
+ symbol: method someMethod()
44
+ location: variable exerciseClassName of type ExerciseClassName
45
+ ```
46
+ This error means that you need to add a method called `someMethod` to your new class.
47
+ In the example above you would add:
48
+ ```
49
+ String someMethod() {
50
+ return "";
51
+ }
52
+ ```
53
+ Make sure the return type matches what the test is expecting.
54
+ You can find out which return type it should have by looking at the type of object it's being compared to in the tests.
55
+ Or you could set your method to return some random type (e.g. `void`), and run the tests again.
56
+ The new error should tell you which type it's expecting.
57
+
58
+ After having resolved these errors you should be ready to start making the tests pass!
@@ -20,6 +20,68 @@ whatever you get.
20
20
  Note that these series are only required to occupy *adjacent positions*
21
21
  in the input; the digits need not be *numerically consecutive*.
22
22
 
23
+ # Java Tips
24
+
25
+ Since this exercise has difficulty 5 it doesn't come with any starter implementation.
26
+ This is so that you get to practice creating classes and methods which is an important part of programming in Java.
27
+ It does mean that when you first try to run the tests, they won't compile.
28
+ They will give you an error similar to:
29
+ ```
30
+ path-to-exercism-dir\exercism\java\name-of-exercise\src\test\java\ExerciseClassNameTest.java:14: error: cannot find symbol
31
+ ExerciseClassName exerciseClassName = new ExerciseClassName();
32
+ ^
33
+ symbol: class ExerciseClassName
34
+ location: class ExerciseClassNameTest
35
+ ```
36
+ This error occurs because the test refers to a class that hasn't been created yet (`ExerciseClassName`).
37
+ To resolve the error you need to add a file matching the class name in the error to the `src/main/java` directory.
38
+ For example, for the error above you would add a file called `ExerciseClassName.java`.
39
+
40
+ When you try to run the tests again you will get slightly different errors.
41
+ You might get an error similar to:
42
+ ```
43
+ constructor ExerciseClassName in class ExerciseClassName cannot be applied to given types;
44
+ ExerciseClassName exerciseClassName = new ExerciseClassName("some argument");
45
+ ^
46
+ required: no arguments
47
+ found: String
48
+ reason: actual and formal argument lists differ in length
49
+ ```
50
+ This error means that you need to add a [constructor](https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html) to your new class.
51
+ If you don't add a constructor, Java will add a default one for you.
52
+ This default constructor takes no arguments.
53
+ So if the tests expect your class to have a constructor which takes arguments, then you need to create this constructor yourself.
54
+ In the example above you could add:
55
+ ```
56
+ ExerciseClassName(String input) {
57
+
58
+ }
59
+ ```
60
+ That should make the error go away, though you might need to add some more code to your constructor to make the test pass!
61
+
62
+ You might also get an error similar to:
63
+ ```
64
+ error: cannot find symbol
65
+ assertEquals(expectedOutput, exerciseClassName.someMethod());
66
+ ^
67
+ symbol: method someMethod()
68
+ location: variable exerciseClassName of type ExerciseClassName
69
+ ```
70
+ This error means that you need to add a method called `someMethod` to your new class.
71
+ In the example above you would add:
72
+ ```
73
+ String someMethod() {
74
+ return "";
75
+ }
76
+ ```
77
+ Make sure the return type matches what the test is expecting.
78
+ You can find out which return type it should have by looking at the type of object it's being compared to in the tests.
79
+ Or you could set your method to return some random type (e.g. `void`), and run the tests again.
80
+ The new error should tell you which type it's expecting.
81
+
82
+ After having resolved these errors you should be ready to start making the tests pass!
83
+
84
+
23
85
  # Running the tests
24
86
 
25
87
  You can run all the tests for an exercise by entering
@@ -1,5 +1,8 @@
1
- import os
2
1
  import unittest
2
+ try:
3
+ import builtins
4
+ except ImportError:
5
+ import __builtin__ as builtins
3
6
 
4
7
  from grep import grep
5
8
 
@@ -15,8 +18,7 @@ And Heroes gave (so stood the will of Jove)
15
18
  To dogs and to all ravening fowls a prey,
16
19
  When fierce dispute had separated once
17
20
  The noble Chief Achilles from the son
18
- Of Atreus, Agamemnon, King of men.
19
- '''
21
+ Of Atreus, Agamemnon, King of men.'''
20
22
 
21
23
  MIDSUMMERNIGHTFILENAME = 'midsummer-night.txt'
22
24
  MIDSUMMERNIGHTCONTENTS = '''I do entreat your grace to pardon me.
@@ -25,8 +27,7 @@ Nor how it may concern my modesty,
25
27
  In such a presence here to plead my thoughts;
26
28
  But I beseech your grace that I may know
27
29
  The worst that may befall me in this case,
28
- If I refuse to wed Demetrius.
29
- '''
30
+ If I refuse to wed Demetrius.'''
30
31
 
31
32
  PARADISELOSTFILENAME = 'paradise-lost.txt'
32
33
  PARADISELOSTCONTENTS = '''Of Mans First Disobedience, and the Fruit
@@ -36,17 +37,59 @@ With loss of Eden, till one greater Man
36
37
  Restore us, and regain the blissful Seat,
37
38
  Sing Heav'nly Muse, that on the secret top
38
39
  Of Oreb, or of Sinai, didst inspire
39
- That Shepherd, who first taught the chosen Seed
40
- '''
40
+ That Shepherd, who first taught the chosen Seed'''
41
+ FILENAMES = [
42
+ ILIADFILENAME,
43
+ MIDSUMMERNIGHTFILENAME,
44
+ PARADISELOSTFILENAME,
45
+ ]
46
+ FILES = {}
41
47
 
42
48
 
43
- def remove_file(file_name):
44
- try:
45
- os.remove(file_name)
46
- except OSError:
49
+ class File(object):
50
+ def __init__(self, name=''):
51
+ self.name = name
52
+ self.contents = ''
53
+
54
+ def read(self):
55
+ return self.contents
56
+
57
+ def readlines(self):
58
+ return [line + '\n' for line in self.read().split('\n') if line]
59
+
60
+ def write(self, data):
61
+ self.contents += data
62
+
63
+ def __enter__(self):
64
+ return self
65
+
66
+ def __exit__(self, *args):
47
67
  pass
48
68
 
49
69
 
70
+ # Store builtin definition of open()
71
+ builtins.oldopen = builtins.open
72
+
73
+
74
+ def open(name, mode='r', *args, **kwargs):
75
+ # if name is a mocked file name, lookup corresponding mocked file
76
+ if name in FILENAMES:
77
+ if mode == 'w' or name not in FILES:
78
+ FILES[name] = File(name)
79
+ return FILES[name]
80
+ # else call builtin open()
81
+ else:
82
+ return builtins.oldopen(name, mode, *args, **kwargs)
83
+
84
+
85
+ builtins.open = open
86
+
87
+
88
+ # remove mocked file contents
89
+ def remove_file(file_name):
90
+ del FILES[file_name]
91
+
92
+
50
93
  def create_file(name, contents):
51
94
  with open(name, 'w') as f:
52
95
  f.write(contents)
@@ -55,6 +98,8 @@ def create_file(name, contents):
55
98
  class GrepTest(unittest.TestCase):
56
99
  @classmethod
57
100
  def setUpClass(self):
101
+ # Override builtin open() with mock-file-enabled one
102
+ builtins.open = open
58
103
  create_file(ILIADFILENAME, ILIADCONTENTS)
59
104
  create_file(MIDSUMMERNIGHTFILENAME, MIDSUMMERNIGHTCONTENTS)
60
105
  create_file(PARADISELOSTFILENAME, PARADISELOSTCONTENTS)
@@ -64,151 +109,169 @@ class GrepTest(unittest.TestCase):
64
109
  remove_file(ILIADFILENAME)
65
110
  remove_file(MIDSUMMERNIGHTFILENAME)
66
111
  remove_file(PARADISELOSTFILENAME)
112
+ # Restore builtin open()
113
+ builtins.open = builtins.oldopen
67
114
 
68
115
  def test_one_file_one_match_no_flags(self):
69
116
  self.assertMultiLineEqual(
70
117
  grep("Agamemnon", [ILIADFILENAME]),
71
- "Of Atreus, Agamemnon, King of men.\n")
118
+ "Of Atreus, Agamemnon, King of men.\n"
119
+ )
72
120
 
73
121
  def test_one_file_one_match_print_line_numbers_flag(self):
74
122
  self.assertMultiLineEqual(
75
123
  grep("Forbidden", [PARADISELOSTFILENAME], "-n"),
76
- "2:Of that Forbidden Tree, whose mortal tast\n")
124
+ "2:Of that Forbidden Tree, whose mortal tast\n"
125
+ )
77
126
 
78
127
  def test_one_file_one_match_case_insensitive_flag(self):
79
128
  self.assertMultiLineEqual(
80
129
  grep("FORBIDDEN", [PARADISELOSTFILENAME], "-i"),
81
- "Of that Forbidden Tree, whose mortal tast\n")
130
+ "Of that Forbidden Tree, whose mortal tast\n"
131
+ )
82
132
 
83
133
  def test_one_file_one_match_print_file_names_flag(self):
84
134
  self.assertMultiLineEqual(
85
135
  grep("Forbidden", [PARADISELOSTFILENAME], "-l"),
86
- PARADISELOSTFILENAME + '\n')
136
+ PARADISELOSTFILENAME + '\n'
137
+ )
87
138
 
88
139
  def test_one_file_one_match_match_entire_lines_flag(self):
89
140
  self.assertMultiLineEqual(
90
141
  grep("With loss of Eden, till one greater Man",
91
142
  [PARADISELOSTFILENAME], "-x"),
92
- "With loss of Eden, till one greater Man\n")
143
+ "With loss of Eden, till one greater Man\n"
144
+ )
93
145
 
94
146
  def test_one_file_one_match_multiple_flags(self):
95
147
  self.assertMultiLineEqual(
96
- grep("OF ATREUS, Agamemnon, KIng of MEN.", [ILIADFILENAME],
97
- "-n -i -x"), "9:Of Atreus, Agamemnon, King of men.\n")
148
+ grep(
149
+ "OF ATREUS, Agamemnon, KIng of MEN.",
150
+ [ILIADFILENAME],
151
+ "-n -i -x"
152
+ ),
153
+ "9:Of Atreus, Agamemnon, King of men.\n"
154
+ )
98
155
 
99
156
  def test_one_file_several_matches_no_flags(self):
100
157
  self.assertMultiLineEqual(
101
158
  grep("may", [MIDSUMMERNIGHTFILENAME]),
102
- ("Nor how it may concern my modesty,\n"
103
- "But I beseech your grace that I may know\n"
104
- "The worst that may befall me in this case,\n"))
159
+ "Nor how it may concern my modesty,\n"
160
+ "But I beseech your grace that I may know\n"
161
+ "The worst that may befall me in this case,\n"
162
+ )
105
163
 
106
164
  def test_one_file_several_matches_print_line_numbers_flag(self):
107
165
  self.assertMultiLineEqual(
108
166
  grep("may", [MIDSUMMERNIGHTFILENAME], "-n"),
109
- ("3:Nor how it may concern my modesty,\n"
110
- "5:But I beseech your grace that I may know\n"
111
- "6:The worst that may befall me in this case,\n"))
167
+ "3:Nor how it may concern my modesty,\n"
168
+ "5:But I beseech your grace that I may know\n"
169
+ "6:The worst that may befall me in this case,\n"
170
+ )
112
171
 
113
172
  def test_one_file_several_matches_match_entire_lines_flag(self):
114
173
  self.assertMultiLineEqual(
115
- grep("may", [MIDSUMMERNIGHTFILENAME], "-x"), "")
174
+ grep("may", [MIDSUMMERNIGHTFILENAME], "-x"),
175
+ ""
176
+ )
116
177
 
117
178
  def test_one_file_several_matches_case_insensitive_flag(self):
118
179
  self.assertMultiLineEqual(
119
180
  grep("ACHILLES", [ILIADFILENAME], "-i"),
120
- ("Achilles sing, O Goddess! Peleus' son;\n"
121
- "The noble Chief Achilles from the son\n"))
181
+ "Achilles sing, O Goddess! Peleus' son;\n"
182
+ "The noble Chief Achilles from the son\n"
183
+ )
122
184
 
123
185
  def test_one_file_several_matches_inverted_flag(self):
124
186
  self.assertMultiLineEqual(
125
187
  grep("Of", [PARADISELOSTFILENAME], "-v"),
126
- ("Brought Death into the World, and all our woe,\n"
127
- "With loss of Eden, till one greater Man\n"
128
- "Restore us, and regain the blissful Seat,\n"
129
- "Sing Heav'nly Muse, that on the secret top\n"
130
- "That Shepherd, who first taught the chosen Seed\n"))
188
+ "Brought Death into the World, and all our woe,\n"
189
+ "With loss of Eden, till one greater Man\n"
190
+ "Restore us, and regain the blissful Seat,\n"
191
+ "Sing Heav'nly Muse, that on the secret top\n"
192
+ "That Shepherd, who first taught the chosen Seed\n"
193
+ )
131
194
 
132
195
  def test_one_file_no_matches_various_flags(self):
133
196
  self.assertMultiLineEqual(
134
- grep("Gandalf", [ILIADFILENAME], "-n -l -x -i"), "")
197
+ grep("Gandalf", [ILIADFILENAME], "-n -l -x -i"),
198
+ ""
199
+ )
135
200
 
136
201
  def test_multiple_files_one_match_no_flags(self):
137
202
  self.assertMultiLineEqual(
138
- grep(
139
- "Agamemnon",
140
- [ILIADFILENAME, MIDSUMMERNIGHTFILENAME, PARADISELOSTFILENAME]),
141
- "iliad.txt:Of Atreus, Agamemnon, King of men.\n")
203
+ grep("Agamemnon", FILENAMES),
204
+ "iliad.txt:Of Atreus, Agamemnon, King of men.\n"
205
+ )
142
206
 
143
207
  def test_multiple_files_several_matches_no_flags(self):
144
208
  self.assertMultiLineEqual(
145
- grep("may",
146
- ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"]),
147
- ("midsummer-night.txt:Nor how it may concern my modesty,\n"
148
- "midsummer-night.txt:But I beseech your grace that I may know\n"
149
- "midsummer-night.txt:The worst that may befall me in this case,\n"
150
- ))
209
+ grep("may", FILENAMES),
210
+ "midsummer-night.txt:Nor how it may concern my modesty,\n"
211
+ "midsummer-night.txt:But I beseech your grace that I may know\n"
212
+ "midsummer-night.txt:The worst that may befall me in this case,\n"
213
+ )
151
214
 
152
215
  def test_multiple_files_several_matches_print_line_numbers_flag(self):
216
+ expected = (
217
+ "midsummer-night.txt:5:But I beseech your grace that I may know\n"
218
+ "midsummer-night.txt:6:The worst that may befall me in this case,"
219
+ "\nparadise-lost.txt:2:Of that Forbidden Tree, whose mortal tast\n"
220
+ "paradise-lost.txt:6:Sing Heav'nly Muse, that on the secret top\n"
221
+ )
153
222
  self.assertMultiLineEqual(
154
- grep("that",
155
- ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"],
156
- "-n"),
157
- ("midsummer-night.txt:5:But I beseech your grace that I may know\n"
158
- "midsummer-night.txt:6:The worst that may befall me in this case,"
159
- "\nparadise-lost.txt:2:Of that Forbidden Tree, whose mortal tast"
160
- "\nparadise-lost.txt:6:Sing Heav'nly Muse, that on the secret top"
161
- "\n"))
223
+ grep("that", FILENAMES, "-n"),
224
+ expected
225
+ )
162
226
 
163
227
  def test_multiple_files_one_match_print_file_names_flag(self):
164
228
  self.assertMultiLineEqual(
165
- grep("who",
166
- ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"],
167
- "-l"), ILIADFILENAME + '\n' + PARADISELOSTFILENAME + '\n')
229
+ grep("who", FILENAMES, "-l"),
230
+ ILIADFILENAME + '\n' + PARADISELOSTFILENAME + '\n')
168
231
 
169
232
  def test_multiple_files_several_matches_case_insensitive_flag(self):
233
+ expected = (
234
+ "iliad.txt:Caused to Achaia's host, sent many a soul\n"
235
+ "iliad.txt:Illustrious into Ades premature,\n"
236
+ "iliad.txt:And Heroes gave (so stood the will of Jove)\n"
237
+ "iliad.txt:To dogs and to all ravening fowls a prey,\n"
238
+ "midsummer-night.txt:I do entreat your grace to pardon me.\n"
239
+ "midsummer-night.txt:In such a presence here to plead my thoughts;"
240
+ "\nmidsummer-night.txt:If I refuse to wed Demetrius.\n"
241
+ "paradise-lost.txt:Brought Death into the World, and all our woe,"
242
+ "\nparadise-lost.txt:Restore us, and regain the blissful Seat,\n"
243
+ "paradise-lost.txt:Sing Heav'nly Muse, that on the secret top\n"
244
+ )
170
245
  self.assertMultiLineEqual(
171
- grep("TO",
172
- ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"],
173
- "-i"),
174
- ("iliad.txt:Caused to Achaia's host, sent many a soul\n"
175
- "iliad.txt:Illustrious into Ades premature,\n"
176
- "iliad.txt:And Heroes gave (so stood the will of Jove)\n"
177
- "iliad.txt:To dogs and to all ravening fowls a prey,\n"
178
- "midsummer-night.txt:I do entreat your grace to pardon me.\n"
179
- "midsummer-night.txt:In such a presence here to plead my thoughts"
180
- ";\nmidsummer-night.txt:If I refuse to wed Demetrius.\n"
181
- "paradise-lost.txt:Brought Death into the World, and all our woe,"
182
- "\nparadise-lost.txt:Restore us, and regain the blissful Seat,\n"
183
- "paradise-lost.txt:Sing Heav'nly Muse, that on the secret top\n"))
246
+ grep("TO", FILENAMES, "-i"),
247
+ expected
248
+ )
184
249
 
185
250
  def test_multiple_files_several_matches_inverted_flag(self):
186
251
  self.assertMultiLineEqual(
187
- grep(
188
- "a", ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"],
189
- "-v"), ("iliad.txt:Achilles sing, O Goddess! Peleus' son;\n"
190
- "iliad.txt:The noble Chief Achilles from the son\n"
191
- "midsummer-night.txt:If I refuse to wed Demetrius.\n"))
252
+ grep("a", FILENAMES, "-v"),
253
+ "iliad.txt:Achilles sing, O Goddess! Peleus' son;\n"
254
+ "iliad.txt:The noble Chief Achilles from the son\n"
255
+ "midsummer-night.txt:If I refuse to wed Demetrius.\n"
256
+ )
192
257
 
193
258
  def test_multiple_files_one_match_match_entire_lines_flag(self):
194
259
  self.assertMultiLineEqual(
195
260
  grep("But I beseech your grace that I may know",
196
- ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"],
197
- "-x"),
261
+ FILENAMES, "-x"),
198
262
  "midsummer-night.txt:But I beseech your grace that I may know\n")
199
263
 
200
264
  def test_multiple_files_one_match_multiple_flags(self):
201
265
  self.assertMultiLineEqual(
202
266
  grep("WITH LOSS OF EDEN, TILL ONE GREATER MAN",
203
- ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"],
204
- "-n -i -x"),
267
+ FILENAMES, "-n -i -x"),
205
268
  "paradise-lost.txt:4:With loss of Eden, till one greater Man\n")
206
269
 
207
270
  def test_multiple_files_no_matches_various_flags(self):
208
271
  self.assertMultiLineEqual(
209
- grep("Frodo",
210
- ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"],
211
- "-n -l -x -i"), "")
272
+ grep("Frodo", FILENAMES, "-n -l -x -i"),
273
+ ""
274
+ )
212
275
 
213
276
 
214
277
  if __name__ == '__main__':