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 AngleUnitTest extends AbstractLinearUnitTest<AngleUnit>
20 {
21
22
23
24 @BeforeEach
25 public final void setup()
26 {
27 Locale.setDefault(new Locale("en"));
28 }
29
30
31
32
33
34
35
36
37
38 protected final void checkUnitValueNameAndAbbreviation(final AngleUnit au, final double expectedValue,
39 final double precision, final String expectedName, final String expectedAbbreviation)
40 {
41 assertEquals("rad", AngleUnit.SI.getQuantity().getSiDimensions().toString(true, false));
42 assertEquals(expectedValue, au.getScale().toStandardUnit(1.0), precision,
43 String.format("one %s is about %f reference unit", au.getId(), expectedValue));
44 assertEquals(expectedName, au.getName(), String.format("Name of %s is %s", au.getId(), expectedName));
45 assertEquals(expectedAbbreviation, au.getDefaultDisplayAbbreviation(),
46 String.format("Abbreviation of %s is %s", au.getId(), expectedAbbreviation));
47 }
48
49
50
51
52 @Test
53 public final void conversions()
54 {
55 checkUnitValueNameAndAbbreviation(AngleUnit.DEGREE, 2 * Math.PI / 360, 0.000001, "degree", "\u00b0");
56 checkUnitValueNameAndAbbreviation(AngleUnit.ARCMINUTE, 2 * Math.PI / 360 / 60, 0.0001, "arcminute", "\'");
57 checkUnitValueNameAndAbbreviation(AngleUnit.GRAD, 2 * Math.PI / 400, 0.00001, "gradian", "grad");
58
59 assertEquals(54, getMultiplicationFactorTo(AngleUnit.GRAD, AngleUnit.ARCMINUTE), 0.5, "one GRAD is about 54 ARCMINUTE");
60 assertEquals(0.0185, getMultiplicationFactorTo(AngleUnit.ARCMINUTE, AngleUnit.GRAD), 0.0001,
61 "one ARCMINUTE is about 0.0185 GRAD");
62
63 checkUnitValueNameAndAbbreviation(AngleUnit.CENTESIMAL_ARCMINUTE, 0.00015708, 0.0000001, "centesimal arcminute", "c\'");
64 checkUnitValueNameAndAbbreviation(AngleUnit.CENTESIMAL_ARCSECOND, 1.57079e-6, 0.1, "centesimal arcsecond", "c\"");
65 checkUnitValueNameAndAbbreviation(AngleUnit.PERCENT, 0.0099996667, 0.0001, "percent", "%");
66 }
67
68
69
70
71 @Test
72 public final void createAngleUnit()
73 {
74 AngleUnit myAPU = AngleUnit.RADIAN.deriveLinear(0.19634954085, "pt", "point", UnitSystem.OTHER);
75 assertTrue(null != myAPU, "Can create a new AngleUnit");
76 checkUnitValueNameAndAbbreviation(myAPU, 0.19634954085, 0.0000001, "point", "pt");
77 AngleUnit.BASE.unregister(myAPU);
78 }
79
80 }