...

Source file src/github.com/golang/geo/s2/edge_vector_shape_test_test.go

Documentation: github.com/golang/geo/s2

     1  // Copyright 2017 Google Inc. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package s2
    16  
    17  import (
    18  	"testing"
    19  )
    20  
    21  func TestEdgeVectorShapeEmpty(t *testing.T) {
    22  	var shape edgeVectorShape
    23  	if got, want := shape.NumEdges(), 0; got != want {
    24  		t.Errorf("shape.NumEdges() = %v, want %v", got, want)
    25  	}
    26  	if got, want := shape.NumChains(), 0; got != want {
    27  		t.Errorf("shape.NumChains() = %v, want %v", got, want)
    28  	}
    29  	if got, want := shape.Dimension(), 1; got != want {
    30  		t.Errorf("shape.Dimension() = %v, want %v", got, want)
    31  	}
    32  	if !shape.IsEmpty() {
    33  		t.Errorf("shape.IsEmpty() = false, want true")
    34  	}
    35  	if shape.IsFull() {
    36  		t.Errorf("shape.IsFull() = true, want false")
    37  	}
    38  	if shape.ReferencePoint().Contained {
    39  		t.Errorf("shape.ReferencePoint().Contained should be false")
    40  	}
    41  }
    42  
    43  func TestEdgeVectorShapeSingletonConstructor(t *testing.T) {
    44  	a := PointFromCoords(1, 0, 0)
    45  	b := PointFromCoords(0, 1, 0)
    46  
    47  	var shape Shape = edgeVectorShapeFromPoints(a, b)
    48  	if shape.NumEdges() != 1 {
    49  		t.Errorf("shape created from one edge should only have one edge, got %v", shape.NumEdges())
    50  	}
    51  	if shape.NumChains() != 1 {
    52  		t.Errorf("should only have one edge got %v", shape.NumChains())
    53  	}
    54  	edge := shape.Edge(0)
    55  
    56  	if edge.V0 != a {
    57  		t.Errorf("vertex 0 of the edge should be the same as was used to create it. got %v, want %v", edge.V0, a)
    58  	}
    59  	if edge.V1 != b {
    60  		t.Errorf("vertex 1 of the edge should be the same as was used to create it. got %v, want %v", edge.V1, b)
    61  	}
    62  	if shape.IsEmpty() {
    63  		t.Errorf("shape.IsEmpty() = true, want false")
    64  	}
    65  	if shape.IsFull() {
    66  		t.Errorf("shape.IsFull() = true, want false")
    67  	}
    68  }
    69  
    70  // TODO(roberts): TestEdgeVectorShapeEdgeAccess
    71  

View as plain text