Koan04 Test 02 - 'n' is incorrectly appearing in result...
Closed this issue · 2 comments
I was having issues with Koan04.
As I am new to Groovy closures, my first thought for filtering was break file into lines and loop through with a for loop and only append the StringWriter with lines that don't start with "#".
List<String> unfilteredLines = new File("$prefix/exercise.txt").readLines()
for (String unfilteredLine : unfilteredLines){
if(!unfilteredLine.startsWith("#")){
filteredResult.append(unfilteredLine)
}
}
This worked correctly but the test was failed when compared against ‘answer’, I added println to see what 'answer' was and what 'result' was.
String result = filteredResult.toString().trim().replaceAll(/[\n\r]+/, /\n/)
String answer = new File("$prefix/exercise-solved.txt").text.replaceAll(/[\n\r]+/, /\n/)
println result
println answer
assert answer == result
Result output:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque fringilla lacus ut diam laoreet fermentum.Ut ornare turpis vitae est auctor sit amet tincidunt nisi feugiat. Donec nec ligula ut nibh convallis mollissollicitudin et lacus. Phasellus odio erat, consectetur vitae dictum ac, varius consectetur dolor.Aenean pretium volutpat nisi vel laoreet. Nulla facilisi. Phasellus sed nisi nibh. Curabitur auctor erat vel arcubibendum id auctor lacus fermentum. Suspendisse cursus volutpat feugiat. Suspendisse sed urna lectus,molestie fermentum augue.Donec mauris diam, mattis quis posuere at, pharetra ac libero. Mauris a lacus id lorem tempus dapibus. Ut viverraimperdiet sapien, vel rhoncus mauris cursus eu. Donec bibendum feugiat ultrices. Vivamus facilisis nisi et lectusEtiam id leo vitae nibh bibendum semper vel sed velit. Etiam tristique urna auctor arcu feugiat nec vehicula nequevulputate. Pellentesque nunc leo, tincidunt sed dapibus sed, pulvinar nec nunc. Mauris vel urna vitae ipsum mattiscongue accumsan a tellus. Donec adipiscing arcu quis enim iaculis ut commodo nisl lacinia. Mauris turpis justo,congue quis sed urna. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.Morbi sagittis tincidunt quam, ac tristique elit rhoncus id. In sem sem, tempus venenatis faucibus eu, dictum accongue eu laoreet ac, porttitor non magna. Mauris imperdiet aliquam nisi sed scelerisque. Maecenas egetconvallis sapien. Mauris convallis sapien ut tellus condimentum volutpat. Nunc nec velit nisl, aliquet gravida felis.
Answer output:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque fringilla lacus ut diam laoreet fermentum.nUt ornare turpis vitae est auctor sit amet tincidunt nisi feugiat. Donec nec ligula ut nibh convallis mollisnsollicitudin et lacus. Phasellus odio erat, consectetur vitae dictum ac, varius consectetur dolor.nAenean pretium volutpat nisi vel laoreet. Nulla facilisi. Phasellus sed nisi nibh. Curabitur auctor erat vel arcunbibendum id auctor lacus fermentum. Suspendisse cursus volutpat feugiat. Suspendisse sed urna lectus,nmolestie fermentum augue.nDonec mauris diam, mattis quis posuere at, pharetra ac libero. Mauris a lacus id lorem tempus dapibus. Ut viverranimperdiet sapien, vel rhoncus mauris cursus eu. Donec bibendum feugiat ultrices. Vivamus facilisis nisi et lectusnEtiam id leo vitae nibh bibendum semper vel sed velit. Etiam tristique urna auctor arcu feugiat nec vehicula nequenvulputate. Pellentesque nunc leo, tincidunt sed dapibus sed, pulvinar nec nunc. Mauris vel urna vitae ipsum mattisncongue accumsan a tellus. Donec adipiscing arcu quis enim iaculis ut commodo nisl lacinia. Mauris turpis justo,ncongue quis sed urna. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.nMorbi sagittis tincidunt quam, ac tristique elit rhoncus id. In sem sem, tempus venenatis faucibus eu, dictum acncongue eu laoreet ac, porttitor non magna. Mauris imperdiet aliquam nisi sed scelerisque. Maecenas egetnconvallis sapien. Mauris convallis sapien ut tellus condimentum volutpat. Nunc nec velit nisl, aliquet gravida felis.```
If you notice, there is a "n" added at what is the first line break.
fringilla lacus ut diam laoreet fermentum.Ut ornare
fringilla lacus ut diam laoreet fermentum.nUt ornare
Notice the "n" inserted between the "." and "Ut ornare", this should not be here.
After switching to Groovy closure.
File file = new File("$prefix/exercise.txt")
file.filterLine(filteredResult) { String line ->
!line.startsWith('#')
}
The "n" is now present in both "result" and "answer". Unfortunately, though this now passes it is not correct, the "n" should not be there.
fringilla lacus ut diam laoreet fermentum.nUt ornare
fringilla lacus ut diam laoreet fermentum.nUt ornare
I am working on Groovy Koans via IntelliJ on a MacBook Pro. I have suspected that this may have something to do with line endings, but is an issue in either way.
Thanks for the detailed bug report. Please check if this fix worked for you!
Confirmed as working!
Standard output in test results now shows a multi-line output with no rogue "n".