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 TimeUnitTest extends AbstractOffsetUnitTest<TimeUnit>
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("s", TimeUnit.DEFAULT.getQuantity().getSiDimensions().toString(true, false));
37 checkUnitRatioOffsetNameAndAbbreviation(TimeUnit.BASE_SECOND, 1, 0.0, 0.00000001, "second", "s");
38 checkUnitRatioOffsetNameAndAbbreviation(TimeUnit.BASE_HOUR, 3600, 0.0, 0.0005, "hour", "h");
39 checkUnitRatioOffsetNameAndAbbreviation(TimeUnit.BASE_DAY, 86400, 0.0, 0.001, "day", "day");
40
41 assertEquals(24, getMultiplicationFactorTo(TimeUnit.BASE_DAY, TimeUnit.BASE_HOUR), 0.0001, "one DAY is 24 HOUR");
42 assertEquals(0.0417, getMultiplicationFactorTo(TimeUnit.BASE_HOUR, TimeUnit.BASE_DAY), 0.0001,
43 "one HOUR is about 0.0417 DAY");
44
45 checkUnitRatioOffsetNameAndAbbreviation(TimeUnit.BASE_MILLISECOND, 0.001, 0.0, 0.00000001, "millisecond", "ms");
46 checkUnitRatioOffsetNameAndAbbreviation(TimeUnit.BASE_MINUTE, 60, 0.0, 0.000001, "minute", "min");
47 checkUnitRatioOffsetNameAndAbbreviation(TimeUnit.BASE_WEEK, 7 * 86400, 0.0, 0.1, "week", "wk");
48
49
50 }
51
52
53
54
55 @Test
56 public final void createTimeUnit()
57 {
58 TimeUnit myTU = TimeUnit.BASE_SECOND.deriveLinearOffset(14.0 * 86400, 0.0, DurationUnit.SECOND, "fn", "Fortnight",
59 UnitSystem.OTHER);
60 assertTrue(null != myTU, "Can create a new TimeUnit");
61 checkUnitRatioOffsetNameAndAbbreviation(myTU, 14 * 86400, 0.0, 1, "Fortnight", "fn");
62 TimeUnit.BASE.unregister(myTU);
63 }
64
65
66
67
68 @Test
69 public final void testRelative()
70 {
71 assertEquals(DurationUnit.BASE, TimeUnit.DEFAULT.getRelativeQuantity());
72 }
73
74 }