Skip to content

Commit

Permalink
fix Delete func
Browse files Browse the repository at this point in the history
  • Loading branch information
baxiry committed Jun 29, 2024
1 parent 9b7e16f commit 22553ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions smap/smap.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ func (l *list) Get(k string) string {
return ""
}
func (l *list) Delete(k string) {
list := []kv{}

for i := 0; i < len(l.list); i++ {
if l.list[i].key == k {
l.list[i].val = ""
if l.list[i].key != k {
list = append(list, l.list[i])
}
}
l.list = list
}

func (l *list) Len() int {
return len(l.list)
}
4 changes: 2 additions & 2 deletions smap/smap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Test_Get(t *testing.T) {
func Test_Len(t *testing.T) {
if smp.Len() != len(cases) {
t.Errorf("have %d, want %d", smp.Len(), len(cases))
// t.Error(smp.list, cases)
//t.Error(smp.list, cases)
}
}

Expand Down Expand Up @@ -64,7 +64,7 @@ func Test_Delete(t *testing.T) {

func Test_Len3(t *testing.T) {
if smp.Len() >= len(cases) {
//t.Errorf("have %d, want %d", smp.Len(), len(cases)-1)
t.Errorf("have %d, want %d", smp.Len(), len(cases)-1)
// t.Error("\n", smp.list, "\n", cases)
}
}
Expand Down

0 comments on commit 22553ae

Please sign in to comment.