001: package org.incava.jagol;
002:
003: import java.io.*;
004: import java.util.*;
005: import junit.framework.TestCase;
006:
007: public class TestDoubleOption extends TestCase {
008: DoubleOption opt = new DoubleOption("dblopt",
009: "this is the description of dblopt");
010:
011: public TestDoubleOption(String name) {
012: super (name);
013: }
014:
015: public void testDefaultNull() {
016: assertEquals("dblopt", opt.getLongName());
017: assertEquals("this is the description of dblopt", opt
018: .getDescription());
019:
020: assertNull("default value", opt.getValue());
021: }
022:
023: public void testDefaultValue() {
024: DoubleOption opt = new DoubleOption("dblopt",
025: "this is the description of dblopt", new Double(6.66));
026: assertEquals("default value", new Double(6.66), opt.getValue());
027: }
028:
029: public void testShortName() {
030: opt.setShortName('d');
031: assertEquals('d', opt.getShortName());
032: }
033:
034: public void testSetDoubleValue() {
035: opt.setValue(new Double(1.4));
036: assertEquals("option value", new Double(1.4), opt.getValue());
037: }
038:
039: public void testSetInvalidValueString() {
040: try {
041: opt.setValue("fred");
042: fail("exception expected");
043: } catch (InvalidTypeException ite) {
044: }
045: }
046:
047: public void testSetInvalidValue() {
048: try {
049: opt.setValue("1.4.8");
050: fail("exception expected");
051: } catch (InvalidTypeException ite) {
052: }
053: }
054:
055: public void testSetValidValueNegative() {
056: try {
057: opt.setValue("-9.87");
058: assertEquals("option value", new Double(-9.87), opt
059: .getValue());
060: } catch (InvalidTypeException ite) {
061: fail("exception not expected");
062: }
063: }
064:
065: public void testSetValidValueNoLeadingZero() {
066: try {
067: opt.setValue(".87");
068: assertEquals("option value", new Double(0.87), opt
069: .getValue());
070: } catch (InvalidTypeException ite) {
071: fail("exception not expected");
072: }
073: }
074:
075: public void testSetFromArgsListEqual() {
076: List args = new ArrayList();
077: try {
078: boolean processed = opt.set("--dblopt=4.44", args);
079: assertEquals("option processed", true, processed);
080: assertEquals("option value", new Double(4.44), opt
081: .getValue());
082: assertEquals("argument removed from list", 0, args.size());
083: } catch (OptionException ite) {
084: fail("failure is not an option");
085: }
086: }
087:
088: public void testSetFromArgsListSeparateString() {
089: List args = new ArrayList();
090: args.add("41.82");
091: try {
092: boolean processed = opt.set("--dblopt", args);
093: assertEquals("option processed", true, processed);
094: assertEquals("option value", new Double(41.82), opt
095: .getValue());
096: assertEquals("argument removed from list", 0, args.size());
097: } catch (OptionException ite) {
098: fail("failure is not an option");
099: }
100: }
101:
102: public void testSetFromLongerArgsListEqual() {
103: List args = new ArrayList();
104: args.add("--anotheropt");
105: try {
106: boolean processed = opt.set("--dblopt=3.1415", args);
107: assertEquals("option processed", true, processed);
108: assertEquals("option value", new Double(3.1415), opt
109: .getValue());
110: assertEquals("argument removed from list", 1, args.size());
111: } catch (OptionException ite) {
112: fail("failure is not an option");
113: }
114: }
115:
116: public void testSetFromLongerArgsListSeparateString() {
117: List args = new ArrayList();
118: args.add("1234.567890");
119: args.add("--anotheropt");
120: try {
121: boolean processed = opt.set("--dblopt", args);
122: assertEquals("option processed", true, processed);
123: assertEquals("option value", new Double(1234.567890), opt
124: .getValue());
125: assertEquals("argument removed from list", 1, args.size());
126: } catch (OptionException ite) {
127: fail("failure is not an option");
128: }
129: }
130:
131: public void testSetInvalidValueDanglingEquals() {
132: List args = new ArrayList();
133: args.add("--anotheropt");
134: try {
135: boolean processed = opt.set("--dblopt=", args);
136: fail("exception expected");
137: } catch (OptionException ite) {
138: }
139: }
140:
141: }
|