Created
October 4, 2013 23:11
-
-
Save Mamunahmed33/6834367 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.univDhaka.iit.CalculatorMain; | |
public class Calculator { | |
public int add(int a, int b){ | |
return a+b; | |
} | |
public int subtract(int a, int b){ | |
return a-b; | |
} | |
public int multiple(int a, int b){ | |
return a*b; | |
} | |
public float divide(int a, int b){ | |
return a/b; | |
} | |
public float squireRoot(float a){ | |
return (float)Math.sqrt(a); | |
} | |
public float remainder(int a, int b){ | |
return a%b; | |
} | |
public double power(double a, double b){ | |
return Math.pow(a, b); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.univDhaka.iit.CalculatorTesting; | |
import static org.junit.Assert.*; | |
import junit.framework.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
import edu.univDhaka.iit.CalculatorMain.Calculator; | |
public class CalculatorTest { | |
private Calculator calculator; | |
@Before | |
public void setUp() throws Exception { | |
calculator = new Calculator(); | |
} | |
@Test | |
public void testAdd() { | |
int a = 10; | |
int b = 15; | |
int result = 25; | |
Assert.assertEquals(result, calculator.add(a, b)); | |
} | |
@Test | |
public void testSubtract(){ | |
int a = 100; | |
int b = 50; | |
int result = 50; | |
Assert.assertEquals(result, calculator.subtract(a, b)); | |
} | |
@Test | |
public void testMultiple(){ | |
int a = 5; | |
int b = 5; | |
int result = 25; | |
Assert.assertEquals(result, calculator.multiple(a, b)); | |
} | |
@Test | |
public void testDivide(){ | |
int a = 25; | |
int b = 5; | |
float result = (float) 5.0; | |
Assert.assertEquals(result, calculator.divide(a, b)); | |
} | |
@Test | |
public void testPower(){ | |
int a = 5; | |
int b = 2; | |
double result = 25.0; | |
Assert.assertEquals(result, calculator.power(a, b)); | |
} | |
@Test | |
public void testRemainder(){ | |
int a = 26; | |
int b = 5; | |
float result = (float) 1.0; | |
Assert.assertEquals(result, calculator.remainder(a, b)); | |
} | |
@Test | |
public void testSquireRoot(){ | |
float a = 25; | |
float result = 5; | |
Assert.assertEquals(result, calculator.squireRoot(a)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment