Решение на Piece table от Ива Милушева

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

Към профила на Ива Милушева

Резултати

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

Код

package main
type Editors struct {
origin bool
offset int
length int
}
type Editor interface {
// Insert text starting from given position.
Insert(position uint, text string) Editor
// Delete length items from offset.
Delete(offset, length uint) Editor
// Undo reverts latest change.
Undo() Editor
// Redo re-applies latest undone change.
Redo() Editor
// String returns complete representation of what a file looks
// like after all manipulations.
String() string
}
var origin []byte
var add []byte
var final []byte
func (editor Editors) String() string {
return string(origin[:len(origin)])
}
func NewEditor(str string) Editors {
origin = []byte(str)
add = []byte("")
final = origin
return Editors{origin: true, offset: 0, length: len(str)}
}
/*
func (editor Editors) Insert(position uint, text string) Editors {
lenn := position + uint(len(text))
add = []byte(text)
final = make([]byte, 0, int(lenn))
final = append(final[:position], append(add[:], final[lenn:]...)...)
return Editors{origin: false, offset: int(position), length: len(final) - len(text)}
}
*/
func (editor Editors) Delete(offset, length uint) Editors{
lenn := int(offset+length)
final = append(final[:offset], final[lenn:]...)
return Editors{origin: false, offset: len(origin), length: len(origin) - int(length)}
}

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

# _/tmp/d20181107-53-1cizeuw [_/tmp/d20181107-53-1cizeuw.test]
./solution_test.go:8:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:21:30: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:28:26: f.Undo undefined (type Editors has no field or method Undo)
./solution_test.go:30:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:31:39: f.Delete(2, 6).Undo undefined (type Editors has no field or method Undo)
./solution_test.go:35:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:44:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:51:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:60:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: NewEditor("Жълтата дюля беше щастлива и замръзна като гьон.").Delete(49, 3).Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: too many errors
FAIL	_/tmp/d20181107-53-1cizeuw [build failed]
# _/tmp/d20181107-53-1cizeuw [_/tmp/d20181107-53-1cizeuw.test]
./solution_test.go:8:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:21:30: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:28:26: f.Undo undefined (type Editors has no field or method Undo)
./solution_test.go:30:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:31:39: f.Delete(2, 6).Undo undefined (type Editors has no field or method Undo)
./solution_test.go:35:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:44:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:51:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:60:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: NewEditor("Жълтата дюля беше щастлива и замръзна като гьон.").Delete(49, 3).Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: too many errors
FAIL	_/tmp/d20181107-53-1cizeuw [build failed]
# _/tmp/d20181107-53-1cizeuw [_/tmp/d20181107-53-1cizeuw.test]
./solution_test.go:8:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:21:30: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:28:26: f.Undo undefined (type Editors has no field or method Undo)
./solution_test.go:30:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:31:39: f.Delete(2, 6).Undo undefined (type Editors has no field or method Undo)
./solution_test.go:35:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:44:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:51:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:60:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: NewEditor("Жълтата дюля беше щастлива и замръзна като гьон.").Delete(49, 3).Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: too many errors
FAIL	_/tmp/d20181107-53-1cizeuw [build failed]
# _/tmp/d20181107-53-1cizeuw [_/tmp/d20181107-53-1cizeuw.test]
./solution_test.go:8:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:21:30: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:28:26: f.Undo undefined (type Editors has no field or method Undo)
./solution_test.go:30:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:31:39: f.Delete(2, 6).Undo undefined (type Editors has no field or method Undo)
./solution_test.go:35:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:44:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:51:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:60:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: NewEditor("Жълтата дюля беше щастлива и замръзна като гьон.").Delete(49, 3).Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: too many errors
FAIL	_/tmp/d20181107-53-1cizeuw [build failed]
# _/tmp/d20181107-53-1cizeuw [_/tmp/d20181107-53-1cizeuw.test]
./solution_test.go:8:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:21:30: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:28:26: f.Undo undefined (type Editors has no field or method Undo)
./solution_test.go:30:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:31:39: f.Delete(2, 6).Undo undefined (type Editors has no field or method Undo)
./solution_test.go:35:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:44:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:51:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:60:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: NewEditor("Жълтата дюля беше щастлива и замръзна като гьон.").Delete(49, 3).Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: too many errors
FAIL	_/tmp/d20181107-53-1cizeuw [build failed]
# _/tmp/d20181107-53-1cizeuw [_/tmp/d20181107-53-1cizeuw.test]
./solution_test.go:8:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:21:30: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:28:26: f.Undo undefined (type Editors has no field or method Undo)
./solution_test.go:30:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:31:39: f.Delete(2, 6).Undo undefined (type Editors has no field or method Undo)
./solution_test.go:35:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:44:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:51:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:60:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: NewEditor("Жълтата дюля беше щастлива и замръзна като гьон.").Delete(49, 3).Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: too many errors
FAIL	_/tmp/d20181107-53-1cizeuw [build failed]
# _/tmp/d20181107-53-1cizeuw [_/tmp/d20181107-53-1cizeuw.test]
./solution_test.go:8:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:21:30: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:28:26: f.Undo undefined (type Editors has no field or method Undo)
./solution_test.go:30:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:31:39: f.Delete(2, 6).Undo undefined (type Editors has no field or method Undo)
./solution_test.go:35:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:44:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:51:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:60:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: NewEditor("Жълтата дюля беше щастлива и замръзна като гьон.").Delete(49, 3).Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: too many errors
FAIL	_/tmp/d20181107-53-1cizeuw [build failed]
# _/tmp/d20181107-53-1cizeuw [_/tmp/d20181107-53-1cizeuw.test]
./solution_test.go:8:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:21:30: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:28:26: f.Undo undefined (type Editors has no field or method Undo)
./solution_test.go:30:7: f.Insert undefined (type Editors has no field or method Insert)
./solution_test.go:31:39: f.Delete(2, 6).Undo undefined (type Editors has no field or method Undo)
./solution_test.go:35:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:44:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:51:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:60:43: NewEditor("A large span of text").Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: NewEditor("Жълтата дюля беше щастлива и замръзна като гьон.").Delete(49, 3).Insert undefined (type Editors has no field or method Insert)
./solution_test.go:68:16: too many errors
FAIL	_/tmp/d20181107-53-1cizeuw [build failed]

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

Ива обнови решението на 07.11.2018 16:55 (преди 9 месеца)

+package main
+
+type Editors struct {
+ origin bool
+ offset int
+ length int
+}
+
+type Editor interface {
+
+ // Insert text starting from given position.
+ Insert(position uint, text string) Editor
+
+ // Delete length items from offset.
+ Delete(offset, length uint) Editor
+
+ // Undo reverts latest change.
+ Undo() Editor
+
+ // Redo re-applies latest undone change.
+ Redo() Editor
+
+ // String returns complete representation of what a file looks
+ // like after all manipulations.
+ String() string
+}
+
+var origin []byte
+var add []byte
+var final []byte
+
+func (editor Editors) String() string {
+
+return string(origin[:len(origin)])
+
+}
+
+func NewEditor(str string) Editors {
+
+origin = []byte(str)
+add = []byte("")
+final = origin
+return Editors{origin: true, offset: 0, length: len(str)}
+}
+
+/*
+func (editor Editors) Insert(position uint, text string) Editors {
+
+
+lenn := position + uint(len(text))
+add = []byte(text)
+final = make([]byte, 0, int(lenn))
+
+final = append(final[:position], append(add[:], final[lenn:]...)...)
+
+return Editors{origin: false, offset: int(position), length: len(final) - len(text)}
+}
+*/
+func (editor Editors) Delete(offset, length uint) Editors{
+
+lenn := int(offset+length)
+final = append(final[:offset], final[lenn:]...)
+return Editors{origin: false, offset: len(origin), length: len(origin) - int(length)}
+
+}