package aalgTest;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;

import org.junit.Assert;
import org.junit.Test;

import aalg.algebra.DlDomainParameters;
import aalg.algebra.MonoidImpl;
import aalg.algebra.MultiGroup;
import aalg.algebra.MultiMonoidElement;
import aalg.algebra.PrimeFieldElement;
import aalg.algebra.PrimeMultiGroupGenerator;
import aalg.algebra.RationalMultiMonoidGenerator;
import aalg.algebra.RationalFieldElement;
import aalg.algebra.MultiMonoid;


public class MultiMonoidGeneratorTest {
	
	private static final BigInteger MIN_PRIME = BigInteger.ONE.shiftLeft(32);
	private static final int MIN_SIZE = 1;
	private static final int MAX_SIZE = 4;
	
	private static final int MIN_RATIONAL_VALUE = -20;
	private static final int MAX_RATIONAL_VALUE = 20;
	
	
	@Test
	public void testGenerateRationalMonoids() {
		final Random rnd = new Random();
		
		for (int size = MIN_SIZE; size <= MAX_SIZE; size++) {
			System.out.println ("Testing size " + size);
			
			final RationalMultiMonoidGenerator generator = new RationalMultiMonoidGenerator(size, MIN_RATIONAL_VALUE, MAX_RATIONAL_VALUE, rnd);
			final MultiMonoid<RationalFieldElement> monoid = generator.generateRationalMonoid();
			
			Assert.assertTrue(monoid != null);
			Assert.assertEquals(size, monoid.getSize());
		}		
	}

	@Test
	public void testGenerateMonoids() {
		final Random rnd = new Random();
		
		for (int size = MIN_SIZE; size <= MAX_SIZE; size++) {
			System.out.println ("Testing size " + size);
			
			final RationalMultiMonoidGenerator rationalGenerator = new RationalMultiMonoidGenerator(size, MIN_RATIONAL_VALUE, MAX_RATIONAL_VALUE, rnd);
			final PrimeMultiGroupGenerator primeGenerator = new PrimeMultiGroupGenerator(rationalGenerator, MIN_PRIME, rnd);
			final DlDomainParameters<MultiMonoidElement<PrimeFieldElement>> domainParameters = primeGenerator.generate();
			
			final MultiGroup<PrimeFieldElement> group = (MultiGroup<PrimeFieldElement>) domainParameters.getGroup();
			Assert.assertTrue(group != null);
			
			final MultiMonoid<PrimeFieldElement> monoid = (MultiMonoid<PrimeFieldElement>) group.getBaseMonoid();
			Assert.assertEquals(size, monoid.getSize());
		}
	}
	
}
