This commit is contained in:
VicRen
2020-12-29 08:54:40 +08:00
parent f51292dc00
commit 6ed6173f36
2 changed files with 149 additions and 0 deletions

27
20201229/main.go Normal file
View File

@@ -0,0 +1,27 @@
package main
func main() {
}
func isEqual(s, t string) bool {
return process(s) == process(t)
}
func process(s string) string {
var ret []rune
for _, c := range s {
if string(c) == "#" {
if len(ret) > 0 {
ret = ret[:len(ret)-1]
}
continue
}
ret = append(ret, c)
}
return string(ret)
}
func process2(s string) string {
return ""
}

122
20201229/main_test.go Normal file
View File

@@ -0,0 +1,122 @@
package main
import "testing"
func Test_process(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
want string
}{
{
"test1",
args{"ab#c"},
"ac",
},
{
"test2",
args{"ad#c"},
"ac",
},
{
"test3",
args{"ab##"},
"",
},
{
"test4",
args{"c#d#"},
"",
},
{
"test5",
args{"a##c"},
"c",
},
{
"test6",
args{"#a#c"},
"c",
},
{
"test7",
args{"a#c"},
"c",
},
{
"test8",
args{"b"},
"b",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := process(tt.args.s); got != tt.want {
t.Errorf("process() = %v, want %v", got, tt.want)
}
})
}
}
func Test_isEqual(t *testing.T) {
type args struct {
s string
t string
}
tests := []struct {
name string
args args
want bool
}{
{
"test1",
args{
"ab#c",
"ad#c",
},
true,
},
{
"test2",
args{
"ab##",
"c#d#",
},
true,
},
{
"test3",
args{
"a##c",
"#a#c",
},
true,
},
{
"test3",
args{
"a#c",
"b",
},
false,
},
{
"test4",
args{
"ac##",
"a##",
},
true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isEqual(tt.args.s, tt.args.t); got != tt.want {
t.Errorf("isEqual() = %v, want %v", got, tt.want)
}
})
}
}