1 package org.djunits.generator;
2
3 import java.io.IOException;
4 import java.net.URISyntaxException;
5 import java.util.ArrayList;
6 import java.util.List;
7
8
9
10
11
12
13
14
15
16 public class GenerateCliConvertersTest
17 {
18
19 private static List<TestRecord> testRecords = new ArrayList<>();
20
21 static
22 {
23
24 testRecords.add(new TestRecord("AbsoluteTemperature", 200.0, "AbsoluteTemperatureUnit.KELVIN", "200.0K",
25 100.0, "AbsoluteTemperatureUnit.DEGREE_CELSIUS", "100.0C"));
26 testRecords.add(new TestRecord("Acceleration", 2.0, "AccelerationUnit.METER_PER_SECOND_2", "2.0m/s^2",
27 1.0, "AccelerationUnit.KM_PER_HOUR_2", "1.0km/h^2"));
28 testRecords.add(new TestRecord("Angle", 2.0, "AngleUnit.RADIAN", "2.0rad",
29 10.0, "AngleUnit.DEGREE", "10.0deg"));
30 testRecords.add(new TestRecord("AngleSolid", 2.0, "AngleSolidUnit.STERADIAN", "2.0sr",
31 1.0, "AngleSolidUnit.SQUARE_DEGREE", "1.0sq.deg"));
32 testRecords.add(new TestRecord("Area", 2.0, "AreaUnit.SQUARE_METER", "2.0m^2",
33 1.0, "AreaUnit.ACRE", "1.0acre"));
34 testRecords.add(new TestRecord("Density", 2.0, "DensityUnit.KG_PER_METER_3", "2.0kg/m^3",
35 1.0, "DensityUnit.GRAM_PER_CENTIMETER_3", "1.0g/cm^3"));
36 testRecords.add(new TestRecord("Dimensionless", 2.0, "DimensionlessUnit.SI", "2.0",
37 1.0, "DimensionlessUnit.SI", "1.0"));
38 testRecords.add(new TestRecord("Direction", 2.0, "DirectionUnit.EAST_RADIAN", "2.0rad(E)",
39 1.0, "DirectionUnit.NORTH_DEGREE", "1.0deg(N)"));
40 testRecords.add(new TestRecord("Duration", 2.0, "DurationUnit.SECOND", "2.0s",
41 1.0, "DurationUnit.DAY", "1.0day"));
42 testRecords.add(new TestRecord("ElectricalCharge", 2.0, "ElectricalChargeUnit.COULOMB", "2.0C",
43 1.0, "ElectricalChargeUnit.MILLIAMPERE_HOUR", "1.0mAh"));
44 testRecords.add(new TestRecord("ElectricalCurrent", 2.0, "ElectricalCurrentUnit.AMPERE", "2.0A",
45 1.0, "ElectricalCurrentUnit.STATAMPERE", "1.0statA"));
46 testRecords.add(new TestRecord("ElectricalPotential", 2.0, "ElectricalPotentialUnit.VOLT", "2.0V",
47 1.0, "ElectricalPotentialUnit.ABVOLT", "1.0abV"));
48 testRecords.add(new TestRecord("ElectricalResistance", 2.0, "ElectricalResistanceUnit.OHM", "2.0Ohm",
49 1.0, "ElectricalResistanceUnit.STATOHM", "1.0stOhm"));
50 testRecords.add(new TestRecord("Energy", 2.0, "EnergyUnit.JOULE", "2.0J",
51 1.0, "EnergyUnit.KILOWATT_HOUR", "1.0kWh"));
52 testRecords.add(new TestRecord("FlowMass", 2.0, "FlowMassUnit.KILOGRAM_PER_SECOND", "2.0kg/s",
53 1.0, "FlowMassUnit.POUND_PER_SECOND", "1.0lb/s"));
54 testRecords.add(new TestRecord("FlowVolume", 2.0, "FlowVolumeUnit.CUBIC_METER_PER_SECOND", "2.0m^3/s",
55 1.0, "FlowVolumeUnit.GALLON_PER_DAY", "1.0gal/day"));
56 testRecords.add(new TestRecord("Force", 2.0, "ForceUnit.NEWTON", "2.0N",
57 1.0, "ForceUnit.KILOGRAM_FORCE", "1.0kgf"));
58 testRecords.add(new TestRecord("Frequency", 2.0, "FrequencyUnit.PER_SECOND", "2.0/s",
59 1.0, "FrequencyUnit.KILOHERTZ", "1.0kHz"));
60 testRecords.add(new TestRecord("Length", 2.0, "LengthUnit.METER", "2.0m",
61 1.0, "LengthUnit.INCH", "1.0in"));
62 testRecords.add(new TestRecord("LinearDensity", 2.0, "LinearDensityUnit.PER_METER", "2.0/m",
63 1.0, "LinearDensityUnit.PER_YARD", "1.0/yd"));
64 testRecords.add(new TestRecord("Mass", 2.0, "MassUnit.KILOGRAM", "2.0kg",
65 1.0, "MassUnit.GIGAELECTRONVOLT", "1.0GeV"));
66 testRecords.add(new TestRecord("Position", 2.0, "PositionUnit.ASTRONOMICAL_UNIT", "2.0AU",
67 1.0, "PositionUnit.DECIMETER", "1.0dm"));
68 testRecords.add(new TestRecord("Power", 2.0, "PowerUnit.WATT", "2.0W",
69 1.0, "PowerUnit.FOOT_POUND_FORCE_PER_HOUR", "1.0ft.lbf/h"));
70 testRecords.add(new TestRecord("Pressure", 2.0, "PressureUnit.PASCAL", "2.0Pa",
71 1.0, "PressureUnit.MILLIMETER_MERCURY", "1.0mmHg"));
72 testRecords.add(new TestRecord("Speed", 2.0, "SpeedUnit.METER_PER_SECOND", "2.0m/s",
73 1.0, "SpeedUnit.MILE_PER_HOUR", "1.0mi/h"));
74 testRecords.add(new TestRecord("Temperature", 2.0, "TemperatureUnit.KELVIN", "2.0K",
75 1.0, "TemperatureUnit.DEGREE_CELSIUS", "1.0degC"));
76 testRecords.add(new TestRecord("Time", 2.0, "TimeUnit.BASE_HOUR", "2.0h",
77 1.0, "TimeUnit.EPOCH_DAY", "1.0day"));
78 testRecords.add(new TestRecord("Torque", 2.0, "TorqueUnit.NEWTON_METER", "2.0N.m",
79 1.0, "TorqueUnit.POUND_FOOT", "1.0lbf.ft"));
80 testRecords.add(new TestRecord("Volume", 2.0, "VolumeUnit.CUBIC_METER", "2.0m^3",
81 1.0, "VolumeUnit.LITER", "1.0L"));
82
83 }
84
85
86
87
88
89
90 public static void main(String[] args) throws IOException, URISyntaxException
91 {
92
93
94
95
96
97
98 for (TestRecord r : testRecords)
99 {
100
101 System.out.println(" /** */\n" +
102 " @Option(names = {\"--" + r.type.toLowerCase() + "\"}, description = \"" + r.type + "\", defaultValue = \"" + r.value1 + "\")\n" +
103 " protected " + r.type + " " + r.type.toLowerCase() + ";\n");
104
105 }
106
107 System.out.println("\n\n");
108
109
110
111
112
113
114
115
116
117
118
119
120 for (TestRecord r : testRecords)
121 {
122
123 System.out.println("args = new String[] {};");
124 System.out.println("options = new Options();");
125 System.out.println("CliUtil.execute(options, args);");
126 System.out.println("assertEquals(new " + r.type + "(" + r.amount1 + ", " + r.unit1 + "), options." + r.type.toLowerCase() + ");");
127 System.out.println("args = new String[] {\"--" + r.type.toLowerCase() + "\", \"" + r.value2 + "\"};");
128 System.out.println("CliUtil.execute(options, args);");
129 System.out.println("assertEquals(new " + r.type + "(" + r.amount2 + ", " + r.unit2 + "), options." + r.type.toLowerCase() + ");\n");
130
131 }
132 }
133
134
135 private static class TestRecord
136 {
137
138 protected String type;
139
140
141 protected double amount1;
142
143
144 protected String unit1;
145
146
147 protected String value1;
148
149
150 protected double amount2;
151
152
153 protected String unit2;
154
155
156 protected String value2;
157
158
159
160
161
162
163
164
165
166
167 public TestRecord(String type, double amount1, String unit1, String value1, double amount2, String unit2, String value2)
168 {
169 this.type = type;
170 this.amount1 = amount1;
171 this.unit1 = unit1;
172 this.value1 = value1;
173 this.amount2 = amount2;
174 this.unit2 = unit2;
175 this.value2 = value2;
176 }
177 }
178 }