/*
    Copyright (C) 2012 Bartosz Broda, Jacek Bochenek, Łukasz Biłeńkij, 
    Damian Jaworski, Wojciech Mazur, Dominik Piasecki, Maciej Piasecki, 
    Radosław Ramocki
    
    This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.

    This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. 

    See the LICENSE and COPYING files for more details.
*/

#include <boost/test/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>
#include <test_utils/utils.h>
#include <index.h>


BOOST_AUTO_TEST_CASE(tuple_adding_test)
{

	std::string* lines=getTupleLines();
	tuplesproc::Index index;
	for(int unsigned i=0; i<lines->size(); i++)
		BOOST_CHECK_EQUAL(index.add_tuple(*lines++), true);

	BOOST_CHECK_EQUAL(index.add_tuple("subst:okres;adjp;subst:demografia"), false);
	BOOST_CHECK_EQUAL(index.add_tuple("subst:okres;adjp;subst:demografia;23;sometingelse"), false);

}

BOOST_AUTO_TEST_CASE(creating_matrix_test)
{
	std::string* lines=getTupleLines();
	tuplesproc::Index index;
	for(int unsigned i=0; i<lines->size(); i++)
		index.add_tuple(*lines++);
	std::map<std::string, size_t> dict;
	Matrices::SuperMatrixPtr matrix = index.mkmatrix("Test", 100, "Corpus", dict);

	BOOST_CHECK_EQUAL(matrix->NumberOfRows(), 20);
	BOOST_CHECK_EQUAL(matrix->NumberOfColumns(), 21);

	Matrices::FeatureVectorPtr rowF= matrix->GetRowFeatures();
	Matrices::FeatureVectorPtr colF= matrix->GetColumnFeatures();

	//Checking rows features
	Matrices::Feature feat=rowF->at(8);
	BOOST_CHECK_EQUAL(feat.GetNZ(), 2);
	BOOST_CHECK_EQUAL(feat.GetTermFrequency(), 3);

	feat=rowF->at(12);
	BOOST_CHECK_EQUAL(feat.GetNZ(), 3);
	BOOST_CHECK_EQUAL(feat.GetTermFrequency(), 5);

	feat=rowF->at(13);
	BOOST_CHECK_EQUAL(feat.GetNZ(), 1);
	BOOST_CHECK_EQUAL(feat.GetTermFrequency(), 1);

	//Checking columns features

	for(int unsigned i=0; i<8; i++)
	{
		feat=colF->at(i);
		BOOST_CHECK_EQUAL(feat.GetLabel().find("adjp"), 0);
		BOOST_CHECK_EQUAL(feat.GetNZ(), 1);
		BOOST_CHECK_EQUAL(feat.GetTermFrequency(), 1);
	}


	feat=colF->at(9);
	BOOST_CHECK_EQUAL(feat.GetLabel().find("coord"), 0);
	BOOST_CHECK_EQUAL(feat.GetNZ(), 1);
	BOOST_CHECK_EQUAL(feat.GetTermFrequency(), 1);

	feat=colF->at(10);
	BOOST_CHECK_EQUAL(feat.GetLabel().find("coord"), 0);
	BOOST_CHECK_EQUAL(feat.GetNZ(), 2);
	BOOST_CHECK_EQUAL(feat.GetTermFrequency(), 3);


	feat=colF->at(17);
	BOOST_CHECK_EQUAL(feat.GetLabel().find("coord"), 0);
	BOOST_CHECK_EQUAL(feat.GetNZ(), 1);
	BOOST_CHECK_EQUAL(feat.GetTermFrequency(), 3);


}

