Changeset 655 in tmcsimulator for trunk/test/tmcsim


Ignore:
Timestamp:
09/11/2022 04:28:42 PM (4 years ago)
Author:
jdalbey
Message:

Improve unit tests.

Location:
trunk/test/tmcsim
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/tmcsim/cadsimulator/CADSimulatorConsoleTest.java

    r653 r655  
    3030    private CADConsoleViewer console; 
    3131    private StringWriter sw; 
    32  
     32    // Setup a path for temp files 
     33    static String tmpPath = "/tmp/";// default path is for linux 
     34    static 
     35    { 
     36        String myOs = System.getProperty("os.name").toLowerCase(); 
     37        if (myOs.indexOf("win") >= 0)  
     38        { 
     39          tmpPath = "C:/TEMP/";  // alt path for Windows 
     40        } 
     41    } 
    3342    public CADSimulatorConsoleTest(String testName) 
    3443    { 
     
    7079 
    7180    /** 
    72      * compare StringWriter contents against expected 
     81     * obsolete: compare StringWriter contents against expected 
    7382     */ 
    74     private void verify(String msg, String expect) 
     83    private void verify0(String msg, String expect) 
    7584    { 
    7685        String result = sw.toString().trim(); 
     
    8594        assertTrue(msg + ": " + result, match); 
    8695    } 
    87  
     96    /** compare StringWriter contents against expected 
     97     *  @param expected contains just the most recent lines of output 
     98     *  @param errmsg message to be displayed if test fails 
     99     *  improved to verify line by line 
     100     */ 
     101    private void verify(String errmsg, String expect) 
     102    { 
     103        String[] results = sw.toString().trim().split("\n");   // split into lines 
     104        String[] expecteds = expect.trim().split("\n"); 
     105        // Work backwards from the most recent line of output  
     106        for (int item=expecteds.length-1; item >= 0; item--) 
     107        { 
     108            //System.out.println("Verifying "+expecteds[item]+" against "+results[item]); 
     109            assertEquals(errmsg + " line "+item, expecteds[item], results[item]); 
     110        }     
     111    }             
    88112    public static void pause(int millis) 
    89113    { 
     
    134158        CADClientInterface ci = mock(CADClientInterface.class); 
    135159        app.theCoordinator.registerForCallback(ci); 
     160        pause(500); 
    136161        verify("connected 1 terminal output incorrect: ", expected2); 
    137162        String expected3 = 
     
    286311            +"FEPSim_IP_addr = localhost\n" 
    287312            +"Output_Destination = Console\n" 
    288             +"Highway_Status_File = /tmp/highway_status.json\n"; 
     313            +"Highway_Status_File = "+tmpPath+"highway_status.json\n"; 
    289314    static final String paramicsData = "ParamicsCommHost = 127.0.0.1\n" 
    290315            + "ParamicsCommPort       = 4450\n" 
  • trunk/test/tmcsim/highwaymodel/HighwaysTest.java

    r653 r655  
    2222public class HighwaysTest extends TestCase { 
    2323 
     24    // Setup a path for temp files 
     25    static String tmpPath = "/tmp/";// default path is for linux 
     26    static 
     27    { 
     28        String myOs = System.getProperty("os.name").toLowerCase(); 
     29        if (myOs.indexOf("win") >= 0)  
     30        { 
     31          tmpPath = "C:/TEMP/";  // alt path for Windows 
     32        } 
     33    }  
     34     
     35     
    2436    public HighwaysTest(String testName) { 
    2537        super(testName); 
     
    3143        PrintWriter writer = null; 
    3244        try { 
    33             writer = new PrintWriter(new FileWriter("/tmp/postmiles1.txt")); 
     45            writer = new PrintWriter(new FileWriter(tmpPath + "postmiles1.txt")); 
    3446            writer.println("5 S 0.9,33.408425,-117.599923,CALAFIA,0,0"); 
    3547            writer.println("5 N 1.24,33.413051,-117.601964,MAGDALENA,0,0"); 
     
    3749            writer.close(); 
    3850 
    39             writer = new PrintWriter(new FileWriter("/tmp/postmiles2.txt")); 
     51            writer = new PrintWriter(new FileWriter(tmpPath + "postmiles2.txt")); 
    4052            writer.println("5 N 5.89,33.459637,-117.657305,ESTRELLA2,0,0"); 
    4153            writer.println("5 S 6.47,33.464281,-117.665631,SACRAMENTO,-0.56275,-0.826627"); 
     
    4759            writer.close(); 
    4860 
    49             writer = new PrintWriter(new FileWriter("/tmp/postmiles3.txt")); 
     61            writer = new PrintWriter(new FileWriter(tmpPath + "/postmiles3.txt")); 
    5062            writer.println("73 N 23.9,33.643656,-117.859875,BISON 2,0.976131,0.217185"); 
    5163            writer.println("55 S 6.88,33.697495,-117.862677,MACARTHU1,-0.710326,0.703873"); 
     
    6375    protected void tearDown() throws Exception { 
    6476        super.tearDown(); 
    65         Path path = FileSystems.getDefault().getPath("/tmp/", "postmiles1.txt"); 
     77        Path path = FileSystems.getDefault().getPath(tmpPath, "postmiles1.txt"); 
    6678        Files.delete(path); 
    67         path = FileSystems.getDefault().getPath("/tmp/", "postmiles2.txt"); 
     79        path = FileSystems.getDefault().getPath(tmpPath, "postmiles2.txt"); 
    6880        Files.delete(path); 
    69         path = FileSystems.getDefault().getPath("/tmp/", "postmiles3.txt"); 
     81        path = FileSystems.getDefault().getPath(tmpPath, "postmiles3.txt"); 
    7082        Files.delete(path); 
    7183    } 
     
    7486        System.out.println("test FindStation()"); 
    7587        Highways highways = new Highways( 
    76                 "/tmp/postmiles1.txt"); 
     88                tmpPath + "postmiles1.txt"); 
    7789        assertTrue(null != highways.findStation(5, DIRECTION.SOUTH, 0.9)); 
    7890        assertTrue(null != highways.findStation(5, DIRECTION.SOUTH, 1.49)); 
     
    8698        System.out.println("toString"); 
    8799        Highways highways = new Highways( 
    88                 "/tmp/postmiles2.txt"); 
     100                tmpPath + "postmiles2.txt"); 
    89101        highways.getHighwayByRouteNumber(5).stations.get(0).loops.get(0).vol = 1; 
    90102        String result = highways.toString(); 
     
    108120        System.out.println("toJson"); 
    109121        Highways highways = new Highways( 
    110                 "/tmp/postmiles1.txt"); 
     122                tmpPath + "postmiles1.txt"); 
    111123        String result = highways.toJson(); 
    112124        System.out.println(result); 
     
    130142        System.out.println("stationSort"); 
    131143        Highways highways = new Highways( 
    132                 "/tmp/postmiles3.txt"); 
     144                tmpPath + "postmiles3.txt"); 
    133145        String result = highways.toJson(); 
    134146        JSONParser parser = new JSONParser(); 
     
    155167        System.out.println("routeSort"); 
    156168        Highways highways = new Highways( 
    157                 "/tmp/postmiles3.txt"); 
     169                tmpPath + "postmiles3.txt"); 
    158170        String result = highways.toJson(); 
    159171        JSONParser parser = new JSONParser(); 
     
    180192        System.out.println("apply color"); 
    181193        Highways highways = new Highways( 
    182                 "/tmp/postmiles1.txt"); 
     194                tmpPath + "postmiles1.txt"); 
    183195        highways.applyColorToHighwayStretch(5, Station.DIRECTION.SOUTH, 0.9, 2.0, 
    184196                LoopDetector.DOTCOLOR.RED); 
Note: See TracChangeset for help on using the changeset viewer.