|
1 | 1 | using Sobol, Compat |
2 | 2 | using Compat.Test |
3 | 3 |
|
4 | | -# compare results with results from C++ code sobol.cc published on |
| 4 | +# compare results with results from C++ code sobol.cc published on |
5 | 5 | # http://web.maths.unsw.edu.au/~fkuo/sobol/ |
6 | 6 | # with new-joe-kuo-6.21201 file used as input. |
7 | 7 | # |
8 | | -# Command line used to generate output is |
| 8 | +# Command line used to generate output is |
9 | 9 | # ./sobol $N 1024 new-joe-kuo-6.21201 > exp_results_$N |
10 | 10 | # |
11 | 11 | # For each of the dimensions below |
12 | 12 | # (except 21201 where only 64 samples are generated) |
13 | 13 |
|
14 | | -dimensions = [5, 10, 20, 50, 100, 500, 21201] |
| 14 | +@testset "published results" begin |
| 15 | + dimensions = [5, 10, 20, 50, 100, 500, 21201] |
15 | 16 |
|
16 | | -for dim in dimensions |
17 | | - println("Testing dimension $(dim)") |
18 | | - open(joinpath(dirname(@__FILE__), "results", "exp_results_$(dim)")) do exp_results_file |
19 | | - s = SobolSeq(dim) |
20 | | - x = zeros(dim) |
21 | | - for line in eachline(exp_results_file) |
22 | | - values = [parse(Float64, item) for item in split(line)] |
23 | | - if length(values) > 0 |
24 | | - @test x == values |
25 | | - next!(s, x) |
| 17 | + for dim in dimensions |
| 18 | + println("Testing dimension $(dim)") |
| 19 | + open(joinpath(dirname(@__FILE__), "results", "exp_results_$(dim)")) do exp_results_file |
| 20 | + s = SobolSeq(dim) |
| 21 | + x = zeros(dim) |
| 22 | + for line in eachline(exp_results_file) |
| 23 | + values = [parse(Float64, item) for item in split(line)] |
| 24 | + if length(values) > 0 |
| 25 | + @test x == values |
| 26 | + next!(s, x) |
| 27 | + end |
26 | 28 | end |
27 | 29 | end |
28 | 30 | end |
29 | 31 | end |
30 | 32 |
|
31 | | -# issue #8 |
32 | 33 | using Base.Iterators: take |
33 | | -@test [x[1] for x in collect(take(Sobol.SobolSeq(1),5))] == [0.5,0.75,0.25,0.375,0.875] |
| 34 | +@testset "iterators" begin |
| 35 | + # issue #8 |
| 36 | + @test [x[1] for x in collect(take(Sobol.SobolSeq(1),5))] == [0.5,0.75,0.25,0.375,0.875] |
| 37 | +end |
| 38 | + |
| 39 | +@testset "scaled" begin |
| 40 | + # ScaledSobolSeq constructors |
| 41 | + lb = [-1,0,0] |
| 42 | + ub = [1,3,2] |
| 43 | + N = length(lb) |
| 44 | + s = SobolSeq(lb,ub) |
| 45 | + @test s isa ScaledSobolSeq{3} |
| 46 | + @test first(s) == [0,1.5,1] |
| 47 | + @test first(SobolSeq((x for x in lb), (x for x in ub))) == [0,1.5,1] |
| 48 | + @test SobolSeq(N,lb,ub) isa ScaledSobolSeq{3} |
| 49 | + @test_throws BoundsError SobolSeq(2,lb,ub) |
| 50 | +end |
0 commit comments