mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 18:34:42 +01:00
20201222
This commit is contained in:
40
20201222/main.go
Normal file
40
20201222/main.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
||||
func isCompatible(a, b, c string) bool {
|
||||
if c == "" {
|
||||
return a == "" && b == ""
|
||||
}
|
||||
if len(c) != len(a)+len(b) {
|
||||
return false
|
||||
}
|
||||
var r []uint8
|
||||
l := -1
|
||||
var ra []uint8
|
||||
for i := 0; i < len(a); i++ {
|
||||
ca := a[i]
|
||||
for {
|
||||
l++
|
||||
cc := c[l]
|
||||
if cc == ca {
|
||||
ra = append(ra, ca)
|
||||
break
|
||||
}
|
||||
r = append(r, c[l])
|
||||
}
|
||||
}
|
||||
for i := l; i < len(c); i++ {
|
||||
r = append(r, c[i])
|
||||
}
|
||||
fmt.Println(string(ra))
|
||||
fmt.Println(string(r))
|
||||
return strings.Contains(string(r), b)
|
||||
}
|
||||
51
20201222/main_test.go
Normal file
51
20201222/main_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func Test_isCompatible(t *testing.T) {
|
||||
type args struct {
|
||||
a string
|
||||
b string
|
||||
c string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
"test1",
|
||||
args{
|
||||
"aabcc",
|
||||
"dbbca",
|
||||
"aadbbcbcac",
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"test2",
|
||||
args{
|
||||
"aabcc",
|
||||
"dbbca",
|
||||
"aadbbbaccc",
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"test3",
|
||||
args{
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
},
|
||||
true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := isCompatible(tt.args.a, tt.args.b, tt.args.c); got != tt.want {
|
||||
t.Errorf("isCompatible() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user