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