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            MEDIUM ("medium"),
024            //MYDB ("mydb"),
025            LARGE ("large");
026    
027            private final String dbPath;
028            TestDB(String name) {
029                this.dbPath = tigerBaseDir + "/" + name;
030            }
031            public String dbPath() {
032                return dbPath;
033            }
034        }
035    
036        /** Types of tests, e.g. a walking test or an invalid address test */
037        public static enum TestType
038        {WALKING,DRIVING,INVALID_DIR_TYPE,INVALID_ADDRESS,NO_PATH};
039    
040        private final String testName;
041        private final TestDB db;
042        private final TestType type;
043    
044        private final Address start;
045        private final Address end;
046    
047        private final String[] directions;
048        private final String tripLength;
049        private final double length;
050        private final String errorMessage;
051    
052        /**
053         *
054         * @param testName name of the test (for use by JUnit)
055         * @param db database information for the test
056         * @param type type of the test
057         * @param start starting address of the query
058         * @param end ending address of the query
059         * @param directions sequence of directions lines expected from getDirections, or null if we
060         * expect not to find any directions. the elements must not contain newlines
061         * at the end.
062         * @param tripLength the trip length or trip time that appear at the end of the directions
063         * @param length expected length of the path, or NaN if we expect not to find any
064         * directions
065         * @param errorMessage expected error message or null if no error is expected
066         */
067        public TestRecord(String testName,TestDB db,TestType type,
068                Address start, Address end,
069                String[] directions, String tripLength, double length,
070                String errorMessage) {
071            this.db = db;
072            this.testName = testName;
073            this.type = type;
074            this.start = start;
075            this.end = end;
076            this.directions = directions;
077            this.tripLength = tripLength;
078            this.length = length;
079            this.errorMessage = errorMessage;
080        }
081    
082        /**
083         * Get a string rep. of the direction type for the test (e.g. "w" or "d")
084         * @return a string representation of the direction type for the test
085         */
086        public String getDirectionType() {
087            switch (type) {
088            case WALKING:
089                return "w";
090            case INVALID_DIR_TYPE:
091                return "q";
092            case DRIVING:
093            default:
094                return "d";
095            }
096        }
097    
098        /**
099         * Get the name of the Test
100         * @return the name of the test
101         */
102        public String getTestName() {
103            return testName;
104        }
105    
106        /**
107         * Get the starting test's starting address
108         * @return the starting address
109         */
110        public Address getStart() {
111            return start;
112        }
113    
114        /**
115         * Get the test's ending address
116         * @return the ending address
117         */
118        public Address getEnd() {
119            return end;
120        }
121    
122        /**
123         * Get the type of test
124         * @return the type of test
125         */
126        public TestType getType() {
127            return type;
128        }
129    
130        /**
131         * Get the expected direction lines
132         * @return the expected direction lines
133         */
134        public String[] getDirections() {
135            return directions;
136        }
137    
138        /**
139         * Get the expected length / travel time line
140         * @return the expected length / travel time line
141         */
142        public String getTripLength() {
143            return tripLength;
144        }
145    
146        /**
147         * Get the expected length of the path
148         * @return the expected length of path
149         */
150        public double getLength() {
151            return length;
152        }
153    
154        /**
155         * Get the expected error message
156         * @return the expected error message
157         */
158        public String getErrorMessage() {
159            return errorMessage;
160        }
161    
162        /**
163         * Get the database information for the test
164         * @return the database for the test
165         */
166        public TestDB getDb() {
167            return db;
168        }
169    
170    }