Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'util/random_test.cc')
-rw-r--r--util/random_test.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/util/random_test.cc b/util/random_test.cc
new file mode 100644
index 000000000..d1c555a0c
--- /dev/null
+++ b/util/random_test.cc
@@ -0,0 +1,39 @@
+#include "util/random.hh"
+
+#define BOOST_TEST_MODULE RandomTest
+#include <boost/test/unit_test.hpp>
+
+namespace util
+{
+namespace
+{
+
+BOOST_AUTO_TEST_CASE(returns_different_consecutive_numbers)
+{
+ rand_int_init(99);
+ const int first = rand_int(), second = rand_int(), third = rand_int();
+ // Sometimes you'll get the same number twice in a row, but generally the
+ // randomizer returns different numbers.
+ BOOST_CHECK(second != first || third != first);
+}
+
+BOOST_AUTO_TEST_CASE(returns_different_numbers_for_different_seeds)
+{
+ rand_int_init(1);
+ const int one1 = rand_int(), one2 = rand_int();
+ rand_int_init(2);
+ const int two1 = rand_int(), two2 = rand_int();
+ BOOST_CHECK(two1 != one1 || two2 != two1);
+}
+
+BOOST_AUTO_TEST_CASE(returns_same_sequence_for_same_seed)
+{
+ rand_int_init(1);
+ const int first = rand_int();
+ rand_int_init(1);
+ const int second = rand_int();
+ BOOST_CHECK_EQUAL(first, second);
+}
+
+} // namespace
+} // namespace util