#include <iostream>
using namespace std;

#include <permutationfunc.h>
#include <binopproperties.h>
#include <binoppropertiestest.h>


uint binoppropertiestest::fop[] = 
{
  0,1,2,
  1,2,0,
  2,0,1,
  0,2,1,
  2,1,0,
  1,0,2
};


void binoppropertiestest::test01()
{
  cout << "Enter i k to calculate  k(i(w)). " << endl;
  uint i;
  uint k;

  //i=1; k=3;
  cin >> i;
  cin >> k;

  uint x[3];

  for (uint w=0; w<3; ++w)
    x[w] = fop[i*3+w];

  for (uint w=0; w<3; ++w)
    cout << x[w] << " ";
  cout << endl; 

  uint x2[3];
  
  for (uint w=0; w<3; ++w)
    x2[w] = fop[ i*3 + fop[ k*3 + w ] ];

  for (uint w=0; w<3; ++w)
    cout << x2[w] << " ";
  cout << endl; 

}


void binoppropertiestest::test02()
{
  cout << "Generate the Binary Operator Table" << endl;

  uint x2[3];

  for (uint i=0; i<6; ++i)
  {
    for (uint k=0; k<6; ++k)
    { 
      cout << "{";
      for (uint w=0; w<3; ++w)
      {
        x2[w] = fop[ i*3 + fop[ k*3 + w ] ];
        cout << x2[w] << " "; 
      }
      cout << "}";
    }
    cout << endl;
  }

}


void binoppropertiestest::test03()
{
  permutationfunc pf(fop,6,3);

  uint k;

  bool found;
  cout << "Test the inverse function" << endl;
  cout << "Iterate over the states, the numbers 0..5 should";
  cout <<  " be displayed where the state is matched with an";
  cout <<  " integer." << endl;
  for (uint i=0; i<6; ++i)
  {
    k = pf.inverse(found,fop + 3*i);
    cout << k << endl;
  }

  cout << endl << endl;
}


void binoppropertiestest::test04()
{
  cout << "Investigating (i+k) mod 6." << endl;
  uint mat[] = 
  {
    0,1,2,3,4,5,
    1,2,3,4,5,0,
    2,3,4,5,0,1,
    3,4,5,0,1,2,
    4,5,0,1,2,3,
    5,0,1,2,3,4
  };

  binopproperties gt(mat,6);

  cout << "isClosed()=" << gt.isClosed() << endl;
  cout << "isCommutative()=" << gt.isCommutative() << endl;
  cout << "isAssociative()=" << gt.isAssociative() << endl;
  cout << "isGroup()=" << gt.isGroup() << endl;
  bool found;
  cout << "identityfind(found)=" << gt.identityfind(found) << endl;
  cout << "  found=" << found << endl;
}


void binoppropertiestest::test05()
{
  cout << "Test if flipping a triange and rotating it form a group." << endl;

  cout << "The rotation and flip operators described by 6 permutation." << endl;

  permutationfunc pf(fop,6,3);

  cout << "Generate the binary table from the operators." << endl;

  uint mat[6*6];

  bool result;
  pf.writeBinaryOperator(result,mat);
  if (result==false)
  {
    cout << "Failed to form a binary operator." << endl;
    return;
  }

  for (uint i=0; i<6; ++i)
  {
    for (uint k=0; k<6; ++k)
    { 
      cout << " ";
      cout << mat[i*6+k];
      cout << " ";
    }
    cout << endl;
  }

  binopproperties gt(mat,6);

  cout << "isClosed()=" << gt.isClosed() << endl;
  cout << "isCommutative()=" << gt.isCommutative() << endl;
  cout << "isAssociative()=" << gt.isAssociative() << endl;
  cout << "isGroup()=" << gt.isGroup() << endl;
  bool found;
  cout << "identityfind(found)=" << gt.identityfind(found) << endl;
  cout << "  found=" << found << endl;
}


