

#include "bdc.h"

#include <set>
#include <iostream>
#include <cassert>
#include <vector>
#include <random>


using namespace std;


void tester(string name, vector<int> values, vector<int> solnA, vector<int> solnB = {}, vector<int> solnC = {}){
	cout << name << endl;
	cout << "\tinput: " << vec_to_string(values) << endl;
	vector<int> ans = biggest_divisible_conglomerate(values);
	cout << "\toutput: " << vec_to_string(ans) << endl;
	set<int> answerSet(ans.begin(), ans.end());
	if(solnB.size() == 0){
		set<int> solnSet(solnA.begin(), solnA.end());
		assert(answerSet == solnSet);
	} else if(solnB.size() > 0 && solnC.size() == 0){
		set<int> solnSetA(solnA.begin(), solnA.end());
		set<int> solnSetB(solnB.begin(), solnB.end());
		assert(answerSet == solnSetA || answerSet == solnSetB);
	} else if(solnB.size() > 0 && solnC.size() > 0){
		set<int> solnSetA(solnA.begin(), solnA.end());
		set<int> solnSetB(solnB.begin(), solnB.end());
		set<int> solnSetC(solnC.begin(), solnC.end());
		assert(answerSet == solnSetA || answerSet == solnSetB || answerSet == solnSetC);
	}
	cout << "\t\x1B[32m" << "PASSED!" << "\033[0m" << endl << endl;
}


void tests(){
	// Same tests for both
	// largest-divisible-pairs.cpp
	// largest-divisible-pairs-dp.cpp
	// the final test is only feasible with the dyncamic programming solution

	cout << "Testing..." << endl;

	vector<int> values = {28, 22, 7, 2, 8, 14, 24, 56};
	tester("Test #1... example from assignment description", values, {56, 14, 7, 28}, {56, 28, 14, 2});

	values = {28, 22, 9, 2, 8, 14, 24, 56};
	tester("Test #1a", values, {2, 14, 28, 56});

	values = {10, 5, 3, 15, 20};
	tester("Test #2", values, {20, 5, 10});

	values = {18, 1, 3, 6, 13, 17};
	tester("Test #3...", values, {1, 3, 6, 18});

	values = {1, 2, 4, 8};
	tester("Test #4 (powers of 2)", values, {8, 4, 2, 1});

	values = {18, 1, 3, 6, 13, 17, 50, 42, 11, 19, 8, 43, 10, 48, 15, 35, 22, 41, 7, 30, 27, 28, 25, 4, 32, 44, 36};
	tester("Test #5... (to big to be done by hand)", values, {36, 6, 3, 1, 18});

	values = {};
	tester("Test #6... (empty vector)", values, {});

	values = {5};
	tester("Test #7... (vector of one item)", values, {5});

	values = {2, 5};
	tester("Test #8... (vector of two items)", values, {5}, {2});

	values = {2, 3, 5, 7, 11, 13};
	tester("Test #9... (all prime numbers)", values, {13}, {2});

	values = {2, 6, 9, 12, 18, 24, 36, 72};
	tester("Test #10... (test with two different valid answers)", values, {2, 6, 12, 24, 72}, {2, 6, 18, 36, 72});

	values = {5, 7, 15, 18, 35, 40, 45};
	tester("Test #11... (prior student suggestion #1)", values, {45, 15, 5});

	values = {4, 5, 7, 15, 17, 34, 68};
	tester("Test #12... (prior student suggestion #2)", values, {17, 34, 68});

	values = {45, 5, 11, 15, 17, 4};
	tester("Test #13... (piror student suggestion #3)", values, {15, 5, 45});

	values = {2, 4, 3, 21, 5, 36, 9, 7, 18, 20};
	tester("Test #14... prior student test #4)", values, {18, 9, 36, 3});

	values = {1, 3, 5, 15, 20, 40, 80};
	tester("Test #15... (prior student test #5)", values, {80, 40, 20, 5, 1});

	values = {14, 16, 1, 18, 3, 6, 12, 9, 36, 72};
	tester("Test #16... (three possible answers)", values, {72, 36, 6, 3, 18, 1}, {1, 3, 9, 18, 36, 72}, {1, 3, 6, 12, 36, 72});



	/*
	cout << "Test #17... (random value tests)" << endl;
	cout << "\tThis test is prohbitively large.\n\tIt is takes several minutes to complete unless dynamic programming is used!" << endl;
	cout << "\tIt may be wise to comment out this test for part 1 of this assignment." << endl;
	vector<int> random_values;
	random_device rd;
	mt19937 gen(rd());
	uniform_int_distribution<int> dist(1, 40000);
	while (random_values.size() < 28000) {
		random_values.push_back(dist(gen));
	}

	cout << "\n\tCalculating answer for input of size: " << random_values.size() << "..." << endl;
	time_t start = time(0);
	vector<int> ans = biggest_divisible_conglomerate(random_values);
	time_t end = time(0);
	cout << "\tDone!  The answer is: " << vec_to_string(ans) << endl;
	time_t duration = end - start;
	cout << "\tIt took " << duration << " seconds.  Wow!" << endl;
	cout << "\t\x1B[32m" << "PASSED!" << "\033[0m" << endl << endl;
	*/


	cout << "\x1B[32m" << "ALL TESTS PASSED!" << "\033[0m" << endl;
}



int main() {
	tests();
	return 0;
}


// New Test (got this test from a student in Fall 2023)
// multiple correct answers
//   [60, 30, 15, 5]
//   [60, 30, 10, 5]
//   [90, 45, 15, 5]
//   [90, 45, 15, 3]

/**
values = {30, 15, 60, 45, 90, 10, 5, 20, 40, 3};
ans = biggest_divisible_conglomerate(values);
cout << "Input: " << vec_to_string(values) << endl;
cout << "Output: " << vec_to_string(ans) << endl << endl;
set<int> answerSet14(ans.begin(), ans.end());
soln = {5, 60, 30, 15};
assert(answerSet14 == soln);


Another interesting test:
[6, 7, 12, 24, 28, 56, 112 OR 48]
**/