001    package ps6.test;
002    
003    import ps6.Address;
004    
005    /**
006     * A test record is a fairly simple record type to hold a query and its expected
007     * results
008     * 
009     * @author tws
010     */
011    public final class TestRecord {
012            
013        //TODO: make sure this points to /cse/courses/cse331/tigerdb when you turn-in the problem set
014        private static final String tigerBaseDir = "/cse/courses/cse331/tigerdb";
015    
016        /**
017         * Database information the various testing databases
018         * @author tws
019         */
020        public static enum TestDB{
021            TINY ("tiny"),
022                SMALL ("small"),
023                //MYDB ("mydb"),
024                MEDIUM ("medium");
025                    
026            private final String dbPath;
027            TestDB(String name){
028                this.dbPath = tigerBaseDir + "/" + name;
029            }
030            public String dbPath(){
031                return dbPath;
032            }
033        }
034            
035        /** Types of tests, e.g. a walking test or an invalid address test */
036        public static enum TestType 
037        {WALKING,DRIVING,INVALID_DIR_TYPE,INVALID_ADDRESS,NO_PATH};
038           
039        private final String testName;
040        private final TestDB db;
041        private final TestType type;
042            
043        private final Address start;
044        private final Address end;
045        
046        private final String[] directions;
047        private final String tripLength;
048        private final double length;
049        private final String errorMessage;
050        
051        /**
052         * 
053         * @param testName name of the test (for use by JUnit) 
054         * @param db database information for the test
055         * @param type type of the test
056         * @param start starting address of the query
057         * @param end ending address of the query
058         * @param directions sequence of directions lines expected from getDirections, or null if we
059         * expect not to find any directions. the elements must not contain newlines
060         * at the end.
061         * @param tripLength the trip length or trip time that appear at the end of the directions
062         * @param length expected length of the path, or NaN if we expect not to find any
063         * directions
064         * @param errorMessage expected error message or null if no error is expected
065         */
066        public TestRecord(String testName,TestDB db,TestType type, 
067                          Address start, Address end, 
068                          String[] directions, String tripLength, double length, 
069                          String errorMessage) {
070            this.db = db;
071            this.testName = testName;
072            this.type = type;
073            this.start = start;
074            this.end = end;
075            this.directions = directions;
076            this.tripLength = tripLength;
077            this.length = length;
078            this.errorMessage = errorMessage;
079        }
080        
081        /**
082         * Get a string rep. of the direction type for the test (e.g. "w" or "d")
083         * @return a string representation of the direction type for the test
084         */
085        public String getDirectionType() {
086            switch (type){
087            case WALKING:
088                return "w";
089            case INVALID_DIR_TYPE:
090                return "q";
091            case DRIVING:
092            default:
093                return "d";
094            }
095        }
096        
097        /**
098         * Get the name of the Test
099         * @return the name of the test
100         */
101        public String getTestName(){
102            return testName;
103        }
104    
105        /**
106         * Get the starting test's starting address
107         * @return the starting address
108         */
109        public Address getStart() {
110            return start;
111        }
112    
113        /**
114         * Get the test's ending address
115         * @return the ending address
116         */
117        public Address getEnd() {
118            return end;
119        }
120    
121        /**
122         * Get the type of test
123         * @return the type of test
124         */
125        public TestType getType() {
126            return type;
127        }
128    
129        /**
130         * Get the expected direction lines
131         * @return the expected direction lines
132         */
133        public String[] getDirections() {
134            return directions;
135        }
136    
137        /**
138         * Get the expected length / travel time line
139         * @return the expected length / travel time line
140         */
141        public String getTripLength() {
142            return tripLength;
143        }
144    
145        /**
146         * Get the expected length of the path
147         * @return the expected length of path
148         */
149        public double getLength() {
150            return length;
151        }
152    
153        /**
154         * Get the expected error message
155         * @return the expected error message
156         */
157        public String getErrorMessage() {
158            return errorMessage;
159        }
160            
161        /**
162         * Get the database information for the test
163         * @return the database for the test
164         */
165        public TestDB getDb(){
166            return db;
167        }
168            
169    }