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

import org.junit.Test;

import static junit.framework.TestCase.assertEquals;

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

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

		//From the coStats class.
		long selected = 8L;

		Co_occurringTerm coOccurringTerm = new Co_occurringTerm(targetTerm, comparedTerm, compared, together);
		assertEquals( 33.33f , coOccurringTerm.calculateProbabilitySimilarityRatio(selected));

		int all = 24;
		assertEquals( 1.5f , coOccurringTerm.calculateProbabilityRatio(selected, all));
	}

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

		Co_occurringTerm coOccurringTerm = new Co_occurringTerm(targetTerm, comparedTerm, compared, together);
		coOccurringTerm.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;

		Co_occurringTerm coOccurringTerm = new Co_occurringTerm(targetTerm, comparedTerm, compared, together);
		coOccurringTerm.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;

		Co_occurringTerm coOccurringTerm = new Co_occurringTerm(targetTerm, comparedTerm, compared, together);
		coOccurringTerm.calculateProbabilityRatio(selected, 0);
	}
}

@@ -603,31 +603,8 @@
 ;%0A%09%09
-assertEquals( 33.33f , 
 coOc
@@ -664,26 +664,8 @@
 ted)
-);%0A%0A%09%09int all = 24
 ;%0A%09%09
@@ -682,11 +682,13 @@
 ls( 
-1.5
+33.33
 f , 
@@ -707,48 +707,169 @@
 erm.
-calculateProbabilityRatio(selected, all)
+getSimilarityRatio() );%0A%0A%09%09int all = 24;%0A%09%09coOccurringTerm.calculateProbabilityRatio(selected, all);%0A%09%09assertEquals( 1.5f ,coOccurringTerm.getProbabilityRatio() 
 );%0A%09

Improve javadoc. Change the statistics calculation methods so that they no longer return values - this isn't required and suggests these methods could be called repeatedly on this class.