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

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

Към профила на Ива Зарева

Резултати

  • 1 точка от тестове
  • 0 бонус точки
  • 1 точка общо
  • 1 успешни тест(а)
  • 14 неуспешни тест(а)

Код

//vtori opit, koito su6to ne minava testa...
package main
import (
"strings"
)
func ExtractColumn(logContents string, column uint8) string {
if len(logContents) == 0 {
return ""
}
lines := strings.Split(logContents, "\n")
var result string
switch {
case column == 0:
{
var str [10]string
for i, j := 0, 0; i < len(lines); i, j = i+1, j+3 {
var words = strings.Split(lines[i], " ")
str[j] = words[0] //za data
str[j+1] = words[1] //za chas
str[j+2] = "\n"
}
res := str[:]
result = strings.Join(res, " ")
}
case column == 1:
{
var str [10]string
for i, j := 0, 0; i < len(lines); i, j = i+1, j+1 {
var words = strings.Split(lines[i], " ")
str[j] = words[2] //za ip
}
res := str[:]
result = strings.Join(res, "\n")
}
case column == 2:
{
var str [10]string
for i, j := 0, 0; i < len(lines); i, j = i+1, j+2 {
var words = strings.Split(lines[i], " ")
temp := words[3:]
str[j] = strings.Join(temp, " ") //texta
str[j+1] = "\n"
}
res := str[:]
result = strings.Join(res, " ")
}
}
return result
}

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

--- 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-1tde8it	0.003s
--- 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: slice bounds out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1tde8it	0.003s
PASS
ok  	_/tmp/d20151103-24541-1tde8it	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-1tde8it	0.003s
--- FAIL: TestSpacesAtTheStartOrEndOfALine (0.00s)
	solution_test.go:253: There was a panic while testing: runtime error: index out of range
	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
		255.255.255.255
		
		
		
		
		
		---
	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 
		 Nothing particularly interesting happened  
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1tde8it	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 
		 There is definitely some trend here 
		      
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1tde8it	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: slice bounds out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1tde8it	0.003s
--- 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: slice bounds out of range
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1tde8it	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-1tde8it	0.004s
--- 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-1tde8it	0.003s
--- FAIL: TestExtractingTexts (0.00s)
	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-1tde8it	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
		208.122.23.23
		
		
		
		
		
		
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1tde8it	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
		208.122.23.23
		
		
		
		
		
		
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1tde8it	0.003s
--- FAIL: TestWithSpaces (0.00s)
	solution_test.go:260: Expected
		---
		spaces   tabs		end
		
		---
		but found
		---
		spaces   tabs		end 
		        
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1tde8it	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-1tde8it	0.003s

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

Ива обнови решението на 02.11.2015 10:39 (преди над 2 години)

+//ne minava testa i ne razbiram za6to...
+
+package main
+
+import (
+ "strings"
+)
+
+func ExtractColumn(logContents string, column uint8) string {
+ if len(logContents) == 0 {
+ return ""
+ }
+ lines := strings.Split(logContents, "\n")
+ var result string
+ switch {
+ case column == 0:
+ {
+ var str [100]string
+ for i, j := 0, 0; i < len(lines); i, j = i+1, j+3 {
+ var words = strings.Split(lines[i], " ")
+ str[j] = words[0] //za data
+ str[j+1] = words[1] //za chas
+ str[j+2] = "\n"
+ }
+ res := str[:]
+ result = strings.Join(res, " ")
+ }
+ case column == 1:
+ {
+
+ var str [100]string
+ for i, j := 0, 0; i < len(lines); i, j = i+1, 2 {
+ var words = strings.Split(lines[i], " ")
+ str[j] = words[3] //za ip
+ str[j+1] = "\n"
+ }
+ res := str[:]
+ result = strings.Join(res, " ")
+ }
+ case column == 2:
+ {
+ var str [100]string
+ for i, j := 0, 0; i < len(lines); i, j = i+1, j+2 {
+ var words = strings.Split(lines[i], " ")
+ temp := words[3:]
+ str[j] = strings.Join(temp, " ") //texta
+ str[j+1] = "\n"
+ }
+ res := str[:]
+ result = strings.Join(res, " ")
+ }
+ }
+ return result
+}

Ива обнови решението на 02.11.2015 22:32 (преди над 2 години)

-//ne minava testa i ne razbiram za6to...
+//vtori opit, koito su6to ne minava testa...
package main
import (
"strings"
)
func ExtractColumn(logContents string, column uint8) string {
if len(logContents) == 0 {
return ""
}
lines := strings.Split(logContents, "\n")
var result string
switch {
case column == 0:
{
- var str [100]string
+ var str [10]string
for i, j := 0, 0; i < len(lines); i, j = i+1, j+3 {
var words = strings.Split(lines[i], " ")
str[j] = words[0] //za data
str[j+1] = words[1] //za chas
str[j+2] = "\n"
}
res := str[:]
result = strings.Join(res, " ")
}
case column == 1:
{
- var str [100]string
- for i, j := 0, 0; i < len(lines); i, j = i+1, 2 {
+ var str [10]string
+ for i, j := 0, 0; i < len(lines); i, j = i+1, j+1 {
var words = strings.Split(lines[i], " ")
- str[j] = words[3] //za ip
- str[j+1] = "\n"
+ str[j] = words[2] //za ip
}
res := str[:]
- result = strings.Join(res, " ")
+ result = strings.Join(res, "\n")
}
case column == 2:
{
- var str [100]string
+ var str [10]string
for i, j := 0, 0; i < len(lines); i, j = i+1, j+2 {
var words = strings.Split(lines[i], " ")
temp := words[3:]
str[j] = strings.Join(temp, " ") //texta
str[j+1] = "\n"
}
res := str[:]
result = strings.Join(res, " ")
}
}
return result
}