001: package org.incava.jagol;
002:
003: import java.io.*;
004: import java.util.*;
005: import junit.framework.TestCase;
006:
007: public class TestFloatOption extends TestCase {
008: FloatOption opt = new FloatOption("fltopt",
009: "this is the description of fltopt");
010:
011: public TestFloatOption(String name) {
012: super (name);
013: }
014:
015: public void testDefaultNull() {
016: assertEquals("fltopt", opt.getLongName());
017: assertEquals("this is the description of fltopt", opt
018: .getDescription());
019:
020: assertNull("default value", opt.getValue());
021: }
022:
023: public void testDefaultValue() {
024: FloatOption opt = new FloatOption("fltopt",
025: "this is the description of fltopt", new Float(10.12F));
026: assertEquals("default value", new Float(10.12F), opt.getValue());
027: }
028:
029: public void testShortName() {
030: opt.setShortName('d');
031: assertEquals('d', opt.getShortName());
032: }
033:
034: public void testSetFloatValue() {
035: opt.setValue(new Float(1.4F));
036: assertEquals("option value", new Float(1.4F), 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 Float(-9.87F), 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 Float(0.87F), 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("--fltopt=4.44", args);
079: assertEquals("option processed", true, processed);
080: assertEquals("option value", new Float(4.44F), 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("--fltopt", args);
093: assertEquals("option processed", true, processed);
094: assertEquals("option value", new Float(41.82F), 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("--fltopt=3.1415", args);
107: assertEquals("option processed", true, processed);
108: assertEquals("option value", new Float(3.1415F), opt
109: .getValue());
110: assertEquals("argument not removed from list", 1, args
111: .size());
112: } catch (OptionException ite) {
113: fail("failure is not an option");
114: }
115: }
116:
117: public void testSetFromLongerArgsListSeparateString() {
118: List args = new ArrayList();
119: args.add("1234.567890");
120: args.add("--anotheropt");
121: try {
122: boolean processed = opt.set("--fltopt", args);
123: assertEquals("option processed", true, processed);
124: assertEquals("option value", new Float(1234.567890F), opt
125: .getValue());
126: assertEquals("argument removed from list", 1, args.size());
127: } catch (OptionException ite) {
128: fail("failure is not an option");
129: }
130: }
131:
132: public void testSetInvalidValueDanglingEquals() {
133: List args = new ArrayList();
134: args.add("--anotheropt");
135: try {
136: boolean processed = opt.set("--fltopt=", args);
137: fail("exception expected");
138: } catch (OptionException ite) {
139: }
140: }
141:
142: }
|