Skip to content

Commit 2b2f15c

Browse files
author
ANDO Yasushi
committed
add tests
1 parent 2e95cd2 commit 2b2f15c

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
go-glmatrix is a golang version of [glMatrix](http://glmatrix.net/), which is ``designed to perform vector and matrix operations stupidly fast''.
99

10-
# Usage
10+
## Usage
1111

1212
```go
1313
package main
@@ -24,11 +24,11 @@ func main() {
2424
}
2525
```
2626

27-
# Document
27+
## Document
2828

2929
- See [https://pkg.go.dev/](https://pkg.go.dev/github.com/technohippy/go-glmatrix)
3030
- or See [the documentation for glMatrix](http://glmatrix.net/docs/)
3131

32-
# License
32+
## License
3333

3434
MIT

quat2_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,37 @@ func TestQuat2Invert(t *testing.T) {
6464
}
6565
}
6666

67+
func TestQuat2SetReal(t *testing.T) {
68+
quat2A := []float64{
69+
1, 2, 3, 4,
70+
2, 5, 6, -2,
71+
}
72+
actual := Quat2SetReal(quat2A, []float64{4, 6, 8, -100})
73+
expect := []float64{4, 6, 8, -100, 2, 5, 6, -2}
74+
if !testSlice(actual, expect) {
75+
t.Errorf("set real: %v", actual)
76+
}
77+
}
78+
func TestQuat2SetDual(t *testing.T) {
79+
quat2A := []float64{
80+
1, 2, 3, 4,
81+
2, 5, 6, -2,
82+
}
83+
actual := Quat2SetDual(quat2A, []float64{4.3, 6, 8, -100})
84+
expect := []float64{1, 2, 3, 4, 4.3, 6, 8, -100}
85+
if !testSlice(actual, expect) {
86+
t.Errorf("set dual: %v", actual)
87+
}
88+
}
89+
90+
func TestQuat2Conjugate(t *testing.T) {
91+
actual := Quat2Conjugate(Quat2Create(), quat2A)
92+
expect := []float64{-1, -2, -3, 4, -2, -5, -6, -2}
93+
if !testSlice(actual, expect) {
94+
t.Errorf("conjugate: %v", actual)
95+
}
96+
}
97+
6798
func TestQuat2Multiply(t *testing.T) {
6899
actual := Quat2Create()
69100
Quat2Multiply(actual, quat2A, quat2B)
@@ -76,6 +107,14 @@ func TestQuat2Multiply(t *testing.T) {
76107
}
77108
}
78109

110+
func TestQuat2Lerp(t *testing.T) {
111+
actual := Quat2Lerp(Quat2Create(), quat2A, quat2B, 0.7)
112+
expect := []float64{3.8, 4.8, 5.8, 6.8, 6.9, 7.1, 6.0, -3.4}
113+
if !testSlice(actual, expect) {
114+
t.Errorf("lerp: %v", actual)
115+
}
116+
}
117+
79118
func TestQuat2Translate(t *testing.T) {
80119
quat2A := Quat2Normalize(Quat2Create(), quat2A)
81120
matrixA := Mat4FromQuat2(Mat4Create(), quat2A)
@@ -100,6 +139,19 @@ func TestQuat2Scale(t *testing.T) {
100139
}
101140
}
102141

142+
func TestQuat2Length(t *testing.T) {
143+
actual := Quat2Length(quat2A)
144+
expect := 5.477225
145+
if !equals(actual, expect) {
146+
t.Errorf("length: %v", actual)
147+
}
148+
149+
actual = Quat2Len(quat2A)
150+
if !equals(actual, expect) {
151+
t.Errorf("len: %v", actual)
152+
}
153+
}
154+
103155
/*
104156
func TestQuat2RotateX(t *testing.T) {
105157
quat2A := Quat2Normalize(Quat2Create(), quat2A)
@@ -142,6 +194,14 @@ func TestQuat2RotateZ(t *testing.T) {
142194
}
143195
*/
144196

197+
func TestQuat2FromRotationTranslationValues(t *testing.T) {
198+
actual := Quat2FromRotationTranslationValues(1, 2, 3, 4, 1, 2, 3)
199+
expect := []float64{1, 2, 3, 4, 2, 4, 6, -7}
200+
if !testSlice(actual, expect) {
201+
t.Errorf("from rotation toranslation values: %v", actual)
202+
}
203+
}
204+
145205
func TestQuat2GetTranslation(t *testing.T) {
146206
quat2A := Quat2FromTranslation(Quat2Create(), []float64{1, 2, 3})
147207
actual := Quat2GetTranslation(Vec3Create(), quat2A)

0 commit comments

Comments
 (0)