Решение на Разлика в сумите от Габриела Грозева

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

Към профила на Габриела Грозева

Резултати

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

Код

package main
import (
"strings"
)
func ExtractLines(logContents string) []string {
a := logContents
arr := strings.Split(a, "\n")
return arr
}
func MakeArray(Line string) []string {
b := strings.Split(Line, " ")
arr := []string{Line[:19], b[2], strings.Join(b[3:], " ")}
return arr
}
func ExtractColumn(logContents string, column uint8) string {
lines := ExtractLines(logContents)
s := make([]string, 0)
for i := 0; i < len(lines)-1; i++ {
b := MakeArray(lines[i])
s = append(s, b[column])
}
return strings.Join(s, "\n") + "\n"
}

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

PASS
ok  	_/tmp/d20151103-24541-t54xu9	0.003s
PASS
ok  	_/tmp/d20151103-24541-t54xu9	0.003s
--- FAIL: TestWithEmptyLog (0.00s)
	solution_test.go:260: Expected
		---
		
		---
		but found
		---
		
		
		---
	solution_test.go:260: Expected
		---
		
		---
		but found
		---
		
		
		---
	solution_test.go:260: Expected
		---
		
		---
		but found
		---
		
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-t54xu9	0.003s
PASS
ok  	_/tmp/d20151103-24541-t54xu9	0.003s
--- FAIL: TestSpacesAtTheStartOrEndOfALine (0.00s)
	solution_test.go:260: Expected
		---
		2015-08-23 12:37:03
		2015-08-23 12:37:04
		2015-08-23 12:37:05
		2015-08-22 12:37:06
		0001-01-01 00:00:00
		
		---
		but found
		---
		2015-08-23 12:37:03
		2015-08-23 12:37:04
		2015-08-23 12:37:05
		2015-08-22 12:37:06
		
		---
	solution_test.go:260: Expected
		---
		8.8.8.8
		8.8.4.4
		208.122.23.23
		208.122.244.221
		255.255.255.255
		
		---
		but found
		---
		8.8.8.8
		8.8.4.4
		208.122.23.23
		208.122.244.221
		
		---
	solution_test.go:260: Expected
		---
		As far as we can tell this is a DNS
		Yet another DNS, how quaint!
		There is definitely some trend here
		 Some spaces at the beginning of this line
		Nothing particularly interesting happened 
		
		---
		but found
		---
		As far as we can tell this is a DNS
		Yet another DNS, how quaint!
		There is definitely some trend here
		 Some spaces at the beginning of this line
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-t54xu9	0.004s
--- FAIL: TestNoNewLineAtEndOfInput (0.00s)
	solution_test.go:260: Expected
		---
		As far as we can tell this is a DNS
		There is definitely some trend here
		
		---
		but found
		---
		As far as we can tell this is a DNS
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-t54xu9	0.003s
PASS
ok  	_/tmp/d20151103-24541-t54xu9	0.003s
--- FAIL: TestWithOnlyOneNewLine (0.00s)
	solution_test.go:253: There was a panic while testing: runtime error: slice bounds out of range
	solution_test.go:253: There was a panic while testing: runtime error: slice bounds out of range
	solution_test.go:253: There was a panic while testing: runtime error: slice bounds out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-t54xu9	0.003s
PASS
ok  	_/tmp/d20151103-24541-t54xu9	0.003s
PASS
ok  	_/tmp/d20151103-24541-t54xu9	0.003s
PASS
ok  	_/tmp/d20151103-24541-t54xu9	0.003s
--- FAIL: TestLogDoesNotEndInNewLine (0.00s)
	solution_test.go:260: Expected
		---
		8.8.8.8
		8.8.4.4
		208.122.23.23
		
		---
		but found
		---
		8.8.8.8
		8.8.4.4
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-t54xu9	0.003s
--- FAIL: TestLogLogLineEndsInIP (0.00s)
	solution_test.go:260: Expected
		---
		8.8.8.8
		8.8.4.4
		208.122.23.23
		
		---
		but found
		---
		8.8.8.8
		8.8.4.4
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-t54xu9	0.003s
--- FAIL: TestWithSpaces (0.00s)
	solution_test.go:260: Expected
		---
		spaces   tabs		end
		
		---
		but found
		---
		
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-t54xu9	0.004s
PASS
ok  	_/tmp/d20151103-24541-t54xu9	0.003s

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

Габриела обнови решението на 01.11.2015 21:34 (преди над 2 години)

+package main
+
+import (
+ "strings"
+)
+
+func ExtractLines(logContents string) []string {
+ a := logContents
+ arr := strings.Split(a, "\n")
+ return arr
+}
+
+func MakeArray(Line string) []string {
+ b := strings.Split(Line, " ")
+ arr := []string{Line[:19], b[2], strings.Join(b[3:], " ")}
+ return arr
+}
+
+func ExtractColumn(logContents string, column uint8) string {
+
+ lines := ExtractLines(logContents)
+ s := make([]string, 0)
+ for i := 0; i < len(lines)-1; i++ {
+ b := MakeArray(lines[i])
+ s = append(s, b[column])
+
+ }
+ return strings.Join(s, "\n") + "\n"
+}