1 package org.djunits.value.vdouble.scalar;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4
5 import org.djunits.unit.AccelerationUnit;
6 import org.djunits.unit.AngleUnit;
7 import org.djunits.unit.AreaUnit;
8 import org.djunits.unit.DimensionlessUnit;
9 import org.djunits.unit.DirectionUnit;
10 import org.djunits.unit.LengthUnit;
11 import org.djunits.unit.SolidAngleUnit;
12 import org.djunits.unit.Unit;
13 import org.djunits.value.vdouble.scalar.base.DoubleScalar;
14 import org.junit.jupiter.api.Test;
15
16
17
18
19
20
21
22
23
24
25 public class DoubleScalarInstantiateTest
26 {
27
28
29
30 @Test
31 public final void instantiateTest()
32 {
33 Dimensionless dimensionless = DoubleScalar.instantiate(10.0, DimensionlessUnit.SI);
34 assertEquals(10.0, dimensionless.getSI(), 0.0001d, "Dimensionless");
35
36 Acceleration acceleration = DoubleScalar.instantiate(10.0, AccelerationUnit.SI);
37 assertEquals(10.0, acceleration.getSI(), 0.0001d, "Acceleration");
38 acceleration = DoubleScalar.instantiate(12960.0, AccelerationUnit.KM_PER_HOUR_2);
39 assertEquals(1.0, acceleration.getSI(), 0.001d, "Acceleration");
40
41 SolidAngle angleSolid = DoubleScalar.instantiate(10.0, SolidAngleUnit.SI);
42 assertEquals(10.0, angleSolid.getSI(), 0.0001d, "SolidAngle");
43 angleSolid = DoubleScalar.instantiate(1.0, SolidAngleUnit.SQUARE_DEGREE);
44 assertEquals((Math.PI / 180.0) * (Math.PI / 180.0), angleSolid.getSI(), 0.001d, "SolidAngle");
45
46 Angle angle = DoubleScalar.instantiate(10.0, AngleUnit.SI);
47 assertEquals(10.0, angle.getSI(), 0.0001d, "Angle");
48 angle = DoubleScalar.instantiate(1.0, AngleUnit.DEGREE);
49 assertEquals(Math.PI / 180.0, angle.getSI(), 0.001d, "Angle");
50
51 Direction direction = DoubleScalar.instantiate(10.0, DirectionUnit.DEFAULT);
52 assertEquals(10.0, direction.getSI(), 0.0001d, "Direction");
53 direction = DoubleScalar.instantiate(1.0, DirectionUnit.EAST_DEGREE);
54 assertEquals(Math.PI / 180.0, direction.getSI(), 0.001d, "Direction");
55
56 Area area = DoubleScalar.instantiate(10.0, AreaUnit.SI);
57 assertEquals(10.0, area.getSI(), 0.0001d, "Area");
58 area = DoubleScalar.instantiate(1.0, AreaUnit.HECTARE);
59 assertEquals(10000.0, area.getSI(), 0.001d, "Area");
60
61
62
63 }
64
65
66
67
68 @Test
69 public final void anonymousUnitTest()
70 {
71 Unit<?> unitSI = LengthUnit.SI;
72 Unit<?> unitKM = LengthUnit.KILOMETER;
73 Length length = DoubleScalar.instantiateAnonymous(10.0, unitSI);
74 assertEquals(10.0, length.getSI(), 0.0001d, "Length");
75 length = DoubleScalar.instantiateAnonymous(1.0, unitKM);
76 assertEquals(1000.0, length.getSI(), 0.001d, "Length");
77
78
79
80 }
81 }