1 package org.djunits.unit;
2
3 import static org.djunits.unit.unitsystem.UnitSystem.OTHER;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertTrue;
6
7 import java.util.Locale;
8
9 import org.djunits.locale.DefaultLocale;
10 import org.junit.Before;
11 import org.junit.Test;
12
13
14
15
16
17
18
19
20
21
22 public class VolumeUnitTest extends AbstractLinearUnitTest<VolumeUnit>
23 {
24
25
26
27 @Before
28 public final void setup()
29 {
30 DefaultLocale.setLocale(new Locale("en"));
31 }
32
33
34
35
36 @Test
37 public final void keys()
38 {
39 checkKeys(VolumeUnit.CUBIC_METER, "VolumeUnit.cubic_meter", "VolumeUnit.m^3");
40 }
41
42
43
44
45 @Test
46 public final void conversions()
47 {
48 checkUnitRatioNameAndAbbreviation(VolumeUnit.CUBIC_METER, 1, 0.00000001, "cubic meter", "m^3");
49 checkUnitRatioNameAndAbbreviation(VolumeUnit.CUBIC_DECIMETER, 0.001, 0.0000000001, "cubic decimeter", "dm^3");
50 checkUnitRatioNameAndAbbreviation(VolumeUnit.LITER, 0.001, 0.0000000001, "liter", "L");
51
52 assertEquals("one CUBIC MILE is about 5451776000 CUBIC YARD", 5451776000.,
53 getMultiplicationFactorTo(VolumeUnit.CUBIC_MILE, VolumeUnit.CUBIC_YARD), 0.5);
54 assertEquals("one CUBIC YARD is 1.83426465e-10 CUBIC MILE", 1.83426465e-10,
55 getMultiplicationFactorTo(VolumeUnit.CUBIC_YARD, VolumeUnit.CUBIC_MILE), 0.0000000001);
56
57 checkUnitRatioNameAndAbbreviation(VolumeUnit.CUBIC_CENTIMETER, 0.000001, 0.000000000001, "cubic centimeter", "cm^3");
58 checkUnitRatioNameAndAbbreviation(VolumeUnit.CUBIC_KILOMETER, 1e9, 1, "cubic kilometer", "km^3");
59 checkUnitRatioNameAndAbbreviation(VolumeUnit.CUBIC_MILE, 4.16818183e9, 1000, "cubic mile", "mi^3");
60 checkUnitRatioNameAndAbbreviation(VolumeUnit.CUBIC_FOOT, 0.0283168, 0.0000001, "cubic foot", "ft^3");
61 checkUnitRatioNameAndAbbreviation(VolumeUnit.CUBIC_INCH, 1.6387e-5, 1e-9, "cubic inch", "in^3");
62 checkUnitRatioNameAndAbbreviation(VolumeUnit.CUBIC_YARD, 0.764554858, 0.0000001, "cubic yard", "yd^3");
63 checkUnitRatioNameAndAbbreviation(VolumeUnit.GALLON_US_FLUID, 0.0037854, 0.0000001, "gallon (US)", "gal(US)");
64 checkUnitRatioNameAndAbbreviation(VolumeUnit.OUNCE_US_FLUID, 0.000029574, 0.000000001, "ounce (fluid US)", "US fl oz");
65
66
67
68
69
70
71
72 }
73
74
75
76
77 @Test
78 public final void createVolumeUnit()
79 {
80 VolumeUnit myVU = new VolumeUnit("Barrel", "brl", OTHER, VolumeUnit.LITER, 119.240471);
81 assertTrue("Can create a new VolumeUnit", null != myVU);
82 checkUnitRatioNameAndAbbreviation(myVU, 0.119240471, 0.000001, "Barrel", "brl");
83 }
84
85 }