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

Function TestSin

math/sin_test.go:9–30  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestSin(t *testing.T) {
10 tests := []struct {
11 name string
12 n float64
13 want float64
14 }{
15 {"sin(0)", 0, 0},
16 {"sin(3π/2)", (3 * stdmath.Pi) / 2, -1},
17 {"sin(π/2)", stdmath.Pi / 2, 1},
18 {"sin(π/6)", stdmath.Pi / 6, 0.5},
19 {"sin(90)", 90, 0.893996663600558},
20 }
21 for _, test := range tests {
22 t.Run(test.name, func(t *testing.T) {
23 got := algmath.Sin(test.n)
24 if stdmath.Abs(got-test.want) >= epsilon {
25 t.Errorf("Sin() = %v, want %v", got, test.want)
26 t.Errorf("MATH Sin() = %v", stdmath.Sin(test.n))
27 }
28 })
29 }
30}
31
32func BenchmarkSin(b *testing.B) {
33 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected