Решение на Разлика в сумите от Стефани Стоянова

Обратно към всички решения

Към профила на Стефани Стоянова

Резултати

  • 3 точки от тестове
  • 0 бонус точки
  • 3 точки общо
  • 5 успешни тест(а)
  • 10 неуспешни тест(а)

Код

package main
import "strings"
func ExtractColumn(logContents string, column uint8) string {
lines := strings.Split(logContents, "\n")
var result string
for _, line := range lines {
if column == 0 {
result += strings.SplitN(line, " ", 4)[column] + " "
}
result += strings.SplitN(line, " ", 4)[column+1]
result += "\n"
}
return result
}
func main() {
}

Лог от изпълнението

--- FAIL: TestWithTheExampleTest (0.00s)
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-h599pi	0.014s
--- FAIL: TestDifferentColumns (0.00s)
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-h599pi	0.003s
--- FAIL: TestWithEmptyLog (0.00s)
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-h599pi	0.003s
--- FAIL: TestWithOneLiner (0.00s)
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-h599pi	0.004s
PASS
ok  	_/tmp/d20151103-24541-h599pi	0.003s
PASS
ok  	_/tmp/d20151103-24541-h599pi	0.003s
--- FAIL: TestIPOrDateAtTheEndOfALine (0.00s)
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-h599pi	0.004s
--- FAIL: TestWithOnlyOneNewLine (0.00s)
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-h599pi	0.003s
--- FAIL: TestExtractingIPs (0.00s)
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-h599pi	0.003s
--- FAIL: TestExtractingTimes (0.00s)
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-h599pi	0.003s
--- FAIL: TestExtractingTexts (0.00s)
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-h599pi	0.003s
PASS
ok  	_/tmp/d20151103-24541-h599pi	0.003s
PASS
ok  	_/tmp/d20151103-24541-h599pi	0.003s
PASS
ok  	_/tmp/d20151103-24541-h599pi	0.003s
--- FAIL: TestMoreLinesThanExample (0.00s)
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-h599pi	0.003s

История (1 версия и 0 коментара)

Стефани обнови решението на 03.11.2015 14:41 (преди над 2 години)

+package main
+
+import "strings"
+
+func ExtractColumn(logContents string, column uint8) string {
+ lines := strings.Split(logContents, "\n")
+
+ var result string
+
+ for _, line := range lines {
+ if column == 0 {
+ result += strings.SplitN(line, " ", 4)[column] + " "
+ }
+ result += strings.SplitN(line, " ", 4)[column+1]
+ result += "\n"
+ }
+
+ return result
+}
+
+func main() {
+
+}