package org.spbu.bdd.samples.test;

import static org.junit.Assert.*;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Random;
import java.util.Set;

import org.junit.Test;
import org.spbu.bdd.samples.assign.AssignBasic;
import org.spbu.bdd.samples.assign.AssignBdd;
import org.spbu.bdd.samples.assign.Timetable;

public class AssignTest {
	static String fileStr = "test/org/spbu/bdd/samples/test/assign/test";
	static int numTests = 1;
	static int taskSize = 3;
	@Test
	public void testBasic() throws Exception {
		long[] times = new long[numTests];
		for (int i=0; i<numTests; i++) {
			FileInputStream in = new FileInputStream(fileStr+"__"+i+".data");
			Timetable t = new Timetable();
			t.parse(in);
			in.close();

			long start = System.currentTimeMillis();
			Set<int[]> res = new AssignBasic().solve(t);
			times[i] = System.currentTimeMillis() - start;
			System.out.println(times[i]);
		}
		System.out.println(Arrays.toString(times));
		//assertEquals(1, res.size());
	}
	
	@Test
	public void testBdd() throws Exception {
		long[] times = new long[numTests];
		for (int i=0; i<numTests; i++) {
			FileInputStream in = new FileInputStream(fileStr+"__"+i+".data");
			Timetable t = new Timetable();
			t.parse(in);
			in.close();

			long start = System.currentTimeMillis();
			Set<LinkedList<Integer>> res = new AssignBdd().solve(t);
			/*
			try {
				Set<LinkedList<Integer>> res = new AssignBdd().solve(t);
			} catch (OutOfMemoryError e) {
				System.out.println("out of memory");
				times[i]=0;
				continue;
			}
			*/
			times[i] = System.currentTimeMillis() - start;
			System.out.println(times[i]);
		}
		System.out.println(Arrays.toString(times));
		System.gc();		
	}
	
	public static void main(String[] args) throws Exception {
		
		for (int i=0; i<numTests; i++) do {
			PrintStream out = new PrintStream(new FileOutputStream(fileStr+"__"+i+".data"));
			Random generator = new Random();
			int values = taskSize+i;
			for (int j=0; j<values; j++) {
				/*
				boolean[] wasAlready = new boolean[values];
				for (int k=0; k<taskSize; k++) {
					int val = generator.nextInt(values);
					if (!wasAlready[val]) {
						wasAlready[val]=true;
						out.print(val+" ");
					}
				}
				*/				

				
				for (int k=j; k<values; k++) {
					out.print(k+" ");
				}
				
				out.println();
			}
			out.close();
			
			/*
			FileInputStream in = new FileInputStream(fileStr+"__"+i+".data");
			Timetable t = new Timetable();
			t.parse(in);
			in.close();
			Set<int[]> res;
			try {
				res = new AssignBasic().solve(t);
			} catch (OutOfMemoryError e) {
				continue;
			}
			*/
		} while (false);
	}
}
