package uk.ac.ebi.quickgo.index.annotation.coterms;

import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;

/**
 * @Author Tony Wardell
 * Date: 16/11/2015
 * Time: 13:52
 * Created with IntelliJ IDEA.
 */
public class CoTermTest {

	@Test
	public void successfullyCalculateStatistics(){
		String targetTerm = "GO:00000200";
		String comparedTerm = "GO:0003824";
		long compared = 8L;
		long together = 4L;

		long selected = 8L;

		CoTerm coTerm =
				new CoTerm.Builder().setTarget(targetTerm).setComparedTerm(comparedTerm).setCompared(compared)
						.setTogether(together).createCoTerm();
		coTerm.calculateProbabilitySimilarityRatio(selected);
		assertThat(coTerm.getSimilarityRatio(), equalTo(33.33f) );

		int all = 24;
		coTerm.calculateProbabilityRatio(selected, all);
		assertThat(coTerm.getProbabilityRatio(), equalTo( 1.5f));
	}

	@Test(expected = IllegalArgumentException.class)
	public void calculateProbabilitySimilarityRatioSelectEqualToZeroThrowsException(){
		String targetTerm = "GO:00000200";
		String comparedTerm = "GO:0003824";
		long compared = 8L;
		long together = 4L;

		CoTerm coTerm =
				new CoTerm.Builder().setTarget(targetTerm).setComparedTerm(comparedTerm).setCompared(compared)
						.setTogether(together).createCoTerm();
		coTerm.calculateProbabilitySimilarityRatio(0L);
	}

	@Test(expected = IllegalArgumentException.class)
	public void calculateProbabilityRatioSelectEqualToZeroThrowsException(){
		String targetTerm = "GO:00000200";
		String comparedTerm = "GO:0003824";
		long compared = 8L;
		long together = 4L;

		int all = 24;

		CoTerm coTerm =
				new CoTerm.Builder().setTarget(targetTerm).setComparedTerm(comparedTerm).setCompared(compared)
						.setTogether(together).createCoTerm();
		coTerm.calculateProbabilityRatio(0l, all);
	}


	@Test(expected = IllegalArgumentException.class)
	public void calculateProbabilityRatioAllEqualToZeroThrowsException(){
		String targetTerm = "GO:00000200";
		String comparedTerm = "GO:0003824";
		long compared = 8L;
		long together = 4L;
		long selected = 8L;

		CoTerm coTerm =
				new CoTerm.Builder().setTarget(targetTerm).setComparedTerm(comparedTerm).setCompared(compared)
						.setTogether(together).createCoTerm();
		coTerm.calculateProbabilityRatio(selected, 0);
	}
}

@@ -2326,11 +2326,982 @@
 , 0);%0A%09%7D
+%0A%0A%09@Test(expected = IllegalArgumentException.class)%0A%09public void ifSetTargetIsPassedNullAnExceptionIsThrown()%7B%0A%09%09new CoTerm.Builder().setTarget(null);%0A%09%7D%0A%0A%09@Test(expected = IllegalArgumentException.class)%0A%09public void ifSetTargetIsPassedEmptyStringAnExceptionIsThrown()%7B%0A%09%09new CoTerm.Builder().setTarget(%22   %22);%0A%09%7D%0A%0A%09@Test(expected = IllegalArgumentException.class)%0A%09public void ifSetComparedTermIsPassedNullAnExceptionIsThrown()%7B%0A%09%09new CoTerm.Builder().setComparedTerm(null);%0A%09%7D%0A%0A%09@Test(expected = IllegalArgumentException.class)%0A%09public void ifSetComparedTermIsPassedEmptyStringAnExceptionIsThrown()%7B%0A%09%09new CoTerm.Builder().setComparedTerm(%22   %22);%0A%09%7D%0A%0A%09@Test(expected = IllegalArgumentException.class)%0A%09public void ifSetComparedIsPassedZeroAnExceptionIsThrown()%7B%0A%09%09new CoTerm.Builder().setCompared(0);%0A%09%7D%0A%0A%09@Test(expected = IllegalArgumentException.class)%0A%09public void ifSetTogetherTermIsPassedEmptyStringAnExceptionIsThrown()%7B%0A%09%09new CoTerm.Builder().setTogether(0);%0A%09%7D
 %0A%7D%0A

Add test methods for builder set methods.