Changeset 1538 for trunk


Ignore:
Timestamp:
Sep 27, 2008, 6:27:55 AM (13 years ago)
Author:
Peter
Message:

refs #368 - added several tests. Left now is to add specializations for trait classes.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/data_weight_proxy_test.cc

    r1537 r1538  
    3535      : proxy_(proxy) {}
    3636
     37    inline Proxy get_copy(void) { return proxy_; }
    3738    inline Proxy& operator()(void) { return proxy_; }
    3839    inline const Proxy& operator()(void) const
     
    9596  suite.add(suite.equal(xw3.weight(), 0.5));
    9697
     98  DataWeight xw4(1.602, 1);
     99  holder.get_copy() = xw4;
     100  suite.add(suite.equal(holder().data(), 1.602));
     101  suite.add(suite.equal(holder().weight(), 1));
     102
    97103  return suite.return_value();
    98104}
  • trunk/test/iterator_test.cc

    r1537 r1538  
    423423  test_bidirectional_iterator(iter, suite);
    424424  test_random_access_iterator(iter, suite);
    425   //std::vector<double> data(vec.size());
    426   //std::vector<double> weight(vec.size());
    427   //WIter iter2(data.begin(), weight.begin());
    428   //  std::copy(iter, iter+3, iter2);
    429   //suite.add(suite.equal(data.front(), 1));
    430 }
     425  std::vector<double> data(vec.size());
     426  std::vector<double> weight(vec.size());
     427  WIter iter2(data.begin(), weight.begin());
     428  utility::DataWeight tmp2(6.89, 0.79);
     429  *iter2 = tmp2;
     430  if (!suite.add(tmp2==*iter2))
     431    suite.err() << "error: tmp2==*iter2" << std::endl;
     432  utility::DataWeight tmp3(*iter2);
     433  suite.add(suite.equal(tmp3.data(), tmp2.data()));
     434  suite.add(suite.equal(tmp3.weight(), tmp2.weight()));
     435  *iter2 = *iter;
     436  if (!suite.add(*iter2 == *iter))
     437    suite.err() << "error: *iter2 == *iter\n";
     438  tmp = *iter2;
     439  suite.add(suite.equal(tmp.data(), 1));
     440  std::copy(iter, iter+3, iter2);
     441  suite.add(suite.equal(vec.front(), 1));
     442  suite.add(suite.equal(data.front(), 1));
     443
     444  suite.err() << "  testing const conversion\n";
     445  typedef std::vector<double>::const_iterator const_Iter;
     446  typedef utility::WeightedIterator<const_Iter, const_Iter> const_WIter;
     447  const_WIter const_iter(vec.begin(), vec.begin());
     448  const_iter = iter;
     449 
     450  suite.err() << "  testing assignment between different iterators\n";
     451  const std::vector<double> const_vec(10, 10.7);
     452  const_WIter const_iter2(const_vec.begin(), const_vec.begin());
     453  utility::DataWeight tmp4;
     454  tmp4 = *const_iter2;
     455  *iter = *const_iter2;
     456  suite.add(*iter==*const_iter2);
     457  *iter = *const_iter;
     458  suite.add(*iter==*const_iter);
     459
     460  double x=101;
     461  utility::WeightedIterator<double*, double*> iter_p(&x, &x);
     462  *iter_p = *iter;
     463  suite.add(*iter_p==*iter); 
     464}
  • trunk/yat/utility/DataWeightProxy.h

    r1537 r1538  
    5252       \return reference to data
    5353     */
     54    //typename std::iterator_traits<DataWeight>::reference data(void) const
    5455    double& data(void) { return *data_; }
    5556
     
    7273       \brief assignment operator
    7374     */
     75    DataWeightProxy& operator=(const DataWeightProxy& rhs)
     76    {
     77      data() = rhs.data();
     78      weight() = rhs.weight();
     79      return *this;
     80    }
     81
     82    /**
     83       \brief assignment operator
     84     */
    7485    DataWeightProxy& operator=(const DataWeight& rhs)
    7586    {
     
    8293       \brief Conversion to DataWeight
    8394     */
    84     operator DataWeight() const { return DataWeight(data(), weight()); }
     95    operator DataWeight() const
     96    { return DataWeight(this->data(), this->weight()); }
    8597
    8698  private:
  • trunk/yat/utility/WeightedIterator.h

    r1537 r1538  
    4141    : public boost::iterator_facade<
    4242    WeightedIterator<DataIterator, WeightIterator>,
    43     DataWeight,
     43    DataWeightProxy<DataIterator, WeightIterator>,
    4444    typename std::iterator_traits<DataIterator>::iterator_category,
    4545    DataWeightProxy<DataIterator, WeightIterator> >
     
    4747  {
    4848  public:
     49    /**
     50       \brief DataIterator
     51     */
     52    typedef DataIterator data_iterator_type;
     53
     54    /**
     55       \brief DataIterator
     56     */
     57    typedef WeightIterator weight_iterator_type;
     58
    4959    /**
    5060       \brief Constructor
     
    5464    {}
    5565   
     66    /**
     67       \return const reference to underlying data iterator
     68     */
     69    const DataIterator& data_base(void) const { return d_iter_; }
     70
     71    /**
     72       \return const reference to underlying weight iterator
     73     */
     74    const WeightIterator& weight_base(void) const { return w_iter_; }
    5675
    5776    /**
     
    7392       to const_iterator.
    7493     */
    75     /*
    7694    template<typename D2, typename W2>
    7795    WeightedIterator(WeightedIterator<D2, W2> other,
    7896            typename boost::enable_if_convertible<D2,DataIterator>::type* = 0,
    7997            typename boost::enable_if_convertible<W2,WeightIterator>::type* = 0)
    80     {}
    81     */
     98      : d_iter_(other.data_base()), w_iter_(other.weight_base()) {}
     99
    82100
    83101  private:
     
    98116    utility::DataWeightProxy<DataIterator, WeightIterator>
    99117    dereference(void) const
    100     {
    101       return DataWeightProxy<DataIterator, WeightIterator>(d_iter_,
     118    { return DataWeightProxy<DataIterator, WeightIterator>(d_iter_,
    102119                                                           w_iter_);
    103120    }
Note: See TracChangeset for help on using the changeset viewer.