use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.
the class FormatOptionHandlerTest method testHexFormat.
@Test
public void testHexFormat() throws Exception {
VType number = ValueFactory.newVDouble(65535.0, display);
String text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true);
System.out.println(text);
assertThat(text, equalTo("0xFFFF V"));
text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true);
System.out.println(text);
assertThat(text, equalTo("0x0000FFFF V"));
text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true);
System.out.println(text);
assertThat(text, equalTo("0x000000000000FFFF V"));
}
use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.
the class FormatOptionHandlerTest method testNumberArrayParsing.
@Test
public void testNumberArrayParsing() throws Exception {
final ListNumber data = new ArrayDouble(1.0, 2.0, 3.0, 4.0);
final VType value = ValueFactory.newVNumberArray(data, ValueFactory.alarmNone(), ValueFactory.timeNow(), display);
Object parsed = FormatOptionHandler.parse(value, " [ 1, 2.5 , 3 ] ", FormatOption.DEFAULT);
assertThat(parsed, instanceOf(double[].class));
final double[] numbers = (double[]) parsed;
assertThat(numbers, equalTo(new double[] { 1.0, 2.5, 3.0 }));
}
use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.
the class FormatOptionHandlerTest method testExponential.
@Test
public void testExponential() throws Exception {
VType number = ValueFactory.newVDouble(3.16, display);
String text = FormatOptionHandler.format(number, FormatOption.DEFAULT, -1, true);
System.out.println(text);
assertThat(text, equalTo("3.160 V"));
text = FormatOptionHandler.format(number, FormatOption.EXPONENTIAL, 3, true);
System.out.println(text);
assertThat(text, equalTo("3.160E0 V"));
text = FormatOptionHandler.format(number, FormatOption.EXPONENTIAL, 1, true);
System.out.println(text);
assertThat(text, equalTo("3.2E0 V"));
}
use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.
the class FormatOptionHandlerTest method testSexagesimalFormat.
@Test
public void testSexagesimalFormat() throws Exception {
final VType sexaPositiveValue = ValueFactory.newVDouble(12.5824414), sexaNegativeValue = ValueFactory.newVDouble(-12.5824414), sexaRoundedValue = ValueFactory.newVDouble(12.9999999);
assertThat(FormatOptionHandler.format(sexaPositiveValue, FormatOption.SEXAGESIMAL, 7, false), equalTo("12:34:56.789"));
assertThat(FormatOptionHandler.format(sexaPositiveValue, FormatOption.SEXAGESIMAL, 2, false), equalTo("12:35"));
assertThat(FormatOptionHandler.format(sexaPositiveValue, FormatOption.SEXAGESIMAL, 4, false), equalTo("12:34:57"));
assertThat(FormatOptionHandler.format(sexaNegativeValue, FormatOption.SEXAGESIMAL, 7, false), equalTo("-12:34:56.789"));
assertThat(FormatOptionHandler.format(sexaRoundedValue, FormatOption.SEXAGESIMAL, 7, false), equalTo("13:00:00.000"));
assertThat(FormatOptionHandler.format(sexaRoundedValue, FormatOption.SEXAGESIMAL, 8, false), equalTo("12:59:59.9996"));
assertThat(FormatOptionHandler.format(ValueFactory.newVDouble(2 * Math.PI), FormatOption.SEXAGESIMAL_HMS, 7, false), equalTo("24:00:00.000"));
assertThat(FormatOptionHandler.format(sexaPositiveValue, FormatOption.SEXAGESIMAL_HMS, 7, false), equalTo("48:03:40.989"));
assertThat(FormatOptionHandler.format(sexaNegativeValue, FormatOption.SEXAGESIMAL_HMS, 7, false), equalTo("-48:03:40.989"));
assertThat(FormatOptionHandler.format(ValueFactory.newVDouble(2 * Math.PI), FormatOption.SEXAGESIMAL_DMS, 7, false), equalTo("360:00:00.000"));
assertThat(FormatOptionHandler.format(sexaPositiveValue, FormatOption.SEXAGESIMAL_DMS, 7, false), equalTo("720:55:14.837"));
assertThat(FormatOptionHandler.format(sexaNegativeValue, FormatOption.SEXAGESIMAL_DMS, 7, false), equalTo("-720:55:14.837"));
assertThat(FormatOptionHandler.format(sexaRoundedValue, FormatOption.SEXAGESIMAL_DMS, 7, false), equalTo("744:50:42.461"));
}
use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.
the class FormatOptionHandlerTest method testArray.
@Test
public void testArray() throws Exception {
final ListNumber data = new ArrayDouble(1.0, 2.0, 3.0, 4.0);
VType value = ValueFactory.newVNumberArray(data, ValueFactory.alarmNone(), ValueFactory.timeNow(), display);
System.out.println(value);
String text = FormatOptionHandler.format(value, FormatOption.DEFAULT, 0, true);
System.out.println(text);
assertThat(text, equalTo("[1, 2, 3, 4] V"));
text = FormatOptionHandler.format(value, FormatOption.DECIMAL, 2, true);
System.out.println(text);
assertThat(text, equalTo("[1.00, 2.00, 3.00, 4.00] V"));
}
Aggregations