github.com/liucxer/courier@v1.7.1/h3/vec2d_test.go (about)

     1  package h3
     2  
     3  import (
     4  	"math"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func Test_v2dMag(t *testing.T) {
    11  	v := Vec2d{3.0, 4.0}
    12  
    13  	require.True(t, math.Abs(_v2dMag(&v)-5.0) < math.SmallestNonzeroFloat64, "magnitude as expected")
    14  }
    15  
    16  func Test_v2dIntersect(t *testing.T) {
    17  	p0 := Vec2d{2.0, 2.0}
    18  	p1 := Vec2d{6.0, 6.0}
    19  	p2 := Vec2d{0.0, 4.0}
    20  	p3 := Vec2d{10.0, 4.0}
    21  	intersection := Vec2d{0.0, 0.0}
    22  	_v2dIntersect(&p0, &p1, &p2, &p3, &intersection)
    23  
    24  	require.True(t, math.Abs(intersection.x-4.0) < math.SmallestNonzeroFloat64, "X coord as expected")
    25  	require.True(t, math.Abs(intersection.y-4.0) < math.SmallestNonzeroFloat64, "Y coord as expected")
    26  }
    27  
    28  func Test_v2dEquals(t *testing.T) {
    29  	v1 := Vec2d{3.0, 4.0}
    30  	v2 := Vec2d{3.0, 4.0}
    31  	v3 := Vec2d{3.5, 4.0}
    32  	v4 := Vec2d{3.0, 4.5}
    33  
    34  	require.True(t, _v2dEquals(&v1, &v2), "true for equal vectors")
    35  	require.True(t, !_v2dEquals(&v1, &v3), "false for different x")
    36  	require.True(t, !_v2dEquals(&v1, &v4), "false for different y")
    37  }