#!/bin/bash # test script for the road network simulator # this version only produces output for tests RoadNework fails # author Douglas Jones # version Feb. 26, 2021 # test1 java RoadNetwork -- with a missing file name echo "Error: missing command line argument, a file name" > expectedDotErr touch expectedDotOut java RoadNetwork > systemDotOut &> systemDotErr if [ $? -eq 0 ] ; then # program did System.exit( 0 ); echo "test1: java Roadnetwork -- terminated with System.exit( 0 )" else # program did System.exit( !=0 ); diff expectedDotOut systemDotOut if [ $? -ne 0 ] ; then echo "test1: java Roadnetwork -- unexpected normal output" fi diff expectedDotErr systemDotErr if [ $? -ne 0 ] ; then echo "test1: java Roadnetwork -- the wrong error message" fi fi rm expectedDotErr expectedDotOut systemDotErr systemDotOut # test2 java RoadNetwork nonexistant blather -- with a missing file name echo "Warning: extra command line argument: blather" > expectedDotErr echo "Error: could not open file: nonexistant" >> expectedDotErr touch expectedDotOut java RoadNetwork nonexistant blather > systemDotOut &> systemDotErr if [ $? -eq 0 ] ; then # program did System.exit( 0 ); echo "test2: java Roadnetwork -- terminated with System.exit( 0 )" else # program did System.exit( !=0 ); diff expectedDotOut systemDotOut if [ $? -ne 0 ] ; then echo "test2: java Roadnetwork none -- unexpected normal output" fi diff expectedDotErr systemDotErr if [ $? -ne 0 ] ; then echo "test2: java Roadnetwork none -- the wrong error message" fi fi rm expectedDotErr expectedDotOut systemDotErr systemDotOut # test3 java RoadNetwork fuzztest touch expectedDotOut java Fuzz 256 > testinput java RoadNetwork testinput blather > systemDotOut &> systemDotErr if [ $? -eq 0 ] ; then # program did System.exit( 0 ); // the likelihood of this is tiny!! echo "test3: java Roadnetwork fuzz -- terminated with System.exit( 0 )" else # program did System.exit( !=0 ); diff expectedDotOut systemDotOut if [ $? -ne 0 ] ; then echo "test3: java Roadnetwork fuzz -- unexpected normal output" fi grep exception systemDotErr if [ $? -eq 0 ] ; then echo "test3: java Roadnetwork fuzz -- threw an exception" fi fi rm expectedDotOut systemDotErr systemDotOut testinput # test4 java RoadNetwork testfile -- just one word, intersection echo "intersection" > testinput echo "Warning: intersection: name missing" > expectedDotErr echo "Warning: intersection ???: traversal time missing" >> expectedDotErr echo "Warning: intersection ??? 99999.0: semicolon missing" >> expectedDotErr touch expectedDotOut java RoadNetwork testinput > systemDotOut &> systemDotErr if [ $? -eq 0 ] ; then # program did System.exit( 0 ); echo "test4: java Roadnetwork -- terminated with System.exit( 0 )" else # program did System.exit( !=0 ); diff expectedDotOut systemDotOut if [ $? -ne 0 ] ; then echo "test4: java Roadnetwork none -- unexpected normal output" fi diff expectedDotErr systemDotErr if [ $? -ne 0 ] ; then echo "test4: java Roadnetwork none -- the wrong error message" fi fi rm expectedDotErr expectedDotOut systemDotErr systemDotOut testinput # test5 java RoadNetwork testfile -- one intersection, defective road echo "intersection A 1.0 ;" > testinput echo "road" >> testinput echo "Warning: road: source missing" > expectedDotErr echo "Warning: road: destination missing" >> expectedDotErr echo "Warning: road ??? ???: travel time missing" >> expectedDotErr echo "Warning: road ??? ??? 99999.0: semicolon missing" >> expectedDotErr echo "Warning: road ??? ??? 99999.0: undefined source intersection?" >> expectedDotErr echo "Warning: road ??? ??? 99999.0: undefined destination intersection?" >> expectedDotErr touch expectedDotOut java RoadNetwork testinput > systemDotOut &> systemDotErr if [ $? -eq 0 ] ; then # program did System.exit( 0 ); echo "test5: java Roadnetwork -- terminated with System.exit( 0 )" else # program did System.exit( !=0 ); diff expectedDotOut systemDotOut if [ $? -ne 0 ] ; then echo "test5: java Roadnetwork none -- unexpected normal output" fi diff expectedDotErr systemDotErr if [ $? -ne 0 ] ; then echo "test5: java Roadnetwork none -- the wrong error message" fi fi rm expectedDotErr expectedDotOut systemDotErr systemDotOut testinput