Hi Raj,
For example
--8<---------------cut here---------------start------------->8---
using StatsBase
using Base.Test
let seed = 9, n = 7
srand(seed)
@test StatsBase.samplepair(n) == (5,7)
end
--8<---------------cut here---------------end--------------->8---
ie you would call the function with a particular seed, then hardcode
that into the test. Note that this is very fragile: if the algorithm
changes, the random values would change too. For testing draws from
distributions etc, other methods exist (eg comparing a goodness of fit
statistic), but they have drawbacks too.
Best,
Tamas
On Mon, Mar 14 2016, RAJ Rohit Jalem wrote:
> Thank you for helping.
>
> Can you explain me in the context of writing a test for this function:
> https://github.com/JuliaStats/StatsBase.jl/blob/master/src/sampling.jl#L77-L81
>
> Can it be possible to write tests for this using the Base.Test package?
> How do I use srand() implementation for writing a test to this?
>
> Sorry for a lot of questions. Was trying to get my head around
> Base.Test!
>
> regards,
> Raj
>
>
>
>
>
> On Monday, March 14, 2016 at 5:07:29 PM UTC+5:30, Milan Bouchet-Valat wrote:
>>
>> Le lundi 14 mars 2016 à 04:19 -0700, RAJ Rohit Jalem a écrit :
>> > How do I test functions that return random values.
>> >
>> > For example, this function here: https://coveralls.io/builds/5402764/
>> > source?filename=src%2Fsampling.jl#L77
>> >
>> > Can it be done with the Base.Test package? If yes, then how?
>> Use srand() before calling them to ensure you always get the same
>> "random" value. For example, srand(1) will work.
>>
>>
>> Regards
>>