Ваше упражнение проверяется по этим тестам
1package solution
2
3import (
4 "github.com/stretchr/testify/assert"
5 "testing"
6)
7
8func TestCopyParent(t *testing.T) {
9 a := assert.New(t)
10
11 // nil case
12 cp := CopyParent(nil)
13 a.Equal(Parent{}, cp)
14
15 // filled struct case
16 p := &Parent{
17 Name: "Harry",
18 Children: []Child{
19 {
20 Name: "Andy",
21 Age: 18,
22 },
23 {
24 Name: "Vasya",
25 Age: 22,
26 },
27 },
28 }
29
30 cp = CopyParent(p)
31 cp.Children[0] = Child{}
32
33 a.Equal("Harry", cp.Name)
34 a.Equal("Harry", p.Name)
35 a.Len(p.Children, 2)
36 a.Len(cp.Children, 2)
37 a.Equal([]Child{
38 {
39 Name: "Andy",
40 Age: 18,
41 },
42 {
43 Name: "Vasya",
44 Age: 22,
45 },
46 }, p.Children)
47 a.Equal([]Child{
48 {},
49 {
50 Name: "Vasya",
51 Age: 22,
52 },
53 }, cp.Children)
54}
55
Решение учителя откроется через: