123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
-
-
- import org.junit.Assert;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
-
- /**
- * The test class NumericInputParserTest.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class NumericInputParserTest
- {
- @Test
- public void testSwitchDisplayMode() {
- //:Given
- String expected = "bin";
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchDisplayMode();
- String actual = p.getDisplayMode();
- //:then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void testSwitchDisplayMode2() {
- //:Given
- String expected = "hex";
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchDisplayMode();
- p.switchDisplayMode();
- String actual = p.getDisplayMode();
- //:then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void testSwitchDisplayMode3() {
- //:Given
- String expected = "oct";
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchDisplayMode();
- p.switchDisplayMode();
- p.switchDisplayMode();
- String actual = p.getDisplayMode();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void testSwitchDisplayMode4() {
- //:Given
- String expected = "oct";
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchDisplayMode("oct");
- String actual = p.getDisplayMode();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void testGetDisplayMode() {
- //:Given
- String expected = "dec";
- //:When
- NumericInputParser p = new NumericInputParser();
- String actual = p.getDisplayMode();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void switchTrigUnitsTest() {
- //:Given
- String expected = "deg";
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchUnitsMode();
- String actual = p.getTrigUnitsMode();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void switchTrigUnitsTest2() {
- //:Given
- String expected = "deg";
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchUnitsMode("deg");
- String actual = p.getTrigUnitsMode();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getTrigUnitsTest() {
- //:Given
- String expected = "rad";
- //:When
- NumericInputParser p = new NumericInputParser();
- String actual = p.getTrigUnitsMode();
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getDoubleTestDec() {
- //:Given
- Double expected = 1.298;
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchDisplayMode("dec");
- Double actual = p.getDouble("1.298");
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getDoubleTestBin() {
- //:Given
- Double expected = 3.0;
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchDisplayMode("bin");
- Double actual = p.getDouble("11");
- //:then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getDoubleTestHex() {
- //:Given
- Double expected = 31.0;
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchDisplayMode("hex");
- Double actual = p.getDouble("1f");
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getDoubleTestOct() {
- //:Given
- Double expected = 8.0;
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchDisplayMode("oct");
- Double actual = p.getDouble("10");
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getFormattedTestDec() {
- //:Given
- String expected = "11.0000000";
- //:When
- NumericInputParser p = new NumericInputParser();
- String actual = p.getFormattedNumber(11.0);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getFormattedTestBin() {
- //Given
- String expected = "11";
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchDisplayMode("bin");
- String actual = p.getFormattedNumber(3.0);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getFormattedTestHex() {
- //Given
- String expected = "f";
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchDisplayMode("hex");
- String actual = p.getFormattedNumber(15);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getFormattedTestOct() {
- //Given
- String expected = "11";
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchDisplayMode("oct");
- String actual = p.getFormattedNumber(9);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getAngleTestRad() {
- //Given
- Double expected = 0.2;
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchUnitsMode("rad");
- Double actual = p.getAngle("0.2");
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getAngleTestDeg() {
- //Given
- Double expected = 90 * (Math.PI/180);
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchUnitsMode("deg");
- Double actual = p.getAngle("90");
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getFormattedAngleRad() {
- //:Given
- String expected = "2.0000000";
- //:When
- NumericInputParser p = new NumericInputParser();
- String actual = p.getFormattedAngle(2.0);
- //:Then
- Assert.assertEquals(expected, actual);
- }
- @Test
- public void getFormattedAngleDeg() {
- //:Given
- String expected = "90.0000000";
- //:When
- NumericInputParser p = new NumericInputParser();
- p.switchUnitsMode("deg");
- String actual = p.getFormattedAngle(Math.PI/2);
- //:Then
- Assert.assertEquals(expected, actual);
- }
-
- }
|