package xyz.thastertyn;

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

import org.junit.Test;

import xyz.thastertyn.Types.FinalMark;
import xyz.thastertyn.Types.Mark;
import xyz.thastertyn.Types.Subject;

/**
 * Unit test for simple App.
 */
public class AppTest 
{
	/**
	 * Rigorous Test :-)
	 */
	@Test
	public void shouldAnswerWithTrue()
	{
		assertTrue( true );
	}

	@Test
	public void noMarksPresentTest()
	{
		// No marks are present on start
		Subject subject = new Subject("Test Subject");

		assertTrue(subject.getMarks().isEmpty());
	}

	@Test
	public void correctAverage()
	{
		Subject subject = new Subject("Test");

		// Average is calculated properly
		subject.addMark(new Mark(1, false, "1"));
		subject.addMark(new Mark(3, false, "3"));

		assertTrue(subject.getFinalMark().getValue() == 2.0);
	}

	@Test
	public void correctSmallMarkAverage()
	{
		// Small marks are calculated properly
		Subject subject = new Subject("Test");

		subject.addMark(new Mark(1, false, "1"));
		subject.addMark(new Mark(3, false, "3"));
		subject.addMark(new Mark(5, true, "5"));
		subject.addMark(new Mark(5, true, "5"));

		assertTrue(subject.getFinalMark().getValue() == 3.0);
	}

	@Test
	public void marksDontChangeFinalMark()
	{
		// Once a final mark is given, no additional marks should change it
		Subject subject = new Subject("Test", FinalMark.NEDOSTATECNY);
		subject.addMark(new Mark(1, false, "a"));
		subject.addMark(new Mark(1, false, "a"));
		subject.addMark(new Mark(1, false, "a"));
		subject.addMark(new Mark(1, false, "a"));

		assertEquals(FinalMark.NEDOSTATECNY, subject.getFinalMark());
	}
}
