On 13/04/12 01:44, bearophile wrote:
final size_t select(ref UniformRNG urng)
in {
     assert(_recordsRemaining>  0);
     assert(_sampleRemaining>  0);
} body {
     ...
}

OK. I'm confused by these asserts, because if I go beyond what is acceptable by calling select() even after I've collected a complete sample, no error is thrown. e.g. if I put in place a function:

void sampling_test_simple(SamplerType, UniformRNG)
                         (size_t records, size_t samples, ref UniformRNG urng)
{
      auto s = new SamplerType(records,samples,urng);
      while(s.sampleRemaining > 0) {
            write("\trecord selected: ", s.select(urng), ".");
            write("\trecords remaining: ", s.recordsRemaining, ".");
            writeln("\tstill to sample: ", s.sampleRemaining, ".");
      }
      // Let's see if we can bust this ...

writeln("Selecting 1 more just for luck: ", s.select(urng), ", records remaining: ", s.recordsRemaining, ", still to sample: ", s.sampleRemaining); writeln("Selecting 1 more just for luck: ", s.select(urng), ", records remaining: ", s.recordsRemaining, ", still to sample: ", s.sampleRemaining); writeln("Selecting 1 more just for luck: ", s.select(urng), ", records remaining: ", s.recordsRemaining, ", still to sample: ", s.sampleRemaining); writeln("Selecting 1 more just for luck: ", s.select(urng), ", records remaining: ", s.recordsRemaining, ", still to sample: ", s.sampleRemaining); writeln("Selecting 1 more just for luck: ", s.select(urng), ", records remaining: ", s.recordsRemaining, ", still to sample: ", s.sampleRemaining); writeln("Selecting 1 more just for luck: ", s.select(urng), ", records remaining: ", s.recordsRemaining, ", still to sample: ", s.sampleRemaining); writeln("Selecting 1 more just for luck: ", s.select(urng), ", records remaining: ", s.recordsRemaining, ", still to sample: ", s.sampleRemaining); writeln("Selecting 1 more just for luck: ", s.select(urng), ", records remaining: ", s.recordsRemaining, ", still to sample: ", s.sampleRemaining); writeln("Selecting 1 more just for luck: ", s.select(urng), ", records remaining: ", s.recordsRemaining, ", still to sample: ", s.sampleRemaining);
}

(... see current GitHub code: https://github.com/WebDrake/SampleD )

It doesn't make any difference if I compile with -debug enabled:

   gdmd -debug -oftest sampled.d

Reply via email to