NumericInputParserTest.java 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import org.junit.Assert;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class NumericInputParserTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class NumericInputParserTest
  12. {
  13. @Test
  14. public void testSwitchDisplayMode() {
  15. //:Given
  16. String expected = "bin";
  17. //:When
  18. NumericInputParser p = new NumericInputParser();
  19. p.switchDisplayMode();
  20. String actual = p.getDisplayMode();
  21. //:then
  22. Assert.assertEquals(expected, actual);
  23. }
  24. @Test
  25. public void testSwitchDisplayMode2() {
  26. //:Given
  27. String expected = "hex";
  28. //:When
  29. NumericInputParser p = new NumericInputParser();
  30. p.switchDisplayMode();
  31. p.switchDisplayMode();
  32. String actual = p.getDisplayMode();
  33. //:then
  34. Assert.assertEquals(expected, actual);
  35. }
  36. @Test
  37. public void testSwitchDisplayMode3() {
  38. //:Given
  39. String expected = "oct";
  40. //:When
  41. NumericInputParser p = new NumericInputParser();
  42. p.switchDisplayMode();
  43. p.switchDisplayMode();
  44. p.switchDisplayMode();
  45. String actual = p.getDisplayMode();
  46. //:Then
  47. Assert.assertEquals(expected, actual);
  48. }
  49. @Test
  50. public void testSwitchDisplayMode4() {
  51. //:Given
  52. String expected = "oct";
  53. //:When
  54. NumericInputParser p = new NumericInputParser();
  55. p.switchDisplayMode("oct");
  56. String actual = p.getDisplayMode();
  57. //:Then
  58. Assert.assertEquals(expected, actual);
  59. }
  60. @Test
  61. public void testGetDisplayMode() {
  62. //:Given
  63. String expected = "dec";
  64. //:When
  65. NumericInputParser p = new NumericInputParser();
  66. String actual = p.getDisplayMode();
  67. //:Then
  68. Assert.assertEquals(expected, actual);
  69. }
  70. @Test
  71. public void switchTrigUnitsTest() {
  72. //:Given
  73. String expected = "deg";
  74. //:When
  75. NumericInputParser p = new NumericInputParser();
  76. p.switchUnitsMode();
  77. String actual = p.getTrigUnitsMode();
  78. //:Then
  79. Assert.assertEquals(expected, actual);
  80. }
  81. @Test
  82. public void switchTrigUnitsTest2() {
  83. //:Given
  84. String expected = "deg";
  85. //:When
  86. NumericInputParser p = new NumericInputParser();
  87. p.switchUnitsMode("deg");
  88. String actual = p.getTrigUnitsMode();
  89. //:Then
  90. Assert.assertEquals(expected, actual);
  91. }
  92. @Test
  93. public void getTrigUnitsTest() {
  94. //:Given
  95. String expected = "rad";
  96. //:When
  97. NumericInputParser p = new NumericInputParser();
  98. String actual = p.getTrigUnitsMode();
  99. //:Then
  100. Assert.assertEquals(expected, actual);
  101. }
  102. @Test
  103. public void getDoubleTestDec() {
  104. //:Given
  105. Double expected = 1.298;
  106. //:When
  107. NumericInputParser p = new NumericInputParser();
  108. p.switchDisplayMode("dec");
  109. Double actual = p.getDouble("1.298");
  110. //:Then
  111. Assert.assertEquals(expected, actual);
  112. }
  113. @Test
  114. public void getDoubleTestBin() {
  115. //:Given
  116. Double expected = 3.0;
  117. //:When
  118. NumericInputParser p = new NumericInputParser();
  119. p.switchDisplayMode("bin");
  120. Double actual = p.getDouble("11");
  121. //:then
  122. Assert.assertEquals(expected, actual);
  123. }
  124. @Test
  125. public void getDoubleTestHex() {
  126. //:Given
  127. Double expected = 31.0;
  128. //:When
  129. NumericInputParser p = new NumericInputParser();
  130. p.switchDisplayMode("hex");
  131. Double actual = p.getDouble("1f");
  132. //:Then
  133. Assert.assertEquals(expected, actual);
  134. }
  135. @Test
  136. public void getDoubleTestOct() {
  137. //:Given
  138. Double expected = 8.0;
  139. //:When
  140. NumericInputParser p = new NumericInputParser();
  141. p.switchDisplayMode("oct");
  142. Double actual = p.getDouble("10");
  143. //:Then
  144. Assert.assertEquals(expected, actual);
  145. }
  146. @Test
  147. public void getFormattedTestDec() {
  148. //:Given
  149. String expected = "11.0000000";
  150. //:When
  151. NumericInputParser p = new NumericInputParser();
  152. String actual = p.getFormattedNumber(11.0);
  153. //:Then
  154. Assert.assertEquals(expected, actual);
  155. }
  156. @Test
  157. public void getFormattedTestBin() {
  158. //Given
  159. String expected = "11";
  160. //:When
  161. NumericInputParser p = new NumericInputParser();
  162. p.switchDisplayMode("bin");
  163. String actual = p.getFormattedNumber(3.0);
  164. //:Then
  165. Assert.assertEquals(expected, actual);
  166. }
  167. @Test
  168. public void getFormattedTestHex() {
  169. //Given
  170. String expected = "f";
  171. //:When
  172. NumericInputParser p = new NumericInputParser();
  173. p.switchDisplayMode("hex");
  174. String actual = p.getFormattedNumber(15);
  175. //:Then
  176. Assert.assertEquals(expected, actual);
  177. }
  178. @Test
  179. public void getFormattedTestOct() {
  180. //Given
  181. String expected = "11";
  182. //:When
  183. NumericInputParser p = new NumericInputParser();
  184. p.switchDisplayMode("oct");
  185. String actual = p.getFormattedNumber(9);
  186. //:Then
  187. Assert.assertEquals(expected, actual);
  188. }
  189. @Test
  190. public void getAngleTestRad() {
  191. //Given
  192. Double expected = 0.2;
  193. //:When
  194. NumericInputParser p = new NumericInputParser();
  195. p.switchUnitsMode("rad");
  196. Double actual = p.getAngle("0.2");
  197. //:Then
  198. Assert.assertEquals(expected, actual);
  199. }
  200. @Test
  201. public void getAngleTestDeg() {
  202. //Given
  203. Double expected = 90 * (Math.PI/180);
  204. //:When
  205. NumericInputParser p = new NumericInputParser();
  206. p.switchUnitsMode("deg");
  207. Double actual = p.getAngle("90");
  208. //:Then
  209. Assert.assertEquals(expected, actual);
  210. }
  211. @Test
  212. public void getFormattedAngleRad() {
  213. //:Given
  214. String expected = "2.0000000";
  215. //:When
  216. NumericInputParser p = new NumericInputParser();
  217. String actual = p.getFormattedAngle(2.0);
  218. //:Then
  219. Assert.assertEquals(expected, actual);
  220. }
  221. @Test
  222. public void getFormattedAngleDeg() {
  223. //:Given
  224. String expected = "90.0000000";
  225. //:When
  226. NumericInputParser p = new NumericInputParser();
  227. p.switchUnitsMode("deg");
  228. String actual = p.getFormattedAngle(Math.PI/2);
  229. //:Then
  230. Assert.assertEquals(expected, actual);
  231. }
  232. }