Skip to content
Snippets Groups Projects
Commit 1544b464 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Added test demo starter code

parent 9ed15553
No related branches found
No related tags found
No related merge requests found
package edu.unl.edu.soft160.testDemo;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
package edu.unl.edu.soft160.testDemo;
import java.util.Scanner;
public class TestDemoTarget {
public static int getMaximum(int firstValue, int secondValue) {
int returnValue = Integer.MIN_VALUE;
if (firstValue > secondValue) {
returnValue = firstValue;
} else if (secondValue > firstValue) {
returnValue = secondValue;
}
return returnValue;
}
public static double getMaximum(double firstValue, double secondValue) {
double returnValue = Double.NaN;
if (firstValue > secondValue) {
returnValue = firstValue;
} else if (secondValue > firstValue) {
returnValue = secondValue;
}
return returnValue;
}
public static double multiplyByTen(double multiplicand) {
double multiplier = 0.0;
for (int i = 0; i < 100; i++) {
multiplier += 0.1;
}
return multiplicand * multiplier;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter first value: ");
double firstValue = Double.valueOf(scanner.nextLine());
System.out.print("Enter secondValue: ");
double secondValue = Double.valueOf(scanner.nextLine());
scanner.close();
System.out.println(
"The maximum of " + firstValue + " and " + secondValue + " is " + getMaximum(firstValue, secondValue));
System.out.println("Multiplying " + firstValue + " ⨉ 10 = " + multiplyByTen(firstValue));
System.out.println("Multiplying " + secondValue + " ⨉ 10 = " + multiplyByTen(secondValue));
}
}
package edu.unl.edu.soft160.testDemo;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
package edu.unl.edu.soft160.testDemo;
import org.junit.Test;
import static org.junit.Assert.*;
public class TestDemoTests {
@Test
public void testIntegerFirstValueIsGreater() {
// arrange
int firstValue = 3;
int secondValue = 5;
int expectedResult = 5;
// act
int actualResult = TestDemoTarget.getMaximum(firstValue, secondValue);
// assert
assertEquals(expectedResult, actualResult);
}
@Test
public void testDoubleFirstValueIsGreater() {
// arrange
double firstValue = 3.5;
double secondValue = 5.2;
double expectedResult = 5.2;
// act
double actualResult = TestDemoTarget.getMaximum(firstValue, secondValue);
// assert
assertEquals(expectedResult, actualResult, 0.0);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment