Skip to content

Commit

Permalink
Bad decision of task centerFile (Attempt Kotlin-Polytech#2).
Browse files Browse the repository at this point in the history
  • Loading branch information
Iksburg committed Nov 14, 2020
1 parent c15dbbd commit d982f0d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions input/center_in3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
АБ -
8 changes: 5 additions & 3 deletions src/lesson7/task1/Files.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ fun centerFile(inputName: String, outputName: String) {
var lastIndexLine = 0
var lineCenter: Int
var newString: String
var newLine: String
for (line in File(inputName).readLines()) {
if (line.trim().length > maxLineLength) maxLineLength = line.trim().length
newLine = line.trim()
if (newLine.length > maxLineLength) maxLineLength = newLine.length
}
val maxLineCenter = (maxLineLength - 1) / 2
val maxLineCenter = maxLineLength / 2
for (line in File(inputName).readLines()) {
val newLine = line.trim()
newLine = line.trim()
for (i in newLine.indices) {
if (newLine[i] != ' ' && firstIndexLine == -1) {
firstIndexLine = i
Expand Down
5 changes: 5 additions & 0 deletions test/lesson7/task1/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ Basic, Ruby, Swift.
@Test
@Tag("15")
fun centerFile() {
centerFile("input/center_in3.txt", "temp.txt")
assertFileContent(
"temp.txt",
"""АБ -"""
)
centerFile("input/center_in2.txt", "temp.txt")
assertFileContent(
"temp.txt",
Expand Down

0 comments on commit d982f0d

Please sign in to comment.