@@ -4,6 +4,8 @@ module Test_utils
44using MultipleTesting
55using Test
66
7+ include (" utils.jl" )
8+
79
810@testset " Utility functions" begin
911
@@ -57,6 +59,29 @@ using Test
5759 end
5860
5961
62+ @testset " harmonic_number" begin
63+
64+ # Exact computation as reference
65+ harm_n_exact (n:: Integer ) = sum ([Rational (1 , i) for i in 1 : BigInt (n)])
66+
67+ n = [1 : 100 ; 200 : 200 : 1000 ; 10000 ]
68+
69+ max_d = 0.0
70+ for i in n
71+ hn1 = MultipleTesting. harmonic_number (i)
72+ hn2 = harm_n_exact (i)
73+ max_d = max (abs (hn1 - hn2), max_d)
74+ end
75+ # approximation error in the range of floating point inaccuracy
76+ @test max_d < (10 * eps ())
77+
78+ end
79+
80+ end
81+
82+
83+ @testset " Helper functions for testing" begin
84+
6085 @testset " unsort" begin
6186
6287 n = 20
@@ -65,8 +90,6 @@ using Test
6590 xu = xs[[1 : 2 : n - 1 ; 2 : 2 : n]] # unsorted
6691 @test ! issorted (xu)
6792
68- unsort = MultipleTesting. unsort
69-
7093 @test issorted (xs)
7194 @test ! issorted (unsort (xs))
7295
@@ -90,8 +113,6 @@ using Test
90113 xu = xs[[1 : 2 : n - 1 ; 2 : 2 : n]] # unsorted
91114 @test ! issorted (xu)
92115
93- unorder = MultipleTesting. unorder
94-
95116 @test issorted (xs)
96117 ord = unorder (xs)
97118 @test ! issorted (ord)
@@ -110,25 +131,6 @@ using Test
110131
111132 end
112133
113-
114- @testset " harmonic_number" begin
115-
116- # Exact computation as reference
117- harm_n_exact (n:: Integer ) = sum ([Rational (1 , i) for i in 1 : BigInt (n)])
118-
119- n = [1 : 100 ; 200 : 200 : 1000 ; 10000 ]
120-
121- max_d = 0.0
122- for i in n
123- hn1 = MultipleTesting. harmonic_number (i)
124- hn2 = harm_n_exact (i)
125- max_d = max (abs (hn1 - hn2), max_d)
126- end
127- # approximation error in the range of floating point inaccuracy
128- @test max_d < (10 * eps ())
129-
130- end
131-
132134end
133135
134136end
0 commit comments