mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-30 16:58:44 +01:00
20201222
This commit is contained in:
@@ -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)
|
||||||
|
}
|
||||||
@@ -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