#include <iostream.h>
#include "hyptest.h"

void knvartest();
void unknvartest();
double testmean(Data<double>&,double);
double testvar(Data<double>&,double);

int main()
{
	cout << "Given a sample a data, this program will utilize 'hyptest.h' to perform" << endl
		<< "some simple statisitcal analysis."<< endl;
	int option;
	while (1)
	{
		cout << endl
			<< "Choose an option:" << endl
			<< "(1) enter in data of known variance" << endl
			<< "(2) enter in data of unknown variance" << endl
			<< "(3) exit this program" <<endl
			<< "? ";
		cin >> option;
		if (option == 1)
			knvartest();
		if (option == 2)
			unknvartest();
		if (option == 3)
			return 0;
	}
	return 0;
}

void knvartest()
{
	cout << endl;
	KnVarData<double> sample;
	int option,i;
	double testval;
	while (1)
	{
		cout << endl
			<< "Choose an option:" << endl
			<< "(1) list the sample data" << endl
			<< "(2) return the true variance" << endl
			<< "(3) calculate the sample mean" << endl
			<< "(4) calculate the sample variance" << endl
			<< "(5) test a given mean" <<endl
			<< "(6) test a given variance" <<endl
			<< "(7) return to main menu" << endl
			<< "? ";
		cin >> option;
		if (option == 1)
		{
			cout << endl << "sample = {";
			for (i=0;i<sample.size()-1;i++)
				cout << sample[i] << ", ";
			cout << sample[i] << "}" << endl;
		}
		if (option == 2)
			cout << endl << "true variance = " << sample.var() << endl;
		if (option == 3)
			cout << endl << "sample mean = " << sample.sampmean() << endl;
		if (option == 4)
			cout << endl << "sample variance = " << sample.sampvar() << endl;
		if (option == 5)
		{
			cout << endl << "Enter the mean to be tested:" << endl << "? ";
			cin >> testval;
			cout << "probability of type I error = "<< 100*testmean(sample,testval)
				<< " %" << endl;
		}
		if (option == 6)
		{
			cout << endl << "Enter the variance to be tested:" << endl << "? ";
			cin >> testval;
			cout << "probability of type I error = "<< 100*testvar(sample,testval)
				<< " %" << endl;
		}
		if (option == 7)
			return;
	}
	return;
}

void unknvartest()
{
	cout << endl;
	UnknVarData<double> sample;
	int option,i;
	double testval;
	while (1)
	{
		cout << endl
			<< "Choose an option:" << endl
			<< "(1) list the sample data" << endl
			<< "(2) calculate the sample mean" << endl
			<< "(3) calculate the sample variance" << endl
			<< "(4) test a given mean" <<endl
			<< "(5) test a given variance" <<endl
			<< "(6) return to main menu" << endl
			<< "? ";
		cin >> option;
		if (option == 1)
		{
			cout << endl << "sample = {";
			for (i=0;i<sample.size()-1;i++)
				cout << sample[i] << ", ";
			cout << sample[i] << "}" << endl;
		}
		if (option == 2)
			cout << endl << "sample mean = " << sample.sampmean() << endl;
		if (option == 3)
			cout << endl << "sample variance = " << sample.sampvar() << endl;
		if (option == 4)
		{
			cout << endl << "Enter the mean to be tested:" << endl << "? ";
			cin >> testval;
			cout <<endl << "probability of type I error = "<< 100*testmean(sample,testval)
				<< " %" << endl;
		}
		if (option == 5)
		{
			cout << endl << "Enter the variance to be tested:" << endl << "? ";
			cin >> testval;
			cout << endl << "probability of type I error = "<< 100*testvar(sample,testval)
				<< " %" << endl;
		}
		if (option == 6)
			return;
	}
	return;
}

double testmean(Data<double>& testsamp,double testval)
{
	return testsamp.meantest(testval);
}

double testvar(Data<double>& testsamp,double testval)
{
	return testsamp.vartest(testval);
}