001    package aima.test.search.map;
002    
003    import junit.framework.TestCase;
004    import aima.search.map.ExtendableMap;
005    import aima.search.map.MapStepCostFunction;
006    
007    /**
008     * @author Ciaran O'Reilly
009     * 
010     */
011    
012    public class MapStepCostFunctionTest extends TestCase {
013            MapStepCostFunction mscf;
014    
015            @Override
016            public void setUp() {
017                    ExtendableMap aMap = new ExtendableMap();
018                    aMap.addBidirectionalLink("A", "B", 5.0);
019                    aMap.addBidirectionalLink("A", "C", 6.0);
020                    aMap.addBidirectionalLink("B", "C", 4.0);
021                    aMap.addBidirectionalLink("C", "D", 7.0);
022                    aMap.addUnidirectionalLink("B", "E", 14.0);
023    
024                    mscf = new MapStepCostFunction(aMap);
025            }
026    
027            public void testCosts() {
028                    assertEquals(new Double(5), mscf.calculateStepCost("A", "B", "Go"));
029                    assertEquals(new Double(6), mscf.calculateStepCost("A", "C", "Go"));
030                    assertEquals(new Double(4), mscf.calculateStepCost("B", "C", "Go"));
031                    assertEquals(new Double(7), mscf.calculateStepCost("C", "D", "Go"));
032                    assertEquals(new Double(14), mscf.calculateStepCost("B", "E", "Go"));
033                    //
034                    assertEquals(new Double(5), mscf.calculateStepCost("B", "A", "Go"));
035                    assertEquals(new Double(6), mscf.calculateStepCost("C", "A", "Go"));
036                    assertEquals(new Double(4), mscf.calculateStepCost("C", "B", "Go"));
037                    assertEquals(new Double(7), mscf.calculateStepCost("D", "C", "Go"));
038                    //
039                    assertEquals(new Double(1), mscf.calculateStepCost("X", "Z", "Go"));
040                    assertEquals(new Double(1), mscf.calculateStepCost("A", "Z", "Go"));
041                    assertEquals(new Double(1), mscf.calculateStepCost("A", "D", "Go"));
042                    assertEquals(new Double(1), mscf.calculateStepCost("A", "E", "Go"));
043            }
044    }