v2 / vlib / v / tests / builtin_maps / complex_map_op_test.v
56 lines · 47 sloc · 1.2 KB · afc1f92d0a42d1e8bbdd09007825f6947955a53a
Raw
1fn test_complex_map_op1() {
2 mut test_map := map[string]Point_map{}
3
4 test_map['test1'] = Point_map{
5 points: {
6 'point3': []Point{}
7 }
8 }
9 test_map['test2'] = Point_map{
10 points: {
11 'point4': []Point{}
12 }
13 }
14 test_map['test1'].points['point3'] << Point{10, 20}
15 test_map['test2'].points['point4'] << Point{50, 60}
16
17 println(test_map)
18
19 assert test_map.len == 2
20 assert Point{10, 20} in test_map['test1'].points['point3']
21 assert Point{50, 60} in test_map['test2'].points['point4']
22 assert Point{10, 20} !in test_map['test2'].points['point4']
23 assert Point{1, 2} !in test_map['test1'].points['point3']
24}
25
26fn test_complex_map_op2() {
27 mut test_map := map[string]map[string][]Point{}
28
29 test_map['test1'] = {
30 'point3': []Point{}
31 }
32 test_map['test2'] = {
33 'point4': []Point{}
34 }
35 test_map['test1']['point3'] << Point{10, 20}
36 test_map['test2']['point4'] << Point{50, 60}
37
38 println(test_map)
39
40 assert test_map.len == 2
41 assert Point{10, 20} in test_map['test1']['point3']
42 assert Point{50, 60} in test_map['test2']['point4']
43 assert Point{10, 20} !in test_map['test2']['point4']
44 assert Point{1, 2} !in test_map['test1']['point3']
45}
46
47struct Point {
48mut:
49 x int
50 y int
51}
52
53struct Point_map {
54mut:
55 points map[string][]Point
56}
57