mirror of
https://github.com/gonum/gonum.git
synced 2025-10-17 12:40:52 +08:00
all: put examples into a xxx_test package clause
Fixes gonum/gonum#1395.
This commit is contained in:
@@ -2,9 +2,13 @@
|
||||
// Use of this code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package floats
|
||||
package floats_test
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gonum.org/v1/gonum/floats"
|
||||
)
|
||||
|
||||
// Set of examples for all the functions
|
||||
|
||||
@@ -14,12 +18,13 @@ func ExampleAdd_simple() {
|
||||
s1 := []float64{1, 2, 3, 4}
|
||||
s2 := []float64{5, 6, 7, 8}
|
||||
s3 := []float64{1, 1, 1, 1}
|
||||
Add(s1, s2)
|
||||
Add(s1, s3)
|
||||
floats.Add(s1, s2)
|
||||
floats.Add(s1, s3)
|
||||
|
||||
fmt.Println("s1 =", s1)
|
||||
fmt.Println("s2 =", s2)
|
||||
fmt.Println("s3 =", s3)
|
||||
|
||||
// Output:
|
||||
// s1 = [7 9 11 13]
|
||||
// s2 = [5 6 7 8]
|
||||
@@ -34,13 +39,14 @@ func ExampleAdd_newslice() {
|
||||
s3 := []float64{1, 1, 1, 1}
|
||||
dst := make([]float64, len(s1))
|
||||
|
||||
AddTo(dst, s1, s2)
|
||||
Add(dst, s3)
|
||||
floats.AddTo(dst, s1, s2)
|
||||
floats.Add(dst, s3)
|
||||
|
||||
fmt.Println("dst =", dst)
|
||||
fmt.Println("s1 =", s1)
|
||||
fmt.Println("s2 =", s2)
|
||||
fmt.Println("s3 =", s3)
|
||||
|
||||
// Output:
|
||||
// dst = [7 9 11 13]
|
||||
// s1 = [1 2 3 4]
|
||||
@@ -54,12 +60,13 @@ func ExampleAdd_unequallengths() {
|
||||
s1 := []float64{1, 2, 3}
|
||||
s2 := []float64{5, 6, 7, 8}
|
||||
|
||||
eq := EqualLengths(s1, s2)
|
||||
eq := floats.EqualLengths(s1, s2)
|
||||
if eq {
|
||||
Add(s1, s2)
|
||||
floats.Add(s1, s2)
|
||||
} else {
|
||||
fmt.Println("Unequal lengths")
|
||||
}
|
||||
|
||||
// Output:
|
||||
// Unequal lengths
|
||||
}
|
||||
@@ -68,9 +75,10 @@ func ExampleAddConst() {
|
||||
s := []float64{1, -2, 3, -4}
|
||||
c := 5.0
|
||||
|
||||
AddConst(c, s)
|
||||
floats.AddConst(c, s)
|
||||
|
||||
fmt.Println("s =", s)
|
||||
|
||||
// Output:
|
||||
// s = [6 3 8 1]
|
||||
}
|
||||
@@ -79,10 +87,11 @@ func ExampleCumProd() {
|
||||
s := []float64{1, -2, 3, -4}
|
||||
dst := make([]float64, len(s))
|
||||
|
||||
CumProd(dst, s)
|
||||
floats.CumProd(dst, s)
|
||||
|
||||
fmt.Println("dst =", dst)
|
||||
fmt.Println("s =", s)
|
||||
|
||||
// Output:
|
||||
// dst = [1 -2 -6 24]
|
||||
// s = [1 -2 3 -4]
|
||||
@@ -92,10 +101,11 @@ func ExampleCumSum() {
|
||||
s := []float64{1, -2, 3, -4}
|
||||
dst := make([]float64, len(s))
|
||||
|
||||
CumSum(dst, s)
|
||||
floats.CumSum(dst, s)
|
||||
|
||||
fmt.Println("dst =", dst)
|
||||
fmt.Println("s =", s)
|
||||
|
||||
// Output:
|
||||
// dst = [1 -1 2 -2]
|
||||
// s = [1 -2 3 -4]
|
||||
|
Reference in New Issue
Block a user