1 package org.djunits.unit;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4 import static org.junit.jupiter.api.Assertions.assertTrue;
5
6 import java.util.Locale;
7
8 import org.djunits.unit.unitsystem.UnitSystem;
9 import org.junit.jupiter.api.BeforeEach;
10 import org.junit.jupiter.api.Test;
11
12
13
14
15
16
17
18
19 public class PositionUnitTest extends AbstractOffsetUnitTest<PositionUnit>
20 {
21
22
23
24 @BeforeEach
25 public final void setup()
26 {
27 Locale.setDefault(new Locale("en"));
28 }
29
30
31
32
33 @Test
34 public final void conversions()
35 {
36 assertEquals("m", PositionUnit.DEFAULT.getQuantity().getSiDimensions().toString(true, false));
37 checkUnitRatioOffsetNameAndAbbreviation(PositionUnit.METER, 1, 0.0, 0.00000001, "meter", "m");
38 checkUnitRatioOffsetNameAndAbbreviation(PositionUnit.MILE, 1609.34, 0.0, 0.05, "mile", "mi");
39 checkUnitRatioOffsetNameAndAbbreviation(PositionUnit.FOOT, 0.3048, 0.0, 0.001, "foot", "ft");
40
41 assertEquals(0.3048, getMultiplicationFactorTo(PositionUnit.FOOT, PositionUnit.METER), 0.0001,
42 "one FOOT is 0.3048 METER");
43 assertEquals(9.461E12, getMultiplicationFactorTo(PositionUnit.LIGHTYEAR, PositionUnit.KILOMETER), 1E9,
44 "one LIGHTYEAR is about 9.461E12 KILOMETER");
45
46
47 }
48
49
50
51
52 @Test
53 public final void createPositionUnit()
54 {
55 PositionUnit myUnit =
56 PositionUnit.DEFAULT.deriveLinearOffset(1.23, 0.0, LengthUnit.METER, "my", "myPosition", UnitSystem.OTHER);
57 assertTrue(null != myUnit, "Can create a new PositionUnit");
58 checkUnitRatioOffsetNameAndAbbreviation(myUnit, 1.23, 0.0, 0.0001, "myPosition", "my");
59 PositionUnit.BASE.unregister(myUnit);
60 }
61
62
63
64
65 @Test
66 public final void testRelative()
67 {
68 assertEquals(LengthUnit.BASE, PositionUnit.DEFAULT.getRelativeQuantity());
69 }
70
71 }