/*
 *  @(#)Test_ShannonsTheorem.java	Feb 17, 2005
 *
 *
 *  This software contains confidential and proprietary information
 *  of Dyer Consulting ("Confidential Information").  You shall not disclose
 *  such Confidential Information and shall use it only in accordance with the
 *  terms of the license agreement you entered into with Dyer Consulting.
 *
 *  This software is provided "AS IS,".  No warrantee of any kind, express
 *  or implied, is included with this software; use at your own risk, responsibility
 *  for damages (if any) to anyone resulting from the use of this software rests
 *  entirely with the user even if Dyer Consulting has been advised of the
 *  possibility of such damages.
 *
 *  This software is not designed or intended for use in on-line control of
 *  aircraft, air traffic, aircraft navigation or aircraft communications; or in
 *  the design, construction, operation or maintenance of any nuclear
 *  facility. Licensee represents and warrants that it will not use or
 *  redistribute the Software for such purposes.
 *
 *  Distribute freely, except: don't remove my name from the source or
 *  documentation, mark your changes (don't blame me for your possible bugs),
 *  don't alter or remove any of this notice.
 *
 */

package networkTest;

import junit.framework.*;
import static org.junit.Assert.fail;

import java.text.DecimalFormat;

import network.ShannonsModel;
import network.ShannonsTheorem;

/**
 * JUnit tests for the ShannonsTheorem class from the "network" project.
 * 
 * 
 * @author 
 * @version 1.8.0 2017/02/11
 */
public class Test_ShannonsTheorem extends TestCase {

	public Test_ShannonsTheorem(String name) {
		super(name);
	}

	public static Test suite() {
		return new TestSuite(Test_ShannonsTheorem.class);
	}

	protected void setUp() throws Exception {
		System.out.println("Test_ShannonsTheorem Begin");
	}

	protected void tearDown() throws Exception {
		System.out.println("Test_ShannonsTheorem End");
	}

	/**
	 * Test the constructors.
	 */
	public void testConstructors() {
		ShannonsModel model = new ShannonsModel();
		shannonsTheorem = new ShannonsTheorem(model);
		assertNotNull(shannonsTheorem.toString());
	}

	/**
	 * Test the getter of bandwidth. Bandwidth value is random positive value.
	 * If this random value doesn't match with expected getBandwidth result,
	 * test will fail.
	 */
	public void testGetBandwidth() {
		ShannonsModel model = new ShannonsModel();
		shannonsTheorem = new ShannonsTheorem(model);
		shannonsTheorem.setBandwidth(100);
		assertEquals(100, shannonsTheorem.getBandwidth(), 0);
	}

	/**
	 * Test the getter of SignalToNoise. Signal to noise value is random
	 * positive value. If this random value doesn't match with expected
	 * getSignalToNoise result, test will fail.
	 */
	public void testgetSignalToNoise() {
		ShannonsModel model = new ShannonsModel();
		shannonsTheorem = new ShannonsTheorem(model);
		shannonsTheorem.setSignalToNoise(2);
		assertEquals(2, shannonsTheorem.getSignalToNoise(), 0);
	}

	/**
	 * Test the setter of bandwidth. Bandwidth value is random positive value.
	 * If this random value doesn't match with expected result, test will fail.
	 */
	public void testSetBandwidth() {
		ShannonsModel model = new ShannonsModel();
		shannonsTheorem = new ShannonsTheorem(model);
		shannonsTheorem.setBandwidth(320);
		double expect1 = shannonsTheorem.getBandwidth();
		assertEquals(expect1, shannonsTheorem.getBandwidth(), 0);
	}

	/**
	 * Test the setter of SignalToNoise. Signal to noise value is random
	 * positive value. If this random value doesn't match with expected result,
	 * test will fail.
	 */
	public void testSetSignalToNoise() {
		ShannonsModel model = new ShannonsModel();
		shannonsTheorem = new ShannonsTheorem(model);
		shannonsTheorem.setSignalToNoise(2);
		double expect1 = shannonsTheorem.getBandwidth();
		assertEquals(expect1, shannonsTheorem.getBandwidth(), 0);

	}

	/**
	 * behaviors1 for testing negative value of signal to noise.
	 * 
	 */
	public void testBehaviors1() {
		ShannonsModel model = new ShannonsModel();
		shannonsTheorem = new ShannonsTheorem(model);
		boolean flag = false;
		try {
			shannonsTheorem.setBandwidth(25);
			shannonsTheorem.setSignalToNoise(-0.1);
		} catch (NumberFormatException e) {
			flag = true;
		}
		assertTrue(flag == true);
	}

	/**
	 * Test for negative one of signal to noise. This test will returns negative
	 * infinity.
	 */
	public void testBehaviors2() {
		ShannonsModel model = new ShannonsModel();
		shannonsTheorem = new ShannonsTheorem(model);
		boolean flag = false;
		try {
			shannonsTheorem.setBandwidth(10);
			shannonsTheorem.setSignalToNoise(-1);
		} catch (NumberFormatException e) {

			flag = true;
		}
		assertTrue(flag == true);

	}

	/**
	 * Test behaviors2 for negative value of signal to noise.
	 */
	public void testBehaviors3() {
		ShannonsModel model = new ShannonsModel();
		shannonsTheorem = new ShannonsTheorem(model);
		shannonsTheorem.setBandwidth(25);
		shannonsTheorem.setSignalToNoise(0);
		double expResult3 = 0;
		double result2 = shannonsTheorem.getMaximumDataRate();
		if (Math.abs(expResult3 - result2) > 0.0000000001) {
			fail("the calculation is incorrect");
		}
	}

	public void testBehaviors4() {
		ShannonsModel model = new ShannonsModel();
		shannonsTheorem = new ShannonsTheorem(model);
		DecimalFormat df = new DecimalFormat("######0.00");
		shannonsTheorem.setBandwidth(25);
		shannonsTheorem.setSignalToNoise(10);
		double expResult3 = 86.49;
		double result2 = Double.parseDouble(df.format(shannonsTheorem.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_ShannonsTheorem suite");
		junit.textui.TestRunner.run(suite());
	}

	/*
	 * Attribute
	 */
	private ShannonsTheorem shannonsTheorem = null;

} /* End of CLASS: Test_ShannonsTheorem.java */
