001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.planning.ldm.measure;
027:
028: /** Point test for measure class functionality **/
029:
030: public class Test {
031: public static void main(String arg[]) {
032: System.out.println("Constructors:");
033: Mass m0 = new Mass(1234.0, Mass.GRAMS);
034: System.out.println(" Mass(double, int)=" + m0);
035: Mass m1 = Mass.newGrams(1234.0);
036: System.out.println(" Mass.newGrams(double)=" + m1);
037: Mass m2 = new Mass("1234 grams");
038: System.out.println(" Mass(String withSpace)=" + m2);
039: Mass m3 = new Mass("1234grams");
040: System.out.println(" Mass(String noSpace)=" + m3);
041:
042: System.out.println("Equals:");
043: System.out.println(" all equals(): "
044: + (m0.equals(m1) && m1.equals(m2) && m2.equals(m3)));
045:
046: System.out.println("Common unit:");
047: int cu = m0.getCommonUnit();
048: System.out.println(" Mass Common unit = " + cu + " ("
049: + m0.getUnitName(cu) + ")");
050: System.out.println(" m0 = " + m0.getValue(cu));
051:
052: System.out.println("Capacity:");
053: System.out.println(" rate Capacity: "
054: + new Capacity("Count=20units Duration=2days"));
055: System.out.println(" instantaneous Capacity"
056: + new Capacity("Count=10units"));
057: System.out.println("Rates:");
058: Speed s = new Speed(1.0, Distance.MILES, Duration.HOURS);
059: System.out.println(" Getters:");
060: System.out.println(" meters/sec = " + s.getMetersPerSecond());
061: System.out.println(" miles/hour = " + s.getMilesPerHour());
062: System.out.println(" miles/hour = "
063: + s.getValue(Speed.MILES_PER_HOUR));
064: System.out.println(" miles/hour = "
065: + s.getValue(Distance.MILES, Duration.HOURS));
066:
067: System.out.println(" 1.0 == "
068: + (new Speed(1.0, Distance.MILES, Duration.HOURS))
069: .getValue(Distance.MILES, Duration.HOURS));
070: System.out.println(" 1.0 == "
071: + (Speed.newMilesPerHour(1.0)).getMilesPerHour());
072: System.out.println(" 1.0 == "
073: + (new Speed(1.0, Speed.MILES_PER_HOUR))
074: .getValue(Speed.MILES_PER_HOUR));
075:
076: System.out.println(" constructors:");
077: System.out.println(" 1: "
078: + new Speed(1.0, Distance.MILES, Duration.HOURS));
079: System.out.println(" 2: "
080: + new Speed(1.0, Speed.MILES_PER_HOUR));
081: System.out.println(" 3: "
082: + new Speed(Distance.newMiles(1.0), Duration
083: .newHours(1)));
084: System.out.println(" 4: " + new Speed("1 milesperhour"));
085: System.out.println(" 5: " + Speed.newMilesPerHour(1.0));
086: System.out.println(" 6: " + Speed.newMilesPerHour("1.0"));
087:
088: System.out.println();
089:
090: Measure m = s;
091: System.out.println(" Measure API:");
092: System.out.println(" Base unit = 0 = " + m.getUnitName(0));
093: System.out.println(" Common unit = " + m.getCommonUnit()
094: + " = " + m.getUnitName(m.getCommonUnit()));
095: System.out.println(" Max unit = " + m.getMaxUnit() + " = "
096: + m.getUnitName(m.getMaxUnit()));
097: System.out.println(" Base unit value = " + m.getValue(0) + " "
098: + m.getUnitName(0));
099: System.out.println(" Common unit value = "
100: + m.getValue(m.getCommonUnit()) + " "
101: + m.getUnitName(m.getCommonUnit()));
102: System.out.println(" Max unit value = "
103: + m.getValue(m.getMaxUnit()) + " "
104: + m.getUnitName(m.getMaxUnit()));
105: Derivative d = s;
106: System.out.println(" Derivative API:");
107: System.out.println(" Numerator Class = "
108: + d.getNumeratorClass());
109: System.out.println(" Denominator Class = "
110: + d.getDenominatorClass());
111: System.out.println(" Canonical Numerator = "
112: + d.getCanonicalNumerator());
113: System.out.println(" CanonicalDenominator = "
114: + d.getCanonicalDenominator());
115: System.out.println(" value(miles,hours) = "
116: + d.getValue(Distance.MILES, Duration.HOURS));
117: System.out.println(" computeNumerator(30minutes) = "
118: + d.computeNumerator(Duration.newMinutes(30)).getValue(
119: Distance.MILES));
120: }
121: }
|