Skip to content

Commit

Permalink
Ensure demo code in README.md stays up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
n8sh committed Dec 21, 2017
1 parent 6cccea3 commit 9347deb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import mir.random.algorithm: range;
void main(){
auto rng = Random(unpredictableSeed); // Engines are allocated on stack or global
auto sample = rng // Engines are passed by reference to algorithms
.range(NormalVariable!double(0, 1)) // Random variables are passed by value
auto sample = range!rng // Engines can passed by alias to algorithms
(NormalVariable!double(0, 1)) // Random variables are passed by value
.take(1000) // Fix sample length to 1000 elements (Input Range API)
.array; // Allocates memory and performs computation
Expand Down
19 changes: 19 additions & 0 deletions source/mir/random/algorithm.d
Original file line number Diff line number Diff line change
Expand Up @@ -804,3 +804,22 @@ nothrow @safe version(mir_random_test) unittest
sort(a);
assert(a == iota(10));
}

// Ensure that the demo code in README.md stays up to date.
// If this unittest needs to be updated due to a change, update
// README.md too!
nothrow @safe version(mir_random_test) unittest
{
import std.range;

import mir.random;
import mir.random.variable: NormalVariable;
import mir.random.algorithm: range;


auto rng = Random(unpredictableSeed); // Engines are allocated on stack or global
auto sample = range!rng // Engines can passed by alias to algorithms
(NormalVariable!double(0, 1)) // Random variables are passed by value
.take(1000) // Fix sample length to 1000 elements (Input Range API)
.array; // Allocates memory and performs computation
}

0 comments on commit 9347deb

Please sign in to comment.