package networkTest;

import network.ShannonsModel;
import java.text.DecimalFormat;
import junit.framework.*;

/**
 * JUnit tests for the ShannonsModel class from the "network" project. This
 * class will test for exception
 * 
 * @author 
 * @version 1.8.0 2017/02/11
 */
public class Test_ShannonsModel extends TestCase {

	public Test_ShannonsModel(String name) {
		super(name);
	}

	public static Test suite() {
		return new TestSuite(Test_ShannonsModel.class);
	}

	protected void setUp() throws Exception {
		System.out.println("Test_ShannonsModel Begin");
	}

	protected void tearDown() throws Exception {
		System.out.println("Test_ShannonsModel End");
	}

	/**
	 * Test the constructors. This test was done by instantiating a new instance
	 * of ShannonsTheorem, and then running a check to see if the object has
	 * random negative value. This will occur the NumberFormatException by
	 * negative value.
	 */
	public void testConstructors() {

		boolean testflag = false;
		try {
			shannonsModel = new ShannonsModel(185.3, -2.3);

		} catch (NumberFormatException e) {
			testflag = true;
		}
		assertTrue(testflag == true);

	}

	/**
	 * Test the getter of bandwidth. Bandwidth value is random negative value.
	 * If this random value doesn't occur the NumberFormatException, test will
	 * fail.
	 */
	public void testGetBandwidth() {

		boolean testflag = false;
		try {
			shannonsModel = new ShannonsModel(-15, 2.5);
			shannonsModel.getBandwidth();

		} catch (NumberFormatException e) {
			testflag = true;
		}

		assertTrue(testflag == true);

	}

	/**
	 * Test the getter of signal to noise. SignalToNoise value is random
	 * negative value. If this random value doesn't occur the
	 * NumberFormatException, test will fail.
	 */
	public void testgetSignalToNoise() {

		boolean testflag = false;
		try {
			shannonsModel = new ShannonsModel(20.5, -2);
			shannonsModel.getSignalToNoise();

		} catch (NumberFormatException e) {
			testflag = true;
		}
		assertTrue(testflag == true);
	}

	/**
	 * Test the setter of bandwidth. Bandwidth value is random negative value.
	 * If this random value doesn't occur the NumberFormatException, test will
	 * fail.
	 */
	public void testSetBandwidth() {
		shannonsModel = new ShannonsModel();
		boolean testflag = false;
		try {
			shannonsModel.setBandwidth(-0.5);

		} catch (NumberFormatException e) {
			testflag = true;
		}
		assertTrue(testflag == true);

	}

	/**
	 * Test the setter of signal to noise. SignalToNoise value is random
	 * negative value. If this random value doesn't occur the
	 * NumberFormatException, test will fail.
	 */
	public void testSetSignalToNoise() {
		shannonsModel = new ShannonsModel();
		boolean testflag = false;
		try {

			shannonsModel.setSignalToNoise(-10.5);

		} catch (NumberFormatException e) {
			testflag = true;
		}
		assertTrue(testflag == true);
	}

	/**
	 * Test behaviors. when bandwidth value have negative value, and signal to
	 * noise have a positive value, it is going to make an number format
	 * exception
	 */
	public void testBehaviors1() {
		shannonsModel = new ShannonsModel();
		boolean testflag = false;
		try {
			shannonsModel.setBandwidth(-50);
			shannonsModel.setSignalToNoise(10);
			shannonsModel.getMaximumDataRate();

		} catch (NumberFormatException e) {
			testflag = true;
		}
		assertTrue(testflag == true);
	}

	/**
	 * Test behaviors. when bandwidth value have negative one, and signal to
	 * noise have a positive value, it is going to make an number format
	 * exception
	 */
	public void testBehaviors2() {
		shannonsModel = new ShannonsModel();
		boolean testflag = false;
		try {

			shannonsModel.setBandwidth(-1);
			shannonsModel.setSignalToNoise(15);
			shannonsModel.getMaximumDataRate();

		} catch (NumberFormatException e) {
			testflag = true;
		}
		assertTrue(testflag == true);
	}

	/**
	 * Test behaviors. when bandwidth value have positive value, and signal to
	 * noise have a negative value, it is going to make an number format
	 * exception
	 */
	public void testBehaviors3() {
		shannonsModel = new ShannonsModel();
		boolean testflag = false;
		try {
			shannonsModel.setBandwidth(12);
			shannonsModel.setSignalToNoise(-5);
			shannonsModel.getMaximumDataRate();
		} catch (NumberFormatException e) {

			testflag = true;

		}
		assertTrue(testflag == true);
	}

	/**
	 * Test behaviors. when bandwidth value have positive value, and signal to
	 * noise have a negative one, it is going to make an number format exception
	 */
	public void testBehaviors4() {
		shannonsModel = new ShannonsModel();
		boolean testflag = false;
		try {
			shannonsModel.setBandwidth(20);
			shannonsModel.setSignalToNoise(-1);
			shannonsModel.getMaximumDataRate();
		} catch (NumberFormatException e) {

			testflag = true;

		}
		assertTrue(testflag == true);
	}

	/**
	 * Test behaviors. when bandwidth value have positive value, and signal to
	 * noise have a zero, it is not going to make an exception.
	 */
	public void testBehaviors5() {
		shannonsModel = new ShannonsModel();
		shannonsModel.setBandwidth(38);
		shannonsModel.setSignalToNoise(0);
		double expResult3 = 0;
		double result2 = shannonsModel.getMaximumDataRate();
		if (Math.abs(expResult3 - result2) > 0.0000000001) {
			fail("the calculation is incorrect");
		}

	}

	/**
	 * Test behaviors. when bandwidth have a zero, and signal to noise have a
	 * positive value, it is not going to make an exception.
	 */
	public void testBehaviors6() {
		shannonsModel = new ShannonsModel();
		shannonsModel.setBandwidth(0);
		shannonsModel.setSignalToNoise(85);
		double expResult3 = 0;
		double result2 = shannonsModel.getMaximumDataRate();
		if (Math.abs(expResult3 - result2) > 0.0000000001) {
			fail("the calculation is incorrect");
		}

	}

	/**
	 * Test behaviors7. when bandwidth and signal to noise have a positive
	 * value, it is not going to make an exception.
	 */
	public void testBehaviors7() {
		shannonsModel = new ShannonsModel();
		shannonsModel.setBandwidth(45);
		shannonsModel.setSignalToNoise(9);
		double expResult3 = 149.49;
		double result2 = Double.parseDouble(df.format(shannonsModel.getMaximumDataRate()));
		if (Math.abs(expResult3 - result2) > 0.0000000001) {
			fail("the calculation is incorrect");
		}
	}

	/**
	 * Test behaviors8. when bandwidth and signal to noise have a positive
	 * value, it is not going to make an exception.
	 */
	public void testBehaviors8() {
		shannonsModel = new ShannonsModel();
		shannonsModel.setBandwidth(54);
		shannonsModel.setSignalToNoise(142);
		double expResult3 = 386.63;
		double result2 = Double.parseDouble(df.format(shannonsModel.getMaximumDataRate()));
		if (Math.abs(expResult3 - result2) > 0.0000000001) {
			fail("the calculation is incorrect");
		}
	}

	/* STAND-ALONE ENTRY POINT ----------------------------------------- */
	/**
	 * Main line for stand alone operation.
	 * 
	 * @param args
	 *            Standard string command line parameters.
	 */
	public static void main(String[] args) {
		System.out.println("Executing Test_ShannonsModel suite");
		junit.textui.TestRunner.run(suite());
	}

	/* ATTRIBUTES ----------------------------------------------- */
	private ShannonsModel shannonsModel = null;
	DecimalFormat df = new DecimalFormat("######0.00");

}// end of class
