CalculationsTest.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class CalculationsTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class CalculationsTest
  12. {
  13. @Test
  14. public void testSquare(){
  15. // set up data
  16. double x = 3.0;
  17. //invoke method under test
  18. double actualResult = Calculations.square(x);
  19. //verify result
  20. double expectResult = 9.0;
  21. assertEquals(expectResult, actualResult, 0.001);
  22. }
  23. @Test
  24. public void testsquareroot(){
  25. double x = 25.0;
  26. double actualResult = Calculations.squareroot(x);
  27. double expectResult = 5.0;
  28. assertEquals(expectResult, actualResult, 0.001);
  29. }
  30. @Test
  31. public void testinverse(){
  32. double x = 2;
  33. double actualResult = Calculations.inverse(x);
  34. double expectResult = 0.5;
  35. assertEquals(expectResult, actualResult, 0.001);
  36. }
  37. @Test
  38. public void testinvert(){
  39. double x = 12.0;
  40. double actualResult = Calculations.invert(x);
  41. double expectResult = -12.0;
  42. assertEquals(expectResult, actualResult, 0.001);
  43. }
  44. @Test
  45. public void testfindSin(){
  46. double x = 90.0;
  47. double actualResult = Calculations.findSin(x);
  48. double expectResult = 0.8939966636;
  49. assertEquals(expectResult, actualResult, 0.001);
  50. }
  51. @Test
  52. public void testfindCos(){
  53. double x = 45.0;
  54. double actualResult = Calculations.findCos(x);
  55. double expectResult = 0.52532198881;
  56. assertEquals(expectResult, actualResult, 0.001);
  57. }
  58. @Test
  59. public void testfindTan(){
  60. double x = 100.0;
  61. double actualResult = Calculations.findTan(x);
  62. double expectResult = -0.58721391515;
  63. assertEquals(expectResult, actualResult, 0.001);
  64. }
  65. @Test
  66. public void testfindAsin(){
  67. double x = 0.5;
  68. double actualResult = Calculations.findAsin(x);
  69. double expectResult = 0.52359877559;
  70. assertEquals(expectResult, actualResult, 0.001);
  71. }
  72. @Test
  73. public void testfindAcos(){
  74. double x = 1.0;
  75. double actualResult = Calculations.findAcos(x);
  76. double expectResult = 0;
  77. assertEquals(expectResult, actualResult, 0.001);
  78. }
  79. @Test
  80. public void testfindAtan(){
  81. double x = 1.0;
  82. double actualResult = Calculations.findAtan(x);
  83. double expectResult = 0.78539816339;
  84. assertEquals(expectResult, actualResult, 0.001);
  85. }
  86. @Test
  87. public void testAddition()
  88. {
  89. assertEquals(20.0, Calculations.addition(15, 5), 0.1);
  90. }
  91. @Test
  92. public void testSubstraction()
  93. {
  94. assertEquals(3.0, Calculations.subtraction(5, 2), 0.1);
  95. }
  96. @Test
  97. public void testMultiplication(){
  98. assertEquals(6.0, Calculations.multiplication(3, 2), 0.1);
  99. }
  100. @Test
  101. public void testDivision()
  102. {
  103. assertEquals(3.0, Calculations.division(6, 2), 0.1);
  104. }
  105. @Test
  106. public void testExponent()
  107. {
  108. assertEquals(64.0, Calculations.exponent(4, 3), 0.1);
  109. }
  110. }