|
| 1 | +package v3 |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/google/go-cmp/cmp" |
| 5 | + "github.com/pdok/smooth-operator/model" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +func TestLayer_setInheritedBoundingBoxes(t *testing.T) { |
| 10 | + first28992BoundingBox := WMSBoundingBox{ |
| 11 | + CRS: "EPSG:28992", |
| 12 | + BBox: model.BBox{ |
| 13 | + MinX: "482.06", |
| 14 | + MaxX: "306602.42", |
| 15 | + MinY: "284182.97", |
| 16 | + MaxY: "637049.52", |
| 17 | + }, |
| 18 | + } |
| 19 | + first4326BoundingBox := WMSBoundingBox{ |
| 20 | + CRS: "EPSG:4326", |
| 21 | + BBox: model.BBox{ |
| 22 | + MinX: "2.35417303", |
| 23 | + MaxX: "7.5553525", |
| 24 | + MinY: "50.71447164", |
| 25 | + MaxY: "55.66948102", |
| 26 | + }, |
| 27 | + } |
| 28 | + first4258BoundingBox := WMSBoundingBox{ |
| 29 | + CRS: "EPSG:4258", |
| 30 | + BBox: model.BBox{ |
| 31 | + MinX: "2.354173", |
| 32 | + MaxX: "7.5553527", |
| 33 | + MinY: "50.71447", |
| 34 | + MaxY: "55.66948", |
| 35 | + }} |
| 36 | + second28992BoundingBox := WMSBoundingBox{ |
| 37 | + CRS: "EPSG:28992", |
| 38 | + BBox: model.BBox{ |
| 39 | + MinX: "0.00", |
| 40 | + MaxX: "310000.00", |
| 41 | + MinY: "275000.00", |
| 42 | + MaxY: "650000.00", |
| 43 | + }} |
| 44 | + |
| 45 | + tests := []struct { |
| 46 | + name string |
| 47 | + layer Layer |
| 48 | + toplayerExpectedBoundingBoxCount int |
| 49 | + toplayerExpectedBoundingBoxes []WMSBoundingBox |
| 50 | + grouplayer1ExpectedBoundingBoxCount int |
| 51 | + grouplayer1ExpectedBoundingBoxes []WMSBoundingBox |
| 52 | + datalayer1ExpectedBoundingBoxCount int |
| 53 | + datalayer1ExpectedBoundingBoxes []WMSBoundingBox |
| 54 | + datalayer2ExpectedBoundingBoxCount int |
| 55 | + datalayer2ExpectedBoundingBoxes []WMSBoundingBox |
| 56 | + }{ |
| 57 | + { |
| 58 | + name: "setInheritedBoundingBoxes for layer", |
| 59 | + layer: Layer{ |
| 60 | + Name: "toplayer", |
| 61 | + BoundingBoxes: []WMSBoundingBox{first28992BoundingBox}, |
| 62 | + Layers: &[]Layer{ |
| 63 | + { |
| 64 | + Name: "grouplayer-1", |
| 65 | + BoundingBoxes: []WMSBoundingBox{first4326BoundingBox}, |
| 66 | + Layers: &[]Layer{ |
| 67 | + { |
| 68 | + Name: "datalayer-1", |
| 69 | + BoundingBoxes: []WMSBoundingBox{first4258BoundingBox}, |
| 70 | + }, |
| 71 | + { |
| 72 | + Name: "datalayer-2", |
| 73 | + BoundingBoxes: []WMSBoundingBox{second28992BoundingBox}, |
| 74 | + }, |
| 75 | + }, |
| 76 | + }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + toplayerExpectedBoundingBoxCount: 1, |
| 80 | + toplayerExpectedBoundingBoxes: []WMSBoundingBox{first28992BoundingBox}, |
| 81 | + grouplayer1ExpectedBoundingBoxCount: 2, |
| 82 | + grouplayer1ExpectedBoundingBoxes: []WMSBoundingBox{first4326BoundingBox, first28992BoundingBox}, |
| 83 | + datalayer1ExpectedBoundingBoxCount: 3, |
| 84 | + datalayer1ExpectedBoundingBoxes: []WMSBoundingBox{first4258BoundingBox, first4326BoundingBox, first28992BoundingBox}, |
| 85 | + datalayer2ExpectedBoundingBoxCount: 2, |
| 86 | + datalayer2ExpectedBoundingBoxes: []WMSBoundingBox{second28992BoundingBox, first4326BoundingBox}, |
| 87 | + }, |
| 88 | + } |
| 89 | + for _, tt := range tests { |
| 90 | + t.Run(tt.name, func(t *testing.T) { |
| 91 | + layer := tt.layer |
| 92 | + layer.setInheritedBoundingBoxes() |
| 93 | + |
| 94 | + topChildLayers := *layer.Layers |
| 95 | + groupLayer1 := topChildLayers[0] |
| 96 | + groupChildLayers := *groupLayer1.Layers |
| 97 | + dataLayer1 := groupChildLayers[0] |
| 98 | + dataLayer2 := groupChildLayers[1] |
| 99 | + |
| 100 | + if len(layer.BoundingBoxes) != tt.toplayerExpectedBoundingBoxCount { |
| 101 | + t.Errorf("Toplayer has unexpected number of bounding boxes = %v, want %v", len(layer.BoundingBoxes), tt.toplayerExpectedBoundingBoxCount) |
| 102 | + } |
| 103 | + if !cmp.Equal(layer.BoundingBoxes, tt.toplayerExpectedBoundingBoxes) { |
| 104 | + t.Errorf("Toplayer has unexpected bounding boxes = %v, want %v", layer.BoundingBoxes, tt.toplayerExpectedBoundingBoxes) |
| 105 | + } |
| 106 | + if len(groupLayer1.BoundingBoxes) != tt.grouplayer1ExpectedBoundingBoxCount { |
| 107 | + t.Errorf("Grouplayer has unexpected number of bounding boxes = %v, want %v", len(groupLayer1.BoundingBoxes), tt.grouplayer1ExpectedBoundingBoxCount) |
| 108 | + } |
| 109 | + if !cmp.Equal(groupLayer1.BoundingBoxes, tt.grouplayer1ExpectedBoundingBoxes) { |
| 110 | + t.Errorf("Grouplayer has unexpected bounding boxes = %v, want %v", groupLayer1.BoundingBoxes, tt.grouplayer1ExpectedBoundingBoxes) |
| 111 | + } |
| 112 | + if len(dataLayer1.BoundingBoxes) != tt.datalayer1ExpectedBoundingBoxCount { |
| 113 | + t.Errorf("Datalayer1 has unexpected number of bounding boxes = %v, want %v", len(dataLayer1.BoundingBoxes), tt.datalayer1ExpectedBoundingBoxCount) |
| 114 | + } |
| 115 | + if !cmp.Equal(dataLayer1.BoundingBoxes, tt.datalayer1ExpectedBoundingBoxes) { |
| 116 | + t.Errorf("Datalayer1 has unexpected bounding boxes = %v, want %v", dataLayer1.BoundingBoxes, tt.datalayer1ExpectedBoundingBoxes) |
| 117 | + } |
| 118 | + if len(dataLayer2.BoundingBoxes) != tt.datalayer2ExpectedBoundingBoxCount { |
| 119 | + t.Errorf("Datalayer2 has unexpected number of bounding boxes = %v, want %v", len(dataLayer2.BoundingBoxes), tt.datalayer2ExpectedBoundingBoxCount) |
| 120 | + } |
| 121 | + if !cmp.Equal(dataLayer2.BoundingBoxes, tt.datalayer2ExpectedBoundingBoxes) { |
| 122 | + t.Errorf("Datalayer2 has unexpected bounding boxes = %v, want %v", dataLayer2.BoundingBoxes, tt.datalayer2ExpectedBoundingBoxes) |
| 123 | + } |
| 124 | + }) |
| 125 | + } |
| 126 | +} |
0 commit comments