#include "ternary.hh"
#include <iostream>

int main()
{
	//build truth table for AND
	std::cout<<"Truth table for AND"<<std::endl;
	std::cout<<"---------------------------------"<<std::endl;
	for(unsigned short i=0; i<3; ++i)
	{
		for(unsigned short j=0; j<3; ++j)
		{
			Ternary a(i);
			Ternary b(j);
			Ternary result = a&&b;
			std::cout<<a<<" and "<<b<<" is "<<result<<std::endl;
		}
	}
	std::cout<<std::endl;

	//build truth table for OR
	std::cout<<"Truth table for OR"<<std::endl;
	std::cout<<"---------------------------------"<<std::endl;
	for(unsigned short i=0; i<3; ++i)
	{
		for(unsigned short j=0; j<3; ++j)
		{
			Ternary a(i);
			Ternary b(j);
			Ternary result = a||b;
			std::cout<<a<<" or "<<b<<" is "<<result<<std::endl;
		}
	}		
	std::cout<<std::endl;

	//build truth table for not
	std::cout<<"Truth table for NOT"<<std::endl;
	std::cout<<"---------------------------------"<<std::endl;
	for(unsigned short i=0; i<3; ++i)
	{
		Ternary a(i);
		Ternary result = !a;
		std::cout<<"not "<<a<<" is "<<result<<std::endl;
	}
	std::cout<<std::endl;

	//check whether de Morgan rules hold for ternary logic
	std::cout<<"Checking De Morgan"<<std::endl;
	std::cout<<"---------------------------------"<<std::endl;
	bool result = true; //some optimism here
	for(unsigned short i=0; i<3; ++i)
	{
		for(unsigned short j=0; j<3; ++j)
		{
			Ternary a(i);
			Ternary b(j);
			Ternary left = !(a&&b);
			Ternary right = (!a)||(!b);
			if(left!=right)
				result = false;
			left = !(a||b);
			right = (!a)&&(!b);
			if(left!=right)
				result = false;
		}
	}
	std::cout<<"De Morgan does";
	if(!result)
		std::cout<<" not";
	std::cout<<" hold for ternary logic!"<<std::endl;
	return 0;
}
