123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
-
-
- import static org.junit.Assert.*;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
-
- /**
- * The test class MathUtilitiesTest.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class MathUtilitiesTest
- {
- private MathUtilities primativeTypes;
-
- /**
- * Sets up the test fixture.
- *
- * Called before every test case method.
- */
- @Before
- public void setUp(){
- primativeTypes = new MathUtilities();
- }
-
- /**
- * Tears down the test fixture.
- *
- * Called after every test case method.
- */
- @After
- public void tearDown()
- {
- }
-
-
-
- @Test
- public void testAdditions() {
- // : Given
- int baseValue = 20;
- int addedValue = 7;
- int expected = 27;
- // : When
- int actual = primativeTypes.add(baseValue, addedValue);
- // : Then
- assertEquals(expected,actual);
- }
- @Test
- public void testAdditions1() {
- // : Given
- long baseValue = 228437266;
- long difference = 228437265;
- long expected = 456874531;
- // : When
- long actual = primativeTypes.add(baseValue, difference);
- // : Then
- assertEquals(expected,actual);
- }
- @Test
- public void testAdditions2() {
- // : Given
- short baseValue = 16384;
- short addedValue = 7;
- short expected = 16391;
- // : When
- short actual = primativeTypes.add(baseValue, addedValue);
- // : Then
- assertEquals(expected,actual);
- }
-
- @Test
- public void testAdditions4() {
- // : Given
- byte baseValue = 63;
- byte addedValue = 64;
- byte expected = 127;
- // : When
- byte actual = primativeTypes.add(baseValue, addedValue);
- // : Then
- assertEquals(expected,actual);
- }
- @Test
- public void testAdditions5() {
- // : Given
- float baseValue = 750.585F;
- float addedValue = 795.000F;
- float expected = 1545.585F;
- // : When
- float actual = primativeTypes.add(baseValue, addedValue);
- // : Then
- assertEquals(expected,actual, 0);
- }
-
- @Test
- public void testAdditions6() {
- // : Given
- double baseValue = 225.25;
- double addedValue = 231;
- double expected = 456.25;
- // : When
- double actual = primativeTypes.add(baseValue,addedValue);
- // : Then
- assertEquals(expected,actual, 0);
- }
-
- @Test
- public void testSubtractions(){
- // : Given
- int baseValue = 20;
- int difference = 7;
- int expectedInt = 13;
- // : When
- int actualInt = primativeTypes.subtract(baseValue,difference);
- // : Then
- assertEquals(expectedInt,actualInt);
- }
- @Test
- public void testSubtractions1() {
- // : Given
- long baseValue = 228437266;
- long difference = 228437265;
- long expectedLong = 1;
- // : When
- long actualLong = primativeTypes.subtract(baseValue, difference);
- // : Then
- assertEquals(expectedLong,actualLong);
- }
- @Test
- public void testSubtractions2() {
- // : Given
- short baseValue = 16384;
- short difference = 16383;
- short expectedShort = 1;
- // : When
- short actualShort = primativeTypes.subtract(baseValue, difference);
- // : Then
- assertEquals(expectedShort,actualShort);
- }
- @Test
- public void testSubtractions3() {
- // : Given
- byte baseValue = 63;
- byte difference = 64;
- byte expectedByte = -1;
- // : When
- byte actualByte = primativeTypes.subtract(baseValue, difference);
- // : Then
- assertEquals(expectedByte,actualByte);
- }
- @Test
- public void testSubtractions4() {
- // : Given
- float baseValue = 750.585F;
- float difference = 795.0F;
- float expectedFloat = -44.415F;
- // : When
- float actualFloat = primativeTypes.subtract(baseValue,difference);
- // : Then
- assertEquals(expectedFloat,actualFloat, 0.005);
- }
- @Test
- public void testSubtractions5() {
- // : Given
- double baseValue = 225.25;
- double difference = 231;
- double expectedDouble = -5.75;
- // : When
- double actualDouble = primativeTypes.subtract(baseValue, difference);
- // : Then
- assertEquals(expectedDouble,actualDouble, 0);
- }
-
- @Test
- public void testDivision(){
- // : Given
- int dividend = 20;
- int divisor = 2;
- int expectedInt = 10;
- // : When
- int actualInt = primativeTypes.divide(dividend, divisor);
- // : Then
- assertEquals(expectedInt,actualInt);
- }
- @Test
- public void testDivision1() {
- // : Given
- int dividend = 20000000;
- int divisor = 1000;
- long expectedLong = 20000;
- // : When
- long actualLong = primativeTypes.divide(dividend, divisor);
- // : Then
- assertEquals(expectedLong,actualLong);
- }
- @Test
- public void testDivision2() {
- // : Given
- short dividend = 2;
- short divisor = 1;
- short expectedShort = 2;
- // : When
- short actualShort = primativeTypes.divide(dividend, divisor);
- // : Then
- assertEquals(expectedShort,actualShort);
-
- }
- @Test
- public void testDivision3() {
- // : Given
- byte dividend = 64;
- byte divisor = 32;
- byte expectedByte = 2;
- // : When
- byte actualByte = primativeTypes.divide(dividend, divisor);
- // : Then
- assertEquals(expectedByte,actualByte);
- }
- @Test
- public void testDivision4() {
- // : Given
- float dividend = 7.5F;
- float divisor = 3;
- float expectedFloat = 2.50F;
- // : When
- float actualFloat = primativeTypes.divide(dividend,divisor);
- // : Then
- assertEquals(expectedFloat,actualFloat, 0);
- }
- @Test
- public void testDivision5() {
- // : Given
- double dividend = 5.0;
- double divisor = 4.0;
- double expectedDouble = 1.25;
- // : When
- double actualDouble = primativeTypes.divide(dividend,divisor);
- // : Then
- assertEquals(expectedDouble,actualDouble, 0);
- }
-
- @Test
- public void testMultiplication(){
- // : Given
- int multiplicand = 5;
- int multiplier = 2;
- int expectedInt = 10;
- // : When
- int actualInt = primativeTypes.multiply(multiplicand,multiplier);
- // : Then
- assertEquals(expectedInt,actualInt);
- }
- @Test
- public void testMultiplication1() {
- // : Given
- long multiplicand = 20;
- long multiplier = 1000;
- long expectedLong = 20000;
- // : When
- long actualLong = primativeTypes.multiply(multiplicand, multiplier);
- // : Then
- assertEquals(expectedLong, actualLong);
- }
- @Test
- public void testMultiplication2() {
- // : Given
- short multiplicand = 2;
- short multiplier = 1;
- short expectedShort = 2;
- // : When
- short actualShort = primativeTypes.multiply(multiplicand, multiplier);
- // : Then
- assertEquals(expectedShort, actualShort);
- }
- @Test
- public void testMultiplication3() {
- // : Given
- byte multiplicand = 16;
- byte multiplier = 14;
- byte expectedByte = -32;
- // : When
- byte actualByte = primativeTypes.multiply(multiplicand, multiplier);
- // : Then
- assertEquals(expectedByte, actualByte);
- }
- @Test
- public void testMultiplication4() {
- // : Given
- float multiplicand = 2.5F;
- float multiplier = 1;
- float expectedFloat = 2.50F;
- // : When
- float actualFloat = primativeTypes.multiply(multiplicand,multiplier);
- // : Then
- assertEquals(expectedFloat, actualFloat, 0);
- }
- @Test
- public void testMultiplication5() {
- // : Given
- double multiplicand = 3.25;
- double multiplier = 3.0;
- double expectedDouble = 9.75;
- // : When
- double actualDouble = primativeTypes.multiply(multiplicand,multiplier);
- // : Then
- assertEquals(expectedDouble, actualDouble, 0);
- }
-
- @Test
- public void testReturnTrue(){
- // : Given
- // : When
- // : Then
- assertTrue(primativeTypes.returnTrue());
- }
-
- @Test
- public void testReturnFalse(){
- // : Given
- // : When
- // : Then
- assertFalse(primativeTypes.returnFalse());
- }
-
- }
|