Changeset 2943 for trunk/test/rng-mt.cc


Ignore:
Timestamp:
Jan 4, 2013, 7:38:38 AM (9 years ago)
Author:
Peter
Message:

merge release 0.10 into trunk

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/test/rng-mt.cc

    r2881 r2943  
    22
    33/*
    4   Copyright (C) 2012 Peter Johansson
     4  Copyright (C) 2012, 2013 Peter Johansson
    55
    66  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    2929
    3030#include <algorithm>
     31#include <cstdlib>
    3132#include <iostream>
    3233#include <iterator>
     34#include <stdexcept>
    3335#include <vector>
    3436
     
    4446  void operator()(void)
    4547  {
    46     for (std::vector<int>::iterator i=begin_; i!=end_; ++i)
    47       *i = rnd_(100);
     48    try {
     49      for (std::vector<int>::iterator i=begin_; i!=end_; ++i)
     50        *i = rnd_(100);
     51    }
     52    catch (std::exception& e) {
     53      std::cerr << e.what() << "\n";
     54      exit(EXIT_FAILURE);
     55    }
    4856  }
    4957
     
    8795  suite.out() << "\ny: ";
    8896  std::copy(y.begin(), y.end(), std::ostream_iterator<int>(suite.out(), " "));
    89   suite.out() << "\n";
     97  suite.out() << std::endl;
    9098
    9199  if (x==y) {
     
    93101    suite.err() << "x and y are equal\n";
    94102  }
     103}
    95104
     105
     106std::vector<int> rnd_vec(void)
     107{
     108  std::vector<int> x(10);
     109  Visitor visitor1(x);
     110  boost::thread_group threads;
     111  threads.create_thread(visitor1);
     112  threads.join_all();
     113  return x;
    96114}
    97115
     
    102120  // test that we get same number with same seed
    103121  RNG::instance()->seed(0);
    104   std::vector<int> x(10);
    105   Visitor visitor1(x);
    106   boost::thread_group threads;
    107   threads.create_thread(visitor1);
    108   threads.join_all();
    109   std::vector<int> y(x);
     122  std::vector<int> y = rnd_vec();
     123  suite.out() << "y: ";
     124  std::copy(y.begin(), y.end(), std::ostream_iterator<int>(suite.out(), " "));
     125  suite.out() << std::endl;
     126
    110127  RNG::instance()->seed(0);
    111   threads.create_thread(visitor1);
    112   threads.join_all();
     128  std::vector<int> x = rnd_vec();
    113129  suite.out() << "x: ";
    114130  std::copy(x.begin(), x.end(), std::ostream_iterator<int>(suite.out(), " "));
    115   suite.out() << "\ny: ";
    116   std::copy(y.begin(), y.end(), std::ostream_iterator<int>(suite.out(), " "));
    117   suite.out() << "\n";
     131  suite.out() << std::endl;
    118132  if (x!=y) {
    119133    suite.add(false);
     
    135149  Visitor visitor(x);
    136150  visitor();
    137 
    138   std::vector<int> y(x);
    139   Visitor visitor1(y);
    140   boost::thread_group threads;
    141   threads.create_thread(visitor1);
    142   threads.join_all();
    143 
    144151  suite.out() << "x: ";
    145152  std::copy(x.begin(), x.end(), std::ostream_iterator<int>(suite.out(), " "));
    146   suite.out() << "\ny: ";
     153  suite.out() << std::endl;
     154
     155  std::vector<int> y = rnd_vec();
     156  suite.out() << "y: ";
    147157  std::copy(y.begin(), y.end(), std::ostream_iterator<int>(suite.out(), " "));
    148   suite.out() << "\n";
     158  suite.out() << std::endl;
    149159
    150160  if (x==y) {
Note: See TracChangeset for help on using the changeset viewer.