summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rwxr-xr-xsrc/test/java/UnitDimensionTest.java79
-rwxr-xr-xsrc/test/java/UnitTest.java49
-rw-r--r--src/test/java/package-info.java23
3 files changed, 151 insertions, 0 deletions
diff --git a/src/test/java/UnitDimensionTest.java b/src/test/java/UnitDimensionTest.java
new file mode 100755
index 0000000..0b5055b
--- /dev/null
+++ b/src/test/java/UnitDimensionTest.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright (C) 2018 Adrien Hopkins
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+package test.java;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.unitConverter.dimension.StandardDimensions.AREA;
+import static org.unitConverter.dimension.StandardDimensions.ENERGY;
+import static org.unitConverter.dimension.StandardDimensions.LENGTH;
+import static org.unitConverter.dimension.StandardDimensions.MASS;
+import static org.unitConverter.dimension.StandardDimensions.MASS_DENSITY;
+import static org.unitConverter.dimension.StandardDimensions.QUANTITY;
+import static org.unitConverter.dimension.StandardDimensions.TIME;
+import static org.unitConverter.dimension.StandardDimensions.VOLUME;
+
+import org.junit.Test;
+import org.unitConverter.dimension.SIBaseDimension;
+import org.unitConverter.dimension.UnitDimension;
+
+/**
+ * Tests for {@link UnitDimension}.
+ *
+ * @author Adrien Hopkins
+ * @since 2018-12-12
+ * @since v0.1.0
+ */
+public class UnitDimensionTest {
+ /**
+ * Tests {@link UnitDimension#equals}
+ *
+ * @since 2018-12-12
+ * @since v0.1.0
+ */
+ @Test
+ public void testEquals() {
+ assertEquals(LENGTH, LENGTH);
+ assertFalse(LENGTH.equals(QUANTITY));
+ }
+
+ /**
+ * Tests {@code UnitDimension}'s exponentiation
+ *
+ * @since 2019-01-15
+ * @since v0.1.0
+ */
+ @Test
+ public void testExponents() {
+ assertEquals(1, LENGTH.getExponent(SIBaseDimension.LENGTH));
+ assertEquals(3, VOLUME.getExponent(SIBaseDimension.LENGTH));
+ }
+
+ /**
+ * Tests {@code UnitDimension}'s multiplication and division.
+ *
+ * @since 2018-12-12
+ * @since v0.1.0
+ */
+ @Test
+ public void testMultiplicationAndDivision() {
+ assertEquals(AREA, LENGTH.times(LENGTH));
+ assertEquals(MASS_DENSITY, MASS.dividedBy(VOLUME));
+ assertEquals(ENERGY, AREA.times(MASS).dividedBy(TIME).dividedBy(TIME));
+ assertEquals(LENGTH, LENGTH.times(TIME).dividedBy(TIME));
+ }
+}
diff --git a/src/test/java/UnitTest.java b/src/test/java/UnitTest.java
new file mode 100755
index 0000000..45f890f
--- /dev/null
+++ b/src/test/java/UnitTest.java
@@ -0,0 +1,49 @@
+/**
+ * Copyright (C) 2018 Adrien Hopkins
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+package test.java;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.unitConverter.dimension.StandardDimensions;
+import org.unitConverter.unit.BaseUnit;
+import org.unitConverter.unit.SI;
+import org.unitConverter.unit.Unit;
+
+/**
+ * Testing the various Unit classes
+ *
+ * @author Adrien Hopkins
+ * @since 2018-12-22
+ */
+public class UnitTest {
+ @Test
+ public void testConversion() {
+ final BaseUnit metre = SI.METRE;
+ final Unit inch = metre.times(0.0254);
+
+ assertEquals(1.9, inch.convertToBase(75), 0.01);
+ }
+
+ @Test
+ public void testEquals() {
+ final BaseUnit metre = SI.METRE;
+ final Unit meter = SI.SI.getBaseUnit(StandardDimensions.LENGTH);
+
+ assertEquals(metre, meter);
+ }
+}
diff --git a/src/test/java/package-info.java b/src/test/java/package-info.java
new file mode 100644
index 0000000..9f2e1d6
--- /dev/null
+++ b/src/test/java/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * Copyright (C) 2019 Adrien Hopkins
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+/**
+ * All of the Unit Converter tests.
+ *
+ * @author Adrien Hopkins
+ * @since 2019-03-16
+ */
+package test.java; \ No newline at end of file