Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/386/go/src/cmd/compile/internal/gc/testdata/sqrtConst_test.go

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


// 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)
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].