-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigamma_test.jule
More file actions
38 lines (34 loc) · 1.11 KB
/
digamma_test.jule
File metadata and controls
38 lines (34 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2025 mertcandav.
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.
use "std/math"
use "std/testing"
struct digammaTest {
x: f64
want: f64
}
// Results computed using WolframAlpha.
let testsDigamma: []digammaTest = [
{0.0, math::Inf(-1)},
{math::Copysign(0.0, -1.0), math::Inf(1)},
{math::Inf(1), math::Inf(1)},
{math::Inf(-1), math::NaN()},
{math::NaN(), math::NaN()},
{-1.0, math::NaN()},
{-100.5, 4.615124601338064117341315601525112558522917517910505881343},
{0.5, -1.96351002602142347944097633299875556719315960466043},
{10, 2.251752589066721107647456163885851537211808918028330369448},
{math::Pow10(20), 46.05170185988091368035482909368728415202202143924212618733},
{-1.111111111e9, math::NaN()},
{1.46, -0.001580561987083417676105544023567034348339520110000},
]
#test
fn testDigamma(t: &testing::T) {
for i, test in testsDigamma {
got := Digamma(test.x)
if !(math::IsNaN(got) && math::IsNaN(test.want)) &&
!Tolerance(got, test.want, 1e-7) {
t.Errorf("test {} Digamma({}) failed: got {} want {}", i, test.x, got, test.want)
}
}
}