mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 21:24:46 +01:00
20201212
This commit is contained in:
17
20201212/main.go
Normal file
17
20201212/main.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func compress(src []int) []int {
|
||||||
|
var ret []int
|
||||||
|
for i := 0; 2*i+1 < len(src); i++ {
|
||||||
|
freq := src[2*i]
|
||||||
|
val := src[2*i+1]
|
||||||
|
for j := 0; j < freq; j++ {
|
||||||
|
ret = append(ret, val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
39
20201212/main_test.go
Normal file
39
20201212/main_test.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_compress(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
src []int
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want []int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"test1",
|
||||||
|
args{
|
||||||
|
[]int{1, 2, 3, 4},
|
||||||
|
},
|
||||||
|
[]int{2, 4, 4, 4},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test2",
|
||||||
|
args{
|
||||||
|
[]int{1, 1, 2, 3},
|
||||||
|
},
|
||||||
|
[]int{1, 3, 3},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := compress(tt.args.src); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("compress() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user