Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on what exactly you want to test. Next to Dirks recommendations, <code>svUnit</code> or the <code>RUnit</code> package VitoshKa mentioned, I'd like to add a few things :</p> <ul> <li>Indeed, set the seed, but make sure you try the function with different seeds as well. Some functions fail only once every ten times you try. Especially when optimization is involved, this becomes crucial. <code>replicate()</code> is a nice function to use in this context.</li> <li>Think very well about the input you want to test. You should test a number of "odd" cases that don't really resemble the "perfect" dataset. I always test at least 10 (simulated) datasets of different sizes. </li> <li>Fool-proof the function: I also throw in some data types that are not the ones the function is meant for. Wrong type input is likely going to happen at one point, and the last thing you want is a function returning a bogus result without a warning. If you use that function later on in some other code, debugging that code can and will! be hell. Been there, done that, bought the t-shirt...</li> </ul> <p>An example on extended testing of datasets: what would you like to see as output in these cases? Is this the result you'd expect? Not according to the test you did.</p> <pre><code>&gt; test3 &lt;- rep(12,100000) # data with only 1 value &gt; expected &lt;- c(12, 12, 12) &gt; actual &lt;- dtheta(test3) Error in quantile.default(x, qs) : 'probs' outside [0,1] &gt; test4 &lt;- rbinom(100000,30,0.5) # large dataset with a limited amount of values &gt; expected &lt;- quantile(test4,c(0.35, 0.50, 0.65)) &gt; actual &lt;- dtheta(test4) &gt; expected %in% signif(actual,2) [1] FALSE TRUE TRUE &gt; test5 &lt;- runif(100,0,100) # small dataset. &gt; expected &lt;- c(35, 50, 65) &gt; actual &lt;- dtheta(test5) &gt; expected %in% signif(actual,2) [1] FALSE FALSE FALSE </code></pre> <p>edit : corrected code so tests are a bit more senseful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload