001package algs31;
002
003import stdlib.*;
004
005public class MySTTest {
006
007        private static void assertEquals(Object expected, Object actual) {
008                if (expected == null) {
009                        if (actual != null) throw new AssertionError();
010                } else {
011                        if (! expected.equals (actual)) throw new AssertionError();
012                }
013        }
014
015        public static void testMin() {
016                // This is a fully random test.
017                // These tests are better if you can come up with one.
018                for (int numTrials = 100; numTrials > 0; numTrials--) {
019                        BinarySearchST<Integer,Integer> st = new BinarySearchST<>();
020                        assertEquals (null, st.min ());
021                        int min = Integer.MAX_VALUE;
022                        for (int numAdded = 100; numAdded > 0; numAdded--) {
023                                int next = StdRandom.uniform (1000);
024                                st.put (next, next*10);
025                                min = Math.min (min, next);
026                                assertEquals (min, st.min ());
027                        }
028                }
029        }
030
031        public static void testMax() {
032                // This is a test with specific values
033                // Not as good as a random test.
034                BinarySearchST<Integer,Integer> st = new BinarySearchST<>();
035                assertEquals (null, st.max()); // empty
036                st.put (5, 50);
037                assertEquals (5, st.max());  // one
038                st.put (2, 20);
039                assertEquals (5, st.max());  // does not change
040                st.put (7, 70);
041                assertEquals (7, st.max());  // changes
042                st.put (1, 10);
043                assertEquals (7, st.max());  // does not change
044                st.put (8, 80);
045                assertEquals (8, st.max());  // changes
046
047                // symmetrically
048                st = new BinarySearchST<>();
049                assertEquals (null, st.max()); // empty
050                st.put (5, 50);
051                assertEquals (5, st.max());  // one
052                st.put (7, 70);
053                assertEquals (7, st.max());  // changes
054                st.put (2, 20);
055                assertEquals (7, st.max());  // does not change
056                st.put (8, 80);
057                assertEquals (8, st.max());  // changes
058                st.put (1, 10);
059                assertEquals (8, st.max());  // does not change
060        }
061
062        public static void testFloor() {
063                // TODO: Write a test.  Try to write a random one, if you can.
064        }
065
066        public static void testCeiling() {
067                // TODO: Write a test.  Try to write a random one, if you can.
068        }
069
070        public static void testSelect() {
071                // TODO: Write a test.
072        }
073
074        public static void testRank() {
075                // TODO: Write a test.
076        }
077
078        public static void testDeleteMin() {
079                // TODO: Write a test.
080        }
081
082        public static void testDeleteMax() {
083                // TODO: Write a test.
084        }
085
086        public static void testKeys() {
087                // TODO: Write a test.
088        }
089
090        public static void main (String[] args) {
091                testMin();
092                testMax();
093                testFloor();
094                testCeiling();
095                testSelect();
096                testRank();
097                testDeleteMin();
098                testDeleteMax();
099                testKeys();
100        }
101}