Added UnitXrossConverter

This commit is contained in:
Willem Cazander 2022-10-11 17:31:59 +02:00
parent 84738628af
commit d97076d436
159 changed files with 9197 additions and 96 deletions

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.unitxc;
import org.junit.jupiter.api.Assertions;
import net.forwardfire.unitxc.converter.UnitXConverter;
public class UnitXCAssert {
private static final UnitXConverter DEFAULT_CONVERTER = UnitXCFactory.createManager().getConverter();
private static final double DEFAULT_VALUE_DELTA = 0;
public static void convertEquals(double expected,String toType,double fromValue,String fromType) {
convertEquals(DEFAULT_CONVERTER,expected, toType, fromValue, fromType);
}
public static void convertEquals(UnitXConverter converter,double expected,String toType,double fromValue,String fromType) {
convertEquals(converter, expected, toType, fromValue, fromType, DEFAULT_VALUE_DELTA);
}
public static void convertEquals(UnitXConverter converter,double expected,String toType,double fromValue,String fromType,double valueDelta) {
Assertions.assertNotNull(converter);
Assertions.assertEquals(expected,converter.convert(fromValue, fromType, toType),valueDelta);
}
}

View file

@ -0,0 +1,210 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.unitxc;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import net.forwardfire.unitxc.converter.UnitXConverterParameterValue;
import net.forwardfire.unitxc.model.UnitXCType;
import net.forwardfire.unitxc.model.UnitXCGroup;
import net.forwardfire.unitxc.model.UnitXCGroupJump;
import net.forwardfire.unitxc.model.UnitXCGroupJumpParameter;
import net.forwardfire.unitxc.model.UnitXCGroupQuantity;
import net.forwardfire.unitxc.model.UnitXConverterResult;
import net.forwardfire.unitxc.model.step.RuleStepCodePrinter;
import net.forwardfire.unitxc.model.step.RuleStepCodeStyle;
import net.forwardfire.unitxc.model.step.UnitXConverterStep;
public class UnitXCConverterStepTest {
@Test
public void testFac() throws Exception {
UnitXCManager unitManager = UnitXCFactory.createManager();
Assertions.assertNotNull(unitManager);
Assertions.assertNotNull(unitManager.getConfig());
Assertions.assertNotNull(unitManager.getConfig().getUnitGroups());
Assertions.assertFalse(unitManager.getConfig().getUnitGroups().isEmpty());
long ts = 0l;
for (UnitXCGroup typeGroup:unitManager.getConfig().getUnitGroups()) {
UnitXCType type = unitManager.getUnitType(typeGroup.getBaseTypeId());
if (type == null) {
throw new IllegalStateException("No base type for: "+typeGroup.getId()+" needs: "+typeGroup.getBaseTypeId());
}
long tc = typeGroup.getUnitTypeSize();
ts += tc;
String groupLine = String.format("%-40s %-20d %-10s", typeGroup.getName().getValue(""),tc,type.getId());
System.out.println(groupLine);
}
System.out.println("\ntotalTypes: "+ts);
System.out.println("");
Set<String> paraSet = new HashSet<>();
for (UnitXCGroup typeGroup:unitManager.getConfig().getUnitGroups()) {
for (UnitXCGroupJump jumpGroup:typeGroup.getGroupJumps()) {
for (UnitXCGroupJumpParameter jumpPara:jumpGroup.getJumpParameters()) {
System.out.println("jumpPara: "+jumpPara.getId()+" as: "+jumpPara.getUnitGroupId());
if (paraSet.contains(jumpPara.getId())) {
//throw new IllegalStateException("duplicate jump parameter id found: "+jumpPara.getId());
}
paraSet.add(jumpPara.getId());
}
}
}
System.out.println("\ntotalTypes: "+ts);
System.out.println("");
UnitXConverterResult result2 = unitManager.getConverter().convertStepped(20.0, "m/s/s", "km/s/s");
System.out.println("20m/s = "+result2.getResultValue()+" km/h");
UnitXConverterResult result = unitManager.getConverter().convertStepped(211.0, "k°F", "m°C");
System.out.println("result: "+result);
//result = unitManager.getConverter().convertStepped(10.763, "ft²", "in²");
//xmlDriver.marshal(result, System.out);
//System.out.println("");
//result = unitManager.getConverter().convertStepped(10.763, "ft³", "in³");
//xmlDriver.marshal(result, System.out);
//result = unitManager.getConverter().convertStepped(1079000000, "km/h", "m/s");
//xmlDriver.marshal(result, System.out);
//try (OutputStream out = new FileOutputStream("/tmp/unitxc.conf.xml")) {
// jaxbDriver.getUnitXCConfig().marshal(unitManager.getConfig(), out);
//}
//System.out.println("GROUP:");
//jaxbDriver.getUnitXCGroup().marshal(unitManager.getUnitGroup("length"), System.out);
Map<String,UnitXConverterParameterValue> para = new HashMap<>();
para.put("metre_per_second_second", new UnitXConverterParameterValue(2, unitManager.getUnitType("minute")));
result = unitManager.getConverter().convertStepped(50, "km/h", "mm",para);
//System.out.println("CONVERT-RESULT: "+result);
long totalUnits=0;
StringBuilder buf = new StringBuilder();
buf.append("digraph G {\n");
//buf.append("\tsize = \"4,4\"\n");
for (UnitXCGroup typeGroup:unitManager.getConfig().getUnitGroups()) {
UnitXCType baseType = unitManager.getUnitType(typeGroup.getBaseTypeId());
System.out.println("group: "+typeGroup.getId());
// print info
buf.append("\t"+typeGroup.getId());
buf.append("[");
if (typeGroup.getDerivedFrom().isEmpty()) {
buf.append("shape=box,style=filled,color=\".9 0.5 0.9\",");
}
StringBuilder label = new StringBuilder();
label.append("label=\"");
label.append(typeGroup.getId()+"\\n");
label.append(baseType.getId()+"\\n");
label.append(baseType.getName()+"\\n");
Iterator<UnitXCGroupQuantity> q = typeGroup.getQuantities().iterator();
label.append("(");
while (q.hasNext()) {
UnitXCGroupQuantity gq = q.next();
label.append(gq.getId());
//label.append(gq.getName());
if (q.hasNext()) {
label.append(",");
}
}
label.append(")");
label.append("\"");
buf.append(label+",labelloc=b");
buf.append("];\n");
// print unit per group
buf.append("\t"+typeGroup.getId()+" -> "+typeGroup.getId());
buf.append("[");
buf.append("color=red,label=\""+typeGroup.getUnitTypeSize()+"\"");
buf.append("];\n");
totalUnits += typeGroup.getUnitTypeSize();
// print relations
for (String groupFrom:typeGroup.getDerivedFrom()) {
buf.append("\t"+groupFrom+" -> "+typeGroup.getId());
buf.append("[");
buf.append("dir=none");
buf.append("];\n");
}
//for (UnitXCGroupJump jumpGroup:typeGroup.getGroupJumps()) {
// System.out.println("jumpGruop: "+jumpGroup.getId()+" to: "+jumpGroup.getUnitGroupId());
// buf.append("\t"+typeGroup.getId()+" -> "+jumpGroup.getUnitGroupId());
// buf.append("[");
// buf.append("];\n");
// buf.append("\t"+typeGroup.getId()+" -> "+jumpGroup.getId());
// buf.append(";\n");
//
// buf.append("\t"+jumpGroup.getId()+" -> "+jumpGroup.getUnitGroupId());
// buf.append(";\n");
//for (UnitXCGroupJumpParameter jumpPara:jumpGroup.getJumpParameters()) {
//buf.append("\t"+jumpPara.getUnitGroupId()+"_"+(x++)+" -> "+jumpGroup.getId());
//buf.append(";\n");
//buf.append("\t"+typeGroup.getId()+" -> "+jumpPara.getId());
//buf.append(";\n");
//buf.append("\t"+jumpPara.getId()+" -> "+jumpGroup.getUnitGroupId());
//buf.append(";\n");
//}
//}
}
buf.append("Stats[shape=box,color=\".9 0.2 0.8\",label=\"unit groups: "+unitManager.getConfig().getUnitGroups().size()+"\\ntotal units: "+totalUnits+"\",labelloc=b];\n");
buf.append("}\n");
System.out.println("dot: \n"+buf.toString());
Files.write(Paths.get("target/groups.dot"), buf.toString().getBytes(Charset.forName("UTF-8")));
List<UnitXConverterStep> steps = new ArrayList<>();
result.getResultSteps().forEach(v -> steps.add(v.getConvertStep()));
String code = RuleStepCodePrinter.print(RuleStepCodeStyle.JAVASCRIPT, steps, result.getStartTypeId()+"_to_"+result.getResultTypeId());
System.out.println("\n\ncode: \n"+code);
}
}

View file

@ -0,0 +1,45 @@
package net.forwardfire.unitxc;
import net.forwardfire.unitxc.model.UnitXCConfig;
import java.util.ArrayList;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class UnitXCFactoryTest {
@Test
public void testCreateConfig() {
Assertions.assertNotNull(UnitXCFactory.createConfig());
}
@Test
public void testCreateConfigList() {
Assertions.assertNotNull(UnitXCFactory.createConfig(new ArrayList<>()));
}
@Test
public void testCreateConfigListNull() {
Assertions.assertThrows(NullPointerException.class, () -> {
Assertions.assertNotNull(UnitXCFactory.createConfig(null));
});
}
@Test
public void testCreateManager() {
Assertions.assertNotNull(UnitXCFactory.createManager());
}
@Test
public void testCreateManagerConfig() {
Assertions.assertNotNull(UnitXCFactory.createManager(new UnitXCConfig()));
}
@Test
public void testCreateManagerConfigNull() {
Assertions.assertThrows(NullPointerException.class, () -> {
Assertions.assertNotNull(UnitXCFactory.createManager(null));
});
}
}

View file

@ -0,0 +1,128 @@
package net.forwardfire.unitxc;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import net.forwardfire.unitxc.module.UnitXCModuleKelvin;
public class UnitXCManagerTest {
private UnitXCManager test = UnitXCFactory.createManager();
@Test
public void testGetConverter() {
Assertions.assertNotNull(test.getConverter());
}
@Test
public void testGetUnitType() {
Assertions.assertNotNull(test.getUnitType(UnitXCModuleKelvin.TYPE_KELVIN_ID));
}
@Test
public void testGetUnitTypeNull() {
Assertions.assertThrows(NullPointerException.class, () -> {
Assertions.assertNotNull(test.getUnitType(null));
});
}
@Test
public void testGetUnitTypeInvalid() {
Assertions.assertNull(test.getUnitType(getClass().getName()));
}
@Test
public void testGetUnitTypeResultId() {
Assertions.assertNotNull(test.getUnitType(UnitXCModuleKelvin.TYPE_KELVIN_ID).getId());
}
@Test
public void testGetUnitTypeResultName() {
Assertions.assertNotNull(test.getUnitType(UnitXCModuleKelvin.TYPE_KELVIN_ID).getName());
}
@Test
public void testGetUnitTypeResultTypeFlags() {
Assertions.assertNotNull(test.getUnitType(UnitXCModuleKelvin.TYPE_KELVIN_ID).getTypeFlags());
}
@Test
public void testGetUnitTypeGroup() {
Assertions.assertNotNull(test.getUnitGroup(UnitXCModuleKelvin.GROUP_ID));
}
@Test
public void testGetUnitTypeGroupNull() {
Assertions.assertThrows(NullPointerException.class, () -> {
Assertions.assertNotNull(test.getUnitGroup(null));
});
}
@Test
public void testGetUnitTypeGroupInvalid() {
Assertions.assertThrows(NullPointerException.class, () -> {
Assertions.assertNotNull(test.getUnitGroup(getClass().getName()));
});
}
@Test
public void testGetUnitTypeGroupResultId() {
Assertions.assertNotNull(test.getUnitGroup(UnitXCModuleKelvin.GROUP_ID).getId());
}
@Test
public void testGetUnitTypeGroupResultDescription() {
Assertions.assertNotNull(test.getUnitGroup(UnitXCModuleKelvin.GROUP_ID).getDescription());
}
@Test
public void testGetUnitTypeResultTypeBaseTypeID() {
Assertions.assertNotNull(test.getUnitGroup(UnitXCModuleKelvin.GROUP_ID).getBaseTypeId());
}
@Test
public void testIsUnitTypeGroupTrue() {
Assertions.assertTrue(test.isUnitGroup(UnitXCModuleKelvin.GROUP_ID));
}
@Test
public void testIsUnitTypeGroupFalse() {
Assertions.assertFalse(test.isUnitGroup(getClass().getName()));
}
@Test
public void testIsUnitTypeGroupNull() {
Assertions.assertThrows(NullPointerException.class, () -> {
Assertions.assertTrue(test.isUnitGroup(null));
});
}
@Test
public void testIsUnitTypeGroupEmpty() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
Assertions.assertTrue(test.isUnitGroup(""));
});
}
// @Test
// public void testIsUnitTypeTrue() {
// assertTrue(test.isUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID));
// }
//
// @Test
// public void testIsUnitTypeFalse() {
// assertFalse(test.isUnitType(getClass().getName()));
// }
//
// @Test(expected=NullPointerException.class)
// public void testIsUnitTypeNull() {
// assertTrue(test.isUnitType(null));
// }
@Test
public void testIsUnitTypeEmpty() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
Assertions.assertTrue(test.isUnitGroup(""));
});
}
}

View file

@ -0,0 +1,92 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.unitxc.module;
import static net.forwardfire.unitxc.UnitXCAssert.convertEquals;
import org.junit.jupiter.api.Test;
public class UnitXCModuleAreaTest {
@Test
public void test1ToSquareKilometre() throws Exception {
convertEquals(0.000001,"km²",1.0, "");
}
@Test
public void test1ToSquareCentimetre() throws Exception {
convertEquals(10000,"cm²",1.0, "");
}
@Test
public void test1ToHectares() throws Exception {
convertEquals(0.0001,"ha",1.0, "");
}
/*
@Test
public void test1ToDecares() throws Exception {
convertEquals(0.001,"daa",1.0, "");
}
*/
@Test
public void test1ToAres() throws Exception {
convertEquals(0.01,"a",1.0, "");
}
/*
@Test
public void test1ToDeciares() throws Exception {
convertEquals(0.1,"da",1.0, "");
}
*/
@Test
public void test1ToCentiare() throws Exception {
convertEquals(1.0,"ca",1.0, "");
}
/*
@Test
public void test1ToAcres() throws Exception {
convertEquals(0.000247105381,"acres",1.0, "");
}
@Test
public void test1ToCents() throws Exception {
convertEquals(0.024710538 ,"cents",1.0, "");
}
@Test
public void test1ToSquareYard() throws Exception {
convertEquals(1.195990 ,"yd²",1.0, "");
}
@Test
public void test1ToSquareFeet() throws Exception {
convertEquals(10.763911 ,"ft²",1.0, "");
}
@Test
public void test1ToSquareInch() throws Exception {
convertEquals(1550.0031 ,"in²",1.0, "");
}
*/
}

View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.unitxc.module;
import static net.forwardfire.unitxc.UnitXCAssert.convertEquals;
import org.junit.jupiter.api.Test;
public class UnitXCModuleLengthTest {
@Test
public void test10cm2mm() {
convertEquals(100.0,"mm",10.0, "cm");
}
@Test
public void test2mm2cm() {
convertEquals(1.0,"cm",10.0,"mm");
}
@Test
public void test004567km2cm() {
convertEquals(4567,"cm",0.04567,"km");
}
@Test
public void test2cm2mm() {
convertEquals(232.0,"mm",23.2, "cm");
}
@Test
public void test2345mm2cm() {
convertEquals(234.56,"cm",2345.6, "mm");
}
@Test
public void test1in2mm() {
convertEquals(25.4,"mm",1.0, "in");
}
@Test
public void test25mm2in() {
convertEquals(1.0,"in",25.4,"mm");
}
@Test
public void test2ft2mm() {
convertEquals(304.8*2,"mm",2.0,"ft");
}
@Test
public void test2ft2m() {
convertEquals(0.6096,"m",2.0, "ft");
}
@Test
public void test06m2in() {
convertEquals(24.0,"in",0.6096, "m");
}
@Test
public void test2ft2in() {
convertEquals(24.0,"in",2.0, "ft");
}
@Test
public void test2ft2cm() {
convertEquals(73.152,"cm",2.4, "ft");
}
@Test
public void test24ft2m() {
convertEquals(7.315,"m",24, "ft");
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.unitxc.module;
import static net.forwardfire.unitxc.UnitXCAssert.convertEquals;
import org.junit.jupiter.api.Test;
public class UnitXCModuleTemperatureTest {
@Test
public void test300K2C() throws Exception {
convertEquals(26.85,"°C",300.0, "K");
}
@Test
public void test37C2K() throws Exception {
convertEquals(310.65,"K",37.5, "°C");
}
@Test
public void test300K2F() throws Exception {
convertEquals(80.32,"°F",300.0, "K");
}
@Test
public void test37C2F() throws Exception {
convertEquals(276.0,"K",37.5, "°F");
}
@Test
public void test37F2K() throws Exception {
convertEquals(276.2,"K",37.505, "°F");
}
@Test
public void test166F2C() throws Exception {
convertEquals(74.937,"°C",166.888, "°F");
}
@Test
public void test100C2F() throws Exception {
convertEquals(211.9,"°F",100.0, "°C");
}
@Test
public void test233R2C() throws Exception {
convertEquals(-143.64,"°C",233.12,"°R");
}
@Test
public void test666C2R() throws Exception {
convertEquals(1691.06,"°R",666.333,"°C");
}
}

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.unitxc.module;
import static net.forwardfire.unitxc.UnitXCAssert.convertEquals;
import org.junit.jupiter.api.Test;
public class UnitXCModuleTimeTest {
@Test
public void test30SecondToMinute() throws Exception {
convertEquals(0.5,"minute",30.0, "s");
}
@Test
public void test300SecondToMinute() throws Exception {
convertEquals(5,"minute",300.0, "s");
}
@Test
public void test7200SecondToHour() throws Exception {
convertEquals(2,"hour",7200.0, "s");
}
@Test
public void test120MinuteToHour() throws Exception {
convertEquals(2,"hour",120.0, "minute");
}
@Test
public void test300MinuteToHour() throws Exception {
convertEquals(5,"hour",300.0, "minute");
}
@Test
public void test48HourToDay() throws Exception {
convertEquals(2,"day",48, "hour");
}
}

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.unitxc.module;
import static net.forwardfire.unitxc.UnitXCAssert.convertEquals;
import org.junit.jupiter.api.Test;
public class UnitXCModuleVolumeTest {
@Test
public void test10CubicFootToCubicInch() throws Exception {
convertEquals(18593.0,"in³",10.763, "ft³"); // redo after fix
}
@Test
public void test1ToCubicCentimetre() throws Exception {
convertEquals(1000000,"cm³",1.0, "");
}
@Test
public void test1ToCubicDecimetre() throws Exception {
convertEquals(1000,"dm³",1.0, "");
}
}