package dkohl.bayes.example;

import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Test;

import dkohl.bayes.bayesnet.BayesNet;
import dkohl.bayes.example.builders.AlarmNetBuilderTable;
import dkohl.bayes.example.builders.AlarmNetBuilderTree;
import dkohl.bayes.inference.EnumerateAll;
import dkohl.bayes.probability.ProbabilityAssignment;
import dkohl.bayes.probability.Variable;

public class AlarmExampleTest {

	@Test
	public void testAlarmExample() {
		BayesNet sprinkler = AlarmNetBuilderTable.alarm();
		sprinkler = AlarmNetBuilderTree.sprinkler();
		// P(B | j, m)
		List<ProbabilityAssignment> probs = EnumerateAll.enumerateAsk(
				new Variable(AlarmNetBuilderTable.BURGLARY,
						AlarmNetBuilderTable.DOMAIN), sprinkler,
				AlarmNetBuilderTable.completeQueryBulgary());
		System.out.print("Burglary: <");
		for (ProbabilityAssignment p : probs) {
			System.out.print("p: "+ p.toString() + ",");
		}
		System.out.println(">");
		
		//assert that burglary is more likely to be false
		assertThat(probs.size(),equalTo(2));
		assertTrue(probs.get(0).getProbability() < probs.get(1).getProbability());
	}
}