123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
-
-
- import org.junit.Assert;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
-
- /**
- * The test class CalculatorTest.
- *
- * Allison & Alfredo
- * 5/25/2018
- *
- */
- public class CalculatorTest
- {
- @Test
- public void memSetTest(){
- //:Given
- Double expected = 2.0;
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(2);
- Double actual = c.memSet();
- //:Then
- Assert.assertEquals(expected, actual);
-
- }
- @Test
- public void memClearTest(){
- //:Given
- Double expected = 0.0;
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(2);
- c.memSet();
- Double actual = c.memClear();
- //:Then
- Assert.assertEquals(expected, actual);
-
- }
- @Test
- public void additionTest(){
- //:Given
- Double expected = 3.0;
- //:When
- Calculator c = new Calculator();
- Double actual = c.add(3);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void subtractionTest(){
- //:Given
- Double expected = 1.0;
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(4);
- Double actual = c.subtract(3);
- //Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void mutliplicationTest(){
- //:Given
- Double expected = 6.0;
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(3);
- Double actual = c.multiply(2);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void divisionTest(){
- //:Given
- Double expected = 0.75;
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(3);
- Double actual = c.divide(4);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void powTest(){
- //:Given
- Double expected = 8.0;
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(2);
- Double actual = c.pow(3);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void squareTest(){
- //:Given
- Double expected = 225.0;
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(15);
- Double actual = c.square();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void sqrtTest(){
- //:Given
- Double expected = 15.0;
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(225);
- Double actual = c.squareRoot();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void inverseTest() {
- //:Given
- Double expected = 1.0 / 5.0;
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(5);
- Double actual = c.inverse();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void sinTest() {
- //:Given
- Double expected = Math.sin(Math.PI);
- //:When
- Calculator c = new Calculator();
- Double actual = c.sin(Math.PI);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void cosTest() {
- //:Given
- Double expected = Math.cos(Math.PI);
- //:When
- Calculator c = new Calculator();
- Double actual = c.cos(Math.PI);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void tanTest() {
- //:Given
- Double expected = Math.tan(Math.PI);
- //:When
- Calculator c = new Calculator();
- Double actual = c.tan(Math.PI);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void inverseSinTest() {
- //:Given
- Double expected = Math.asin(.2);
- //:When
- Calculator c = new Calculator();
- Double actual = c.inverseSin(.2);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void inverseCosTest() {
- //:Given
- Double expected = Math.acos(.2);
- //:When
- Calculator c = new Calculator();
- Double actual = c.inverseCos(.2);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void inverseTanTest() {
- //:Given
- Double expected = Math.atan(.2);
- //:When
- Calculator c = new Calculator();
- Double actual = c.inverseTan(.2);
- //:then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void logTest() {
- //:Given
- Double expected = Math.log(5);
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(5);
- Double actual = c.log();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void inverseLogTest() {
- //:Given
- Double expected = Math.pow(100, 10);
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(100);
- Double actual = c.inverseLog();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void naturalLogTest() {
- //:Given
- Double expected = Math.log1p(20);
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(20);
- Double actual = c.naturalLog();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void inverseLnTest() {
- //:Given
- Double expected = Math.pow(Math.E, 5);
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(5);
- Double actual = c.inverseLn();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void factorialTest() {
- //:Given
- Double expected = 120.0;
- //:When
- Calculator c = new Calculator();
- c.setDisplayValue(5);
- Double actual = c.factorial();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- }
|