package com.carbon108.tilde;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.util.Collection;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * @author K Moroz
 * @version 1.0
 */
public class PrimaryModelFactoryTest {

	private PrimaryModelFactory factory;

	@Before
	public void setUp() {
		factory = new PrimaryModelFactory();
	}

	@Rule
	public final ExpectedException exception = ExpectedException.none();

	@Test
	public void getIDsGetsAllValidModelIDs() {
		Collection<String> factoryIDs = factory.getIDs();
		assertEquals(2, factoryIDs.size());
		assertEquals(true, factoryIDs.contains(ModelID.LINEAR));
		assertEquals(true, factoryIDs.contains(ModelID.CONSTANT));

		// check immutability
		exception.expect(UnsupportedOperationException.class);
		factoryIDs.add("someString");
	}

	@Test
	public void makeValidModelIDGetsModel() {
		TildeModel model1 = factory.make(ModelID.LINEAR);
		TildeModel model2 = factory.make(ModelID.CONSTANT);
		assertEquals(ModelID.LINEAR, model1.getID());
		assertEquals(ModelID.CONSTANT, model2.getID());
	}

	@Test
	public void makeInvalidIDGetsNullModel() {
		TildeModel m1null = factory.make(null);
		TildeModel m1blank = factory.make("");
		TildeModel m2invalid = factory.make("invalidModelID");
		assertTrue(m1null.isNullModel());
		assertTrue(m1blank.isNullModel());
		assertTrue(m2invalid.isNullModel());
	}

	@Test
	public void makeAll() {
		Collection<TildeModel> models = factory.makeAll();
		assertEquals(2, models.size());
		assertEquals(true, models.contains(new LinearModel()));
		assertEquals(true, models.contains(new ConstantModel()));
	}

}
