001: /*
002: Copyright 2004-2007 Paul R. Holser, Jr. All rights reserved.
003: Licensed under the Academic Free License version 3.0
004: */
005:
006: package joptsimple;
007:
008: import java.util.Collections;
009:
010: import junit.framework.TestCase;
011:
012: /**
013: * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
014: * @version $Id: AbbreviationMapToJavaUtilMapTest.java,v 1.2 2007/04/21 22:30:21 pholser Exp $
015: */
016: public class AbbreviationMapToJavaUtilMapTest extends TestCase {
017: private AbbreviationMap abbreviations;
018:
019: protected void setUp() throws Exception {
020: super .setUp();
021: abbreviations = new AbbreviationMap();
022: }
023:
024: public void testEmpty() {
025: assertEquals(Collections.EMPTY_MAP, abbreviations
026: .toJavaUtilMap());
027: }
028:
029: public void testAddingOne() {
030: abbreviations.put("box", "2");
031:
032: assertEquals(Collections.singletonMap("box", "2"),
033: abbreviations.toJavaUtilMap());
034: }
035:
036: public void testAddingManyWithNoCommonPrefix() {
037: abbreviations.put("box", "1");
038: abbreviations.put("cat", "2");
039: abbreviations.put("dog", "3");
040:
041: assertEquals("{box=1, cat=2, dog=3}", abbreviations
042: .toJavaUtilMap().toString());
043: }
044:
045: public void testAddingTwoWithCommonPrefix() {
046: abbreviations.put("box", "3");
047: abbreviations.put("boy", "4");
048:
049: assertEquals("{box=3, boy=4}", abbreviations.toJavaUtilMap()
050: .toString());
051: }
052:
053: public void testAddingThreeWithSuccessivelySmallerPrefixes() {
054: abbreviations.put("boy", "3");
055: abbreviations.put("bo", "2");
056: abbreviations.put("b", "1");
057:
058: assertEquals("{b=1, bo=2, boy=3}", abbreviations
059: .toJavaUtilMap().toString());
060: }
061:
062: public void testAddingThreeWithSuccessivelyLargerPrefixes() {
063: abbreviations.put("b", "1");
064: abbreviations.put("bo", "2");
065: abbreviations.put("boy", "3");
066:
067: assertEquals("{b=1, bo=2, boy=3}", abbreviations
068: .toJavaUtilMap().toString());
069: }
070:
071: public void testAddingThreeWithMixOfPrefixSize() {
072: abbreviations.put("boy", "3");
073: abbreviations.put("b", "1");
074: abbreviations.put("bo", "2");
075:
076: assertEquals("{b=1, bo=2, boy=3}", abbreviations
077: .toJavaUtilMap().toString());
078: }
079:
080: public void testAddingOneThenReplacing() {
081: abbreviations.put("box", "2");
082: abbreviations.put("box", "3");
083:
084: assertEquals("{box=3}", abbreviations.toJavaUtilMap()
085: .toString());
086: }
087:
088: public void testRemoveKeyWithCommonPrefix() {
089: abbreviations.put("box", "-1");
090: abbreviations.put("boy", "-2");
091: abbreviations.remove("box");
092:
093: assertEquals("{boy=-2}", abbreviations.toJavaUtilMap()
094: .toString());
095: }
096:
097: public void testAddKeysWithCommonPrefixesStairstepStyle() {
098: abbreviations.put("a", "1");
099: abbreviations.put("abc", "2");
100: abbreviations.put("abcde", "3");
101:
102: assertEquals("{a=1, abc=2, abcde=3}", abbreviations
103: .toJavaUtilMap().toString());
104: }
105:
106: public void testAddKeysWithCommonPrefixesStairstepStyleJumbled() {
107: abbreviations.put("a", "1");
108: abbreviations.put("abcde", "3");
109: abbreviations.put("abc", "2");
110:
111: assertEquals("{a=1, abc=2, abcde=3}", abbreviations
112: .toJavaUtilMap().toString());
113: }
114:
115: public void testMultipleKeysWithCommonPrefix() {
116: abbreviations.put("good", "4");
117: abbreviations.put("goodyear", "8");
118: abbreviations.put("go", "2");
119: abbreviations.put("goodyea", "7");
120: abbreviations.put("goodye", "6");
121: abbreviations.remove("goodyea");
122:
123: assertEquals("{go=2, good=4, goodye=6, goodyear=8}",
124: abbreviations.toJavaUtilMap().toString());
125: }
126: }
|