text:
#include "knowledge_of_valid_opening.h"
#include <NTL/GF2X.h>
#include <utils/utils.h>
#include <hamming/jain_commitment/jain_commitment.h>

void hamming_metric::knowledge_of_valid_opening::generate_public_key(
        public_key_t * public_key,
        const private_key_t *private_key) {

    NTL::vec_GF2 r;
    utils::generate_random_binary_matrix(
            public_key->A,
            JAIN_K,
            JAIN_L + JAIN_V);

    utils::generate_random_binary_vector(
            r,
            JAIN_L);

    hamming_metric::commitment::generate_commitment(
            public_key->commitment,
            public_key->A,
            r,
            private_key->m,
            private_key->e);
}

void hamming_metric::knowledge_of_valid_opening::generate_private_key(
        private_key_t * private_key) {

    private_key->e.kill();
    private_key->m.kill();

    utils::generate_random_binary_vector(
            private_key->m,
            JAIN_V);

    utils::generate_vector_of_weight_w(
            private_key->e,
            JAIN_K,
            W);
}

void hamming_metric::knowledge_of_valid_opening::generate_random_values(
        random_values_t *random_values) {

    ::utils::generate_random_binary_vector(
            random_values->v,
            JAIN_L + JAIN_V);

    ::utils::generate_random_binary_vector(
            random_values->f,
            JAIN_K);
}

void hamming_metric::knowledge_of_valid_opening::generate_revealed_values(
        revealed_values_t *revealed_values) {

    utils::create_permutation_matrix(
            revealed_values->P,
            JAIN_K);
}

void hamming_metric::knowledge_of_valid_opening::generate_commitments_and_responses(
        responses_t *responses,
        commitments_t *commitments,
        const random_values_t *random_values,
        const revealed_values_t *revealed_values,
        const public_key_t *public_key,
        const private_key_t *private_key) {

    ::hamming_metric::knowledge_of_valid_opening::generate_commitment_and_response_0(
            commitments->c0,
            commitments->r0,
            responses->t0,
            random_values->v,
            public_key->A,
            random_values->f);

    ::hamming_metric::knowledge_of_valid_opening::generate_commitment_and_response_1(
            commitments->c1,
            commitments->r1,
            responses->t1,
            public_key->A,
            revealed_values->P,
            random_values->f);

    ::hamming_metric::knowledge_of_valid_opening::generate_commitment_and_response_2(
            commitments->c2,
            commitments->r2,
            responses->t2,
            public_key->A,
            revealed_values->P,
            random_values->f,
            private_key->e);
}

void hamming_metric::knowledge_of_valid_opening::encode(
        NTL::vec_GF2 &out,
        const NTL::vec_GF2 &v) {

    out = utils::encode_binary_vector(v, JAIN_V);
}

void hamming_metric::knowledge_of_valid_opening::commit(
        NTL::vec_GF2 &c,
        NTL::vec_GF2 &r,
        const NTL::vec_GF2 &v,
        const NTL::mat_GF2 &A) {

    utils::generate_random_binary_vector(
            r,
            JAIN_L);

    hamming_metric::commitment::generate_commitment(
            c,
            A,
            r,
            v);
}

void hamming_metric::knowledge_of_valid_opening::generate_response_0(
        NTL::vec_GF2 &t0,
        const NTL::vec_GF2 &n,
        const NTL::mat_GF2 &A,
        const NTL::vec_GF2 &f) {

    t0 = (A * n) + f;
}

void hamming_metric::knowledge_of_valid_opening::generate_commitment_and_response_0(
        NTL::vec_GF2 &c0,
        NTL::vec_GF2 &r0,
        NTL::vec_GF2 &t0,
        const NTL::vec_GF2 &n,
        const NTL::mat_GF2 &A,
        const NTL::vec_GF2 &f) {

    generate_response_0(
            t0,
            n,
            A,
            f);

    NTL::vec_GF2 encoded;
    encode(
            encoded,
            t0);

    commit(
            c0,
            r0,
            encoded,
            A);

}

void hamming_metric::knowledge_of_valid_opening::generate_response_1(
        NTL::vec_GF2 &t1,
        const NTL::mat_GF2 &P,
        const NTL::vec_GF2 &f) {

    t1 = P * f;
}

void hamming_metric::knowledge_of_valid_opening::generate_commitment_and_response_1(
        NTL::vec_GF2 &c1,
        NTL::vec_GF2 &r1,
        NTL::vec_GF2 &t1,
        const NTL::mat_GF2 &A,
        const NTL::mat_GF2 &P,
        const NTL::vec_GF2 &f) {

    generate_response_1(
            t1,
            P,
            f);

    NTL::vec_GF2 encoded;
    encode(
            encoded,
           t1);

    commit(
            c1,
           r1,
           encoded,
           A);
}

void hamming_metric::knowledge_of_valid_opening::generate_response_2(
        NTL::vec_GF2 &t2,
        const NTL::mat_GF2 &P,
        const NTL::vec_GF2 &f,
        const NTL::vec_GF2 &e) {

    t2 = P * (f + e);
}

void hamming_metric::knowledge_of_valid_opening::generate_commitment_and_response_2(
        NTL::vec_GF2 &c2,
        NTL::vec_GF2 &r2,
        NTL::vec_GF2 &t2,
        const NTL::mat_GF2 &A,
        const NTL::mat_GF2 &P,
        const NTL::vec_GF2 &f,
        const NTL::vec_GF2 &e) {

    generate_response_2(
            t2,
            P,
            f,
            e);

    NTL::vec_GF2 encoded;
    encode(
            encoded,
           t2);

    commit(
            c2,
           r2,
           encoded,
           A);
}

int hamming_metric::knowledge_of_valid_opening::verify_0(
        const NTL::vec_GF2 &c0,
        const NTL::vec_GF2 &r0,
        const NTL::vec_GF2 &t0,
        const NTL::vec_GF2 &c1,
        const NTL::vec_GF2 &r1,
        const NTL::vec_GF2 &t1,
        const NTL::mat_GF2 &P,
        const public_key_t *public_key) {

    auto _t0 = utils::encode_binary_vector(t0, JAIN_V);
    auto _t1 = utils::encode_binary_vector(t1, JAIN_V);

    if (hamming_metric::commitment::verify(
            c0,
            public_key->A,
            r0,
            _t0) != 0) {
        std::cout << "Knowledge of valid opening. Verification failed on ch = 0 and c0" << std::endl;
        return 1;
    }

    if (hamming_metric::commitment::verify(
            c1,
            public_key->A,
            r1,
            _t1) != 0) {
        std::cout << "Knowledge of valid opening. Verification failed on ch = 0 and c1" << std::endl;
        return 1;
    }

    auto sum = t0 + (NTL::inv(P) * t1);

    NTL::vec_GF2 result;
    if(utils::solve_equation(
            result,
            public_key->A,
            sum) != 0) {
        std::cout << "No solutions" << std::endl;
        return 1;
    }

    return 0;
}

int hamming_metric::knowledge_of_valid_opening::verify_1(
        const NTL::vec_GF2 &c0,
        const NTL::vec_GF2 &r0,
        const NTL::vec_GF2 &t0,
        const NTL::vec_GF2 &c2,
        const NTL::vec_GF2 &r2,
        const NTL::vec_GF2 &t2,
        const NTL::mat_GF2 &P,
        const public_key_t *public_key) {

    auto _t0 = utils::encode_binary_vector(t0, JAIN_V);
    auto _t2 = utils::encode_binary_vector(t2, JAIN_V);

    if (hamming_metric::commitment::verify(
            c0,
            public_key->A,
            r0,
            _t0) != 0) {
        std::cout << "Knowledge of valid opening. Verification failed on ch = 1 and c0" << std::endl;
        return 1;
    }

    if (hamming_metric::commitment::verify(
            c2,
            public_key->A,
            r2,
            _t2) != 0) {
        std::cout << "Knowledge of valid opening. Verification failed on ch = 1 and c2" << std::endl;
        return 1;
    }

    auto sum = t0 + public_key->commitment + (NTL::inv(P) * t2);

    NTL::vec_GF2 result;
    if(utils::solve_equation(
            result,
            public_key->A,
            sum) != 0) {
        std::cout << "No solutions" << std::endl;
        return 1;
    }

    return 0;
}

int hamming_metric::knowledge_of_valid_opening::verify_2(
        const NTL::vec_GF2 &c1,
        const NTL::vec_GF2 &r1,
        const NTL::vec_GF2 &t1,
        const NTL::vec_GF2 &c2,
        const NTL::vec_GF2 &r2,
        const NTL::vec_GF2 &t2,
        const public_key_t *public_key) {

    auto _t1 = utils::encode_binary_vector(t1, JAIN_V);
    auto _t2 = utils::encode_binary_vector(t2, JAIN_V);

    if (hamming_metric::commitment::verify(
            c1,
            public_key->A,
            r1,
            _t1) != 0) {
        std::cout << "Knowledge of valid opening. Verification failed on ch = 2 and c1" << std::endl;
        return 1;
    }

    if (hamming_metric::commitment::verify(
            c2,
            public_key->A,
            r2,
            _t2) != 0) {
        std::cout << "Knowledge of valid opening. Verification failed on ch = 2 and c2" << std::endl;
        return 1;
    }

    if (NTL::weight(t1 + t2) != W) {
        return 1;
    }

    return 0;
}


text:
////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/container for documentation.
//
////////////////////////////////////////

#ifndef BOOST_CONTAINER_TEST_LIST_TEST_HEADER
#define BOOST_CONTAINER_TEST_LIST_TEST_HEADER

#include <boost/container/detail/config_begin.hpp>
#include "check_equal_containers.hpp"
#include <memory>
#include <list>
#include <vector>
#include <functional>
#include "print_container.hpp"
#include <boost/move/move.hpp>
#include <string>

namespace boost{
namespace container {
namespace test{

template<bool DoublyLinked>
struct push_data_function
{
   template<class MyShmList, class MyStdList>
   static int execute(int max, MyShmList *shmlist, MyStdList *stdlist)
   {
      typedef typename MyShmList::value_type IntType;
      for(int i = 0; i < max; ++i){
         IntType move_me(i);
         shmlist->push_back(boost::move(move_me));
         stdlist->push_back(i);
      }
      if(!CheckEqualContainers(shmlist, stdlist))
         return 1;
      return 0;
   }
};

template<>
struct push_data_function<false>
{
   template<class MyShmList, class MyStdList>
   static int execute(int max, MyShmList *shmlist, MyStdList *stdlist)
   {
      typedef typename MyShmList::value_type IntType;
      for(int i = 0; i < max; ++i){
         IntType move_me(i);
         shmlist->push_front(boost::move(move_me));
         stdlist->push_front(i);
      }
      if(!CheckEqualContainers(shmlist, stdlist))
         return 1;
      return 0;
   }
};

template<bool DoublyLinked>
struct pop_back_function
{
   template<class MyStdList, class MyShmList>
   static int execute(MyShmList *shmlist, MyStdList *stdlist)
   {
      shmlist->pop_back();
      stdlist->pop_back();
      if(!CheckEqualContainers(shmlist, stdlist))
         return 1;
      return 0;
   }
};

template<>
struct pop_back_function<false>
{
   template<class MyStdList, class MyShmList>
   static int execute(MyShmList *shmlist, MyStdList *stdlist)
   {
      (void)shmlist; (void)stdlist;
      return 0;
   }
};

template<class MyShmList
        ,bool  DoublyLinked>
int list_test (bool copied_allocators_equal = true)
{
   typedef std::list<int> MyStdList;
   typedef typename MyShmList::value_type IntType;
   const int max = 100;
   typedef push_data_function<DoublyLinked> push_data_t;

   try{
      MyShmList *shmlist = new MyShmList;
      MyStdList *stdlist = new MyStdList;

      if(push_data_t::execute(max, shmlist, stdlist)){
         return 1;
      }

      shmlist->erase(shmlist->begin()++);
      stdlist->erase(stdlist->begin()++);
      if(!CheckEqualContainers(shmlist, stdlist)) return 1;

      if(pop_back_function<DoublyLinked>::execute(shmlist, stdlist)){
         return 1;
      }

      shmlist->pop_front();
      stdlist->pop_front();
      if(!CheckEqualContainers(shmlist, stdlist)) return 1;

      {
         IntType aux_vect[50];
         for(int i = 0; i < 50; ++i){
            IntType move_me(-1);
            aux_vect[i] = boost::move(move_me);
         }
         int aux_vect2[50];
         for(int i = 0; i < 50; ++i){
            aux_vect2[i] = -1;
         }
         shmlist->assign(boost::make_move_iterator(&aux_vect[0])
                        ,boost::make_move_iterator(&aux_vect[50]));
         stdlist->assign(&aux_vect2[0], &aux_vect2[50]);
         if(!CheckEqualContainers(shmlist, stdlist)) return 1;
      }

      if(copied_allocators_equal){
         shmlist->sort();
         stdlist->sort();
         if(!CheckEqualContainers(shmlist, stdlist)) return 1;
      }

      shmlist->reverse();
      stdlist->reverse();
      if(!CheckEqualContainers(shmlist, stdlist)) return 1;

      shmlist->reverse();
      stdlist->reverse();
      if(!CheckEqualContainers(shmlist, stdlist)) return 1;

      {
         IntType aux_vect[50];
         for(int i = 0; i < 50; ++i){
            IntType move_me(-1);
            aux_vect[i] = boost::move(move_me);
         }
         int aux_vect2[50];
         for(int i = 0; i < 50; ++i){
            aux_vect2[i] = -1;
         }
         shmlist->insert(shmlist->begin()
                        ,boost::make_move_iterator(&aux_vect[0])
                        ,boost::make_move_iterator(&aux_vect[50]));
         stdlist->insert(stdlist->begin(), &aux_vect2[0], &aux_vect2[50]);
      }

      shmlist->unique();
      stdlist->unique();
      if(!CheckEqualContainers(shmlist, stdlist))
         return 1;

      if(copied_allocators_equal){
         shmlist->sort(std::greater<IntType>());
         stdlist->sort(std::greater<int>());
         if(!CheckEqualContainers(shmlist, stdlist))
            return 1;
      }

      shmlist->resize(25);
      stdlist->resize(25);
      shmlist->resize(50);
      stdlist->resize(50);
      shmlist->resize(0);
      stdlist->resize(0);
      if(!CheckEqualContainers(shmlist, stdlist))
         return 1;

      if(push_data_t::execute(max, shmlist, stdlist)){
         return 1;
      }
      {
         MyShmList othershmlist(shmlist->get_allocator());
         MyStdList otherstdlist;

         int listsize = (int)shmlist->size();

         if(push_data_t::execute(listsize, shmlist, stdlist)){
            return 1;
         }

         if(copied_allocators_equal){
            shmlist->splice(shmlist->begin(), othershmlist);
            stdlist->splice(stdlist->begin(), otherstdlist);
            if(!CheckEqualContainers(shmlist, stdlist))
               return 1;
         }

         listsize = (int)shmlist->size();

         if(push_data_t::execute(listsize, shmlist, stdlist)){
            return 1;
         }

         if(push_data_t::execute(listsize, &othershmlist, &otherstdlist)){
            return 1;
         }

         if(copied_allocators_equal){
            shmlist->sort(std::greater<IntType>());
            stdlist->sort(std::greater<int>());
            if(!CheckEqualContainers(shmlist, stdlist))
               return 1;

            othershmlist.sort(std::greater<IntType>());
            otherstdlist.sort(std::greater<int>());
            if(!CheckEqualContainers(&othershmlist, &otherstdlist))
               return 1;

            shmlist->merge(othershmlist, std::greater<IntType>());
            stdlist->merge(otherstdlist, std::greater<int>());
            if(!CheckEqualContainers(shmlist, stdlist))
               return 1;
         }
      }

      delete shmlist;
      delete stdlist;
   }
   catch(...){
      throw;
   }
   return 0;
}

}  //namespace test{
}  //namespace container {
}  //namespace boost{

#include <boost/container/detail/config_end.hpp>

#endif

ext: hpp

max_stars_repo_name: ghisguth/tasks

max_issues_repo_name: ghisguth/tasks

max_forks_repo_name: ghisguth/tasks


text:
//  Copyright (c) 2001-2011 Hartmut Kaiser
//
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#if !defined(BOOST_SPIRIT_ADAPT_ADT_ATTRIBUTES_SEP_15_2010_1219PM)
#define BOOST_SPIRIT_ADAPT_ADT_ATTRIBUTES_SEP_15_2010_1219PM

#if defined(_MSC_VER)
#pragma once
#endif

#include <boost/fusion/include/adapt_adt.hpp>
#include <boost/spirit/home/support/attributes.hpp>
#include <boost/spirit/home/support/container.hpp>
#include <boost/spirit/home/support/numeric_traits.hpp>
#include <boost/utility/enable_if.hpp>

///////////////////////////////////////////////////////////////////////////////
// customization points allowing to use adapted classes with spirit
namespace boost {
namespace spirit {
namespace traits {
///////////////////////////////////////////////////////////////////////////
template <typename T, int N, bool Const, typename Domain>
struct not_is_variant<fusion::extension::adt_attribute_proxy<T, N, Const>,
                      Domain>
    : not_is_variant<
          typename fusion::extension::adt_attribute_proxy<T, N, Const>::type,
          Domain> {};

template <typename T, int N, bool Const, typename Domain>
struct not_is_optional<fusion::extension::adt_attribute_proxy<T, N, Const>,
                       Domain>
    : not_is_optional<
          typename fusion::extension::adt_attribute_proxy<T, N, Const>::type,
          Domain> {};

///////////////////////////////////////////////////////////////////////////
template <typename T, int N, bool Const>
struct is_container<fusion::extension::adt_attribute_proxy<T, N, Const>>
    : is_container<
          typename fusion::extension::adt_attribute_proxy<T, N, Const>::type> {
};

template <typename T, int N, bool Const>
struct container_value<fusion::extension::adt_attribute_proxy<T, N, Const>>
    : container_value<typename remove_reference<
          typename fusion::extension::adt_attribute_proxy<T, N,
                                                          Const>::type>::type> {
};

template <typename T, int N, bool Const>
struct container_value<
    fusion::extension::adt_attribute_proxy<T, N, Const> const>
    : container_value<typename add_const<typename remove_reference<
          typename fusion::extension::adt_attribute_proxy<T, N, Const>::type>::
                                             type>::type> {};

template <typename T, int N, typename Val>
struct push_back_container<
    fusion::extension::adt_attribute_proxy<T, N, false>, Val,
    typename enable_if<is_reference<
        typename fusion::extension::adt_attribute_proxy<T, N, false>::type>>::
        type> {
  static bool call(fusion::extension::adt_attribute_proxy<T, N, false> &p,
                   Val const &val) {
    typedef
        typename fusion::extension::adt_attribute_proxy<T, N, false>::type type;
    return push_back(type(p), val);
  }
};

template <typename T, int N, bool Const>
struct container_iterator<fusion::extension::adt_attribute_proxy<T, N, Const>>
    : container_iterator<typename remove_reference<
          typename fusion::extension::adt_attribute_proxy<T, N,
                                                          Const>::type>::type> {
};

template <typename T, int N, bool Const>
struct container_iterator<
    fusion::extension::adt_attribute_proxy<T, N, Const> const>
    : container_iterator<typename add_const<typename remove_reference<
          typename fusion::extension::adt_attribute_proxy<T, N, Const>::type>::
                                                type>::type> {};

template <typename T, int N, bool Const>
struct begin_container<fusion::extension::adt_attribute_proxy<T, N, Const>> {
  typedef typename remove_reference<
      typename fusion::extension::adt_attribute_proxy<T, N, Const>::type>::type
      container_type;

  static typename container_iterator<container_type>::type
  call(fusion::extension::adt_attribute_proxy<T, N, Const> &c) {
    return c.get().begin();
  }
};

template <typename T, int N, bool Const>
struct begin_container<
    fusion::extension::adt_attribute_proxy<T, N, Const> const> {
  typedef typename add_const<
      typename remove_reference<typename fusion::extension::adt_attribute_proxy<
          T, N, Const>::type>::type>::type container_type;

  static typename container_iterator<container_type>::type
  call(fusion::extension::adt_attribute_proxy<T, N, Const> const &c) {
    return c.get().begin();
  }
};

template <typename T, int N, bool Const>
struct end_container<fusion::extension::adt_attribute_proxy<T, N, Const>> {
  typedef typename remove_reference<
      typename fusion::extension::adt_attribute_proxy<T, N, Const>::type>::type
      container_type;

  static typename container_iterator<container_type>::type
  call(fusion::extension::adt_attribute_proxy<T, N, Const> &c) {
    return c.get().end();
  }
};

template <typename T, int N, bool Const>
struct end_container<
    fusion::extension::adt_attribute_proxy<T, N, Const> const> {
  typedef typename add_const<
      typename remove_reference<typename fusion::extension::adt_attribute_proxy<
          T, N, Const>::type>::type>::type container_type;

  static typename container_iterator<container_type>::type
  call(fusion::extension::adt_attribute_proxy<T, N, Const> const &c) {
    return c.get().end();
  }
};

///////////////////////////////////////////////////////////////////////////
template <typename T, int N, typename Val>
struct assign_to_attribute_from_value<
    fusion::extension::adt_attribute_proxy<T, N, false>, Val> {
  static void call(Val const &val,
                   fusion::extension::adt_attribute_proxy<T, N, false> &attr) {
    attr = val;
  }
};

template <typename T, int N, bool Const, typename Exposed>
struct extract_from_attribute<
    fusion::extension::adt_attribute_proxy<T, N, Const>, Exposed> {
  typedef typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
      get_return_type;
  typedef typename remove_const<
      typename remove_reference<get_return_type>::type>::type embedded_type;
  typedef typename spirit::result_of::extract_from<Exposed, embedded_type>::type
      extracted_type;

  // If adt_attribute_proxy returned a value we must pass the attribute
  // by value, otherwise we will end up with a reference to a temporary
  // that will expire out of scope of the function call.
  typedef
      typename mpl::if_c<is_reference<get_return_type>::value, extracted_type,
                         typename remove_reference<extracted_type>::type>::type
          type;

  template <typename Context>
  static type
  call(fusion::extension::adt_attribute_proxy<T, N, Const> const &val,
       Context &ctx) {
    return extract_from<Exposed>(val.get(), ctx);
  }
};

///////////////////////////////////////////////////////////////////////////
template <typename T, int N, bool Const>
struct attribute_type<fusion::extension::adt_attribute_proxy<T, N, Const>>
    : fusion::extension::adt_attribute_proxy<T, N, Const> {};

///////////////////////////////////////////////////////////////////////////
template <typename T, int N, bool Const>
struct optional_attribute<fusion::extension::adt_attribute_proxy<T, N, Const>> {
  typedef typename result_of::optional_value<
      typename remove_reference<typename fusion::extension::adt_attribute_proxy<
          T, N, Const>::type>::type>::type type;

  static type
  call(fusion::extension::adt_attribute_proxy<T, N, Const> const &val) {
    return optional_value(val.get());
  }

  static bool
  is_valid(fusion::extension::adt_attribute_proxy<T, N, Const> const &val) {
    return has_optional_value(val.get());
  }
};

///////////////////////////////////////////////////////////////////////////
template <typename T, int N, typename Attribute, typename Domain>
struct transform_attribute<
    fusion::extension::adt_attribute_proxy<T, N, false>, Attribute, Domain,
    typename disable_if<is_reference<
        typename fusion::extension::adt_attribute_proxy<T, N, false>::type>>::
        type> {
  typedef Attribute type;

  static Attribute
  pre(fusion::extension::adt_attribute_proxy<T, N, false> &val) {
    return val;
  }
  static void post(fusion::extension::adt_attribute_proxy<T, N, false> &val,
                   Attribute const &attr) {
    val = attr;
  }
  static void fail(fusion::extension::adt_attribute_proxy<T, N, false> &) {}
};

template <typename T, int N, bool Const, typename Attribute, typename Domain>
struct transform_attribute<
    fusion::extension::adt_attribute_proxy<T, N, Const>, Attribute, Domain,
    typename enable_if<is_reference<
        typename fusion::extension::adt_attribute_proxy<T, N, Const>::type>>::
        type> {
  typedef Attribute &type;

  static Attribute &
  pre(fusion::extension::adt_attribute_proxy<T, N, Const> &val) {
    return val;
  }
  static void post(fusion::extension::adt_attribute_proxy<T, N, Const> &,
                   Attribute const &) {}
  static void fail(fusion::extension::adt_attribute_proxy<T, N, Const> &) {}
};

template <typename T, int N, bool Const>
struct clear_value<fusion::extension::adt_attribute_proxy<T, N, Const>> {
  static void call(fusion::extension::adt_attribute_proxy<T, N, Const> &val) {
    typedef
        typename fusion::extension::adt_attribute_proxy<T, N, Const>::type type;
    clear(type(val));
  }
};

template <typename T, int N, bool Const>
struct attribute_size<fusion::extension::adt_attribute_proxy<T, N, Const>> {
  typedef typename remove_const<
      typename remove_reference<typename fusion::extension::adt_attribute_proxy<
          T, N, Const>::type>::type>::type embedded_type;

  typedef typename attribute_size<embedded_type>::type type;

  static type
  call(fusion::extension::adt_attribute_proxy<T, N, Const> const &val) {
    return attribute_size<embedded_type>::call(val.get());
  }
};

///////////////////////////////////////////////////////////////////////////
// customization point specializations for numeric generators
template <typename T, int N, bool Const>
struct absolute_value<fusion::extension::adt_attribute_proxy<T, N, Const>> {
  typedef
      typename fusion::extension::adt_attribute_proxy<T, N, Const>::type type;

  static type
  call(fusion::extension::adt_attribute_proxy<T, N, Const> const &val) {
    return get_absolute_value(val.get());
  }
};

template <typename T, int N, bool Const>
struct is_negative<fusion::extension::adt_attribute_proxy<T, N, Const>> {
  static bool
  call(fusion::extension::adt_attribute_proxy<T, N, Const> const &val) {
    return test_negative(val.get());
  }
};

template <typename T, int N, bool Const>
struct is_zero<fusion::extension::adt_attribute_proxy<T, N, Const>> {
  static bool
  call(fusion::extension::adt_attribute_proxy<T, N, Const> const &val) {
    return test_zero(val.get());
  }
};

template <typename T, int N, bool Const>
struct is_nan<fusion::extension::adt_attribute_proxy<T, N, Const>> {
  static bool
  call(fusion::extension::adt_attribute_proxy<T, N, Const> const &val) {
    return test_nan(val.get());
  }
};

template <typename T, int N, bool Const>
struct is_infinite<fusion::extension::adt_attribute_proxy<T, N, Const>> {
  static bool
  call(fusion::extension::adt_attribute_proxy<T, N, Const> const &val) {
    return test_infinite(val.get());
  }
};
} // namespace traits
} // namespace spirit
} // namespace boost

///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace spirit {
namespace result_of {
template <typename T, int N, bool Const>
struct optional_value<fusion::extension::adt_attribute_proxy<T, N, Const>>
    : result_of::optional_value<typename remove_const<typename remove_reference<
          typename fusion::extension::adt_attribute_proxy<T, N, Const>::type>::
                                                          type>::type> {};
} // namespace result_of
} // namespace spirit
} // namespace boost

#endif

max_stars_repo_name: henrywarhurst/matrix

max_issues_repo_name: henrywarhurst/matrix

max_forks_repo_name: henrywarhurst/matrix


text:
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>
#include <boost/algorithm/string/split.hpp>

#include <string>
#include <vector>
#include <memory>

#include "../../include/ast.hpp"

#include "test_setup.hpp"

namespace data = boost::unit_test::data;
namespace ast = rhea::ast;

namespace {
    // Datasets

    // Tests
    BOOST_AUTO_TEST_SUITE (AST_Binop)

    BOOST_AUTO_TEST_CASE (binop_ast)
    {
        ast::expression_ptr l = std::make_unique<ast::Integer>(42);
        ast::expression_ptr r = std::make_unique<ast::Integer>(69);
        auto op = ast::BinaryOperators::Add;

        auto node = std::make_unique<ast::BinaryOp>(op, std::move(l), std::move(r));

        BOOST_TEST_MESSAGE("Testing AST Node " << node->to_string());

        BOOST_TEST((node->op == ast::BinaryOperators::Add));

        auto node_l = dynamic_cast<ast::Integer*>(node->left.get());
        auto node_r = dynamic_cast<ast::Integer*>(node->right.get());
        BOOST_TEST(node_l->value + node_r->value == 42 + 69);
    }

    BOOST_AUTO_TEST_SUITE_END ()

    BOOST_AUTO_TEST_SUITE (AST_TernaryOp)

    BOOST_AUTO_TEST_CASE (ternary_ast)
    {
        ast::expression_ptr c = std::make_unique<ast::Integer>(42);
        ast::expression_ptr t = std::make_unique<ast::Boolean>(true);
        ast::expression_ptr f = std::make_unique<ast::Boolean>(false);

        auto node = std::make_unique<ast::TernaryOp>(std::move(c),std::move(t),std::move(f));

        BOOST_TEST_MESSAGE("Testing AST Node " << node->to_string());

        auto node_c = dynamic_cast<ast::Integer*>(node->condition.get());
        auto node_t = dynamic_cast<ast::Boolean*>(node->true_branch.get());
        auto node_f = dynamic_cast<ast::Boolean*>(node->false_branch.get());

        BOOST_TEST(node_c->value == 42);
        BOOST_TEST(node_t->value == !node_f->value);
    }

    BOOST_AUTO_TEST_SUITE_END ()

    BOOST_AUTO_TEST_SUITE (AST_UnaryOp)

    BOOST_AUTO_TEST_CASE (unary_ast)
    {
        ast::expression_ptr o = std::make_unique<ast::Integer>(42);

        auto node = std::make_unique<ast::UnaryOp>(ast::UnaryOperators::Minus, std::move(o));

        BOOST_TEST_MESSAGE("Testing AST Node " << node->to_string());

        BOOST_TEST((node->op == ast::UnaryOperators::Minus));
        BOOST_TEST((node->to_string() == "(UnaryOp,1,(Integral,42,0))"));
    }

    BOOST_AUTO_TEST_SUITE_END ()
}

ext: cpp

max_stars_repo_name: momikey/rhea

max_issues_repo_name: momikey/rhea

max_forks_repo_name: momikey/rhea