go sqrtConst_test 源码
golang sqrtConst_test 代码
文件路径:/src/cmd/compile/internal/test/testdata/sqrtConst_test.go
// Copyright 2016 The Go 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 main
import (
"math"
"testing"
)
var tests = [...]struct {
name string
in float64 // used for error messages, not an input
got float64
want float64
}{
{"sqrt0", 0, math.Sqrt(0), 0},
{"sqrt1", 1, math.Sqrt(1), 1},
{"sqrt2", 2, math.Sqrt(2), math.Sqrt2},
{"sqrt4", 4, math.Sqrt(4), 2},
{"sqrt100", 100, math.Sqrt(100), 10},
{"sqrt101", 101, math.Sqrt(101), 10.04987562112089},
}
var nanTests = [...]struct {
name string
in float64 // used for error messages, not an input
got float64
}{
{"sqrtNaN", math.NaN(), math.Sqrt(math.NaN())},
{"sqrtNegative", -1, math.Sqrt(-1)},
{"sqrtNegInf", math.Inf(-1), math.Sqrt(math.Inf(-1))},
}
func TestSqrtConst(t *testing.T) {
for _, test := range tests {
if test.got != test.want {
t.Errorf("%s: math.Sqrt(%f): got %f, want %f\n", test.name, test.in, test.got, test.want)
}
}
for _, test := range nanTests {
if math.IsNaN(test.got) != true {
t.Errorf("%s: math.Sqrt(%f): got %f, want NaN\n", test.name, test.in, test.got)
}
}
if got := math.Sqrt(math.Inf(1)); !math.IsInf(got, 1) {
t.Errorf("math.Sqrt(+Inf), got %f, want +Inf\n", got)
}
}
相关信息
相关文章
0
赞
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦