|
|
|
@ -7,8 +7,7 @@ import ( |
|
|
|
|
|
|
|
|
|
func TestSplit(t *testing.T) { |
|
|
|
|
type args struct { |
|
|
|
|
code string |
|
|
|
|
length int |
|
|
|
|
code string |
|
|
|
|
} |
|
|
|
|
tests := []struct { |
|
|
|
|
name string |
|
|
|
@ -18,15 +17,28 @@ func TestSplit(t *testing.T) { |
|
|
|
|
{ |
|
|
|
|
name: "test1", |
|
|
|
|
args: args{ |
|
|
|
|
code: "A00001B00001C00001", |
|
|
|
|
length: 6, |
|
|
|
|
code: "A00001B00001C00001", |
|
|
|
|
}, |
|
|
|
|
wantRes: []string{"A00001B00001C00001", "A00001B00001", "A00001"}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "test2", |
|
|
|
|
args: args{ |
|
|
|
|
code: "A001", |
|
|
|
|
}, |
|
|
|
|
wantRes: []string{"A001"}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "test3", |
|
|
|
|
args: args{ |
|
|
|
|
code: "", |
|
|
|
|
}, |
|
|
|
|
wantRes: []string{}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
if gotRes := Split(tt.args.code, tt.args.length); !reflect.DeepEqual(gotRes, tt.wantRes) { |
|
|
|
|
if gotRes := Split(tt.args.code); !reflect.DeepEqual(gotRes, tt.wantRes) { |
|
|
|
|
t.Errorf("Split() = %v, want %v", gotRes, tt.wantRes) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
@ -110,3 +122,43 @@ func TestTree(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestLength(t *testing.T) { |
|
|
|
|
type args struct { |
|
|
|
|
code string |
|
|
|
|
} |
|
|
|
|
tests := []struct { |
|
|
|
|
name string |
|
|
|
|
args args |
|
|
|
|
want int |
|
|
|
|
}{ |
|
|
|
|
{ |
|
|
|
|
name: "test1", |
|
|
|
|
args: args{ |
|
|
|
|
code: "A00001B00001C00001", |
|
|
|
|
}, |
|
|
|
|
want: 6, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "test2", |
|
|
|
|
args: args{ |
|
|
|
|
code: "C0001D0001E00001", |
|
|
|
|
}, |
|
|
|
|
want: 5, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "test3", |
|
|
|
|
args: args{ |
|
|
|
|
code: "A0001", |
|
|
|
|
}, |
|
|
|
|
want: 5, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
if got := Length(tt.args.code); got != tt.want { |
|
|
|
|
t.Errorf("length() = %v, want %v", got, tt.want) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|