github.com/15mga/kiwi@v0.0.2-0.20240324021231-b95d5c3ac751/util/vec_test.go (about)

     1  package util
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestRadian(t *testing.T) {
    11  	v1 := Vec2{3, 0}
    12  	for i := 0; i < 360; i++ {
    13  		d := float32(i)
    14  		if d > 180 {
    15  			d -= 360
    16  		}
    17  		r := DegreeToRadian(d)
    18  		v2 := Vec2Rotate(v1, r)
    19  		r1 := Vec2Radian(v1, v2)
    20  		r2 := Abs(Vec2ToRadian(v2))
    21  		assert.Truef(t, Equal(r1, r2), "r1:%f r2:%f", r1, r2)
    22  	}
    23  }
    24  
    25  func TestRadian2(t *testing.T) {
    26  	v1 := Vec2{3, 0}
    27  	for i := 0; i < 4; i++ {
    28  		r := DegreeToRadian(float32(i) * 90)
    29  		v2 := Vec2Rotate(v1, r)
    30  		r2 := Vec2Radian(v1, v2)
    31  		fmt.Printf("i:%d r:%f\n", i, r2)
    32  	}
    33  }
    34  
    35  func BenchmarkLower(b *testing.B) {
    36  	str := "2benchmark_2lower"
    37  	s := ToBigHump(str)
    38  	fmt.Println(s)
    39  	b.Run("2", func(b *testing.B) {
    40  		b.ReportAllocs()
    41  		for i := 0; i < b.N; i++ {
    42  			ToBigHump(str)
    43  		}
    44  	})
    45  	b.Run("3", func(b *testing.B) {
    46  		b.ReportAllocs()
    47  		for i := 0; i < b.N; i++ {
    48  			ToUnderline(s)
    49  		}
    50  	})
    51  }