mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 21:24:46 +01:00
20201229
This commit is contained in:
27
20201229/main.go
Normal file
27
20201229/main.go
Normal 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
122
20201229/main_test.go
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user