mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 07:37:03 +08:00
unit: Update documentation, create examples, and comment types
Updates 90.
This commit is contained in:
29
unit/unitexample_test.go
Normal file
29
unit/unitexample_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright ©2017 The gonum Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package unit_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gonum.org/v1/gonum/unit"
|
||||
)
|
||||
|
||||
func ExampleNew() {
|
||||
// Create an acceleration of 3 m/s^2
|
||||
accel := unit.New(3.0, unit.Dimensions{unit.LengthDim: 1, unit.TimeDim: -2})
|
||||
fmt.Println(accel)
|
||||
|
||||
// Output: 3 m s^-2
|
||||
}
|
||||
|
||||
func ExampleNewDimension() {
|
||||
// Create a "trees" dimension
|
||||
// Typically, this should be used within an init function
|
||||
treeDim := unit.NewDimension("tree")
|
||||
countPerArea := unit.New(0.1, unit.Dimensions{treeDim: 1, unit.LengthDim: -2})
|
||||
fmt.Println(countPerArea)
|
||||
|
||||
// Output: 0.1 tree m^-2
|
||||
}
|
Reference in New Issue
Block a user