MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestSquareRootCalculation

Function TestSquareRootCalculation

math/binary/sqrt_test.go:15–38  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13const epsilon = 0.001
14
15func TestSquareRootCalculation(t *testing.T) {
16 tests := []struct {
17 name string
18 number float32
19 want float64
20 }{
21 {"sqrt(1)", 1, 1},
22 {"sqrt(9)", 9, 3},
23 {"sqrt(25)", 25, 5},
24 {"sqrt(121)", 121, 11},
25 {"sqrt(10000)", 10000, 100},
26 {"sqrt(169)", 169, 13},
27 {"sqrt(0)", 0, 0},
28 }
29 for _, test := range tests {
30 t.Run(test.name, func(t *testing.T) {
31 got := Sqrt(test.number)
32 delta := math.Abs(test.want - float64(got))
33 if delta > epsilon {
34 t.Errorf("Sqrt() = %v, want %v delta %v", got, test.want, delta)
35 }
36 })
37 }
38}
39
40func BenchmarkSquareRootCalculation(b *testing.B) {
41 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls 1

SqrtFunction · 0.85

Tested by

no test coverage detected