1 package org.incava.jagol; 2 3 import java.io.*; 4 import java.util.*; 5 import junit.framework.TestCase; 6 7 8 public class TestDoubleOption extends TestCase 9 { 10 DoubleOption opt = new DoubleOption("dblopt", "this is the description of dblopt"); 11 12 public TestDoubleOption(String name) 13 { 14 super(name); 15 } 16 17 public void testDefaultNull() 18 { 19 assertEquals("dblopt", opt.getLongName()); 20 assertEquals("this is the description of dblopt", opt.getDescription()); 21 22 assertNull("default value", opt.getValue()); 23 } 24 25 public void testDefaultValue() 26 { 27 DoubleOption opt = new DoubleOption("dblopt", "this is the description of dblopt", new Double (6.66)); 28 assertEquals("default value", new Double (6.66), opt.getValue()); 29 } 30 31 public void testShortName() 32 { 33 opt.setShortName('d'); 34 assertEquals('d', opt.getShortName()); 35 } 36 37 public void testSetDoubleValue() 38 { 39 opt.setValue(new Double (1.4)); 40 assertEquals("option value", new Double (1.4), opt.getValue()); 41 } 42 43 public void testSetInvalidValueString() 44 { 45 try { 46 opt.setValue("fred"); 47 fail("exception expected"); 48 } 49 catch (InvalidTypeException ite) { 50 } 51 } 52 53 public void testSetInvalidValue() 54 { 55 try { 56 opt.setValue("1.4.8"); 57 fail("exception expected"); 58 } 59 catch (InvalidTypeException ite) { 60 } 61 } 62 63 public void testSetValidValueNegative() 64 { 65 try { 66 opt.setValue("-9.87"); 67 assertEquals("option value", new Double (-9.87), opt.getValue()); 68 } 69 catch (InvalidTypeException ite) { 70 fail("exception not expected"); 71 } 72 } 73 74 public void testSetValidValueNoLeadingZero() 75 { 76 try { 77 opt.setValue(".87"); 78 assertEquals("option value", new Double (0.87), opt.getValue()); 79 } 80 catch (InvalidTypeException ite) { 81 fail("exception not expected"); 82 } 83 } 84 85 public void testSetFromArgsListEqual() 86 { 87 List args = new ArrayList(); 88 try { 89 boolean processed = opt.set("--dblopt=4.44", args); 90 assertEquals("option processed", true, processed); 91 assertEquals("option value", new Double (4.44), opt.getValue()); 92 assertEquals("argument removed from list", 0, args.size()); 93 } 94 catch (OptionException ite) { 95 fail("failure is not an option"); 96 } 97 } 98 99 public void testSetFromArgsListSeparateString() 100 { 101 List args = new ArrayList(); 102 args.add("41.82"); 103 try { 104 boolean processed = opt.set("--dblopt", args); 105 assertEquals("option processed", true, processed); 106 assertEquals("option value", new Double (41.82), opt.getValue()); 107 assertEquals("argument removed from list", 0, args.size()); 108 } 109 catch (OptionException ite) { 110 fail("failure is not an option"); 111 } 112 } 113 114 public void testSetFromLongerArgsListEqual() 115 { 116 List args = new ArrayList(); 117 args.add("--anotheropt"); 118 try { 119 boolean processed = opt.set("--dblopt=3.1415", args); 120 assertEquals("option processed", true, processed); 121 assertEquals("option value", new Double (3.1415), opt.getValue()); 122 assertEquals("argument removed from list", 1, args.size()); 123 } 124 catch (OptionException ite) { 125 fail("failure is not an option"); 126 } 127 } 128 129 public void testSetFromLongerArgsListSeparateString() 130 { 131 List args = new ArrayList(); 132 args.add("1234.567890"); 133 args.add("--anotheropt"); 134 try { 135 boolean processed = opt.set("--dblopt", args); 136 assertEquals("option processed", true, processed); 137 assertEquals("option value", new Double (1234.567890), opt.getValue()); 138 assertEquals("argument removed from list", 1, args.size()); 139 } 140 catch (OptionException ite) { 141 fail("failure is not an option"); 142 } 143 } 144 145 public void testSetInvalidValueDanglingEquals() 146 { 147 List args = new ArrayList(); 148 args.add("--anotheropt"); 149 try { 150 boolean processed = opt.set("--dblopt=", args); 151 fail("exception expected"); 152 } 153 catch (OptionException ite) { 154 } 155 } 156 157 } 158 | Popular Tags |