Example #1
0
 def test_design_log_storage_system(self):
     commands = ["LogSystem", "put", "put", "put", "retrieve", "retrieve"]
     params = [[], [1, "2017:01:01:23:59:59"], [2, "2017:01:01:22:59:59"], [3, "2016:01:01:00:00:00"],
               ["2016:01:01:01:01:01", "2017:01:01:23:00:00", "Year"],
               ["2016:01:01:01:01:01", "2017:01:01:23:00:00", "Hour"]]
     res = [None, None, None, None, [3, 1, 2], [1, 2]]
     test_by_reflect(self, 'q635_design_log_storage_system', commands, params, res)
    def test_shortest_word_distance_ii(self):
        commands = ["WordDistance", "shortest", "shortest"]
        params = [[["practice", "makes", "perfect", "coding", "makes"]],
                  ["coding", "practice"], ["makes", "coding"]]
        res = [None, 3, 1]

        test_by_reflect(self, 'q244_shortest_word_distance_ii', commands,
                        params, res)
 def test_design_hit_counter(self):
     commands = [
         "HitCounter", "hit", "hit", "hit", "getHits", "hit", "getHits",
         "getHits"
     ]
     params = [[], [1], [2], [3], [4], [300], [300], [301]]
     res = [None, None, None, None, 3, None, 4, 3]
     test_by_reflect(self, 'q362_design_hit_counter', commands, params, res)
Example #4
0
    def test_amazon(self):
        commands = [
            "MinStack", "push", "push", "push", "getMin", "pop", "top",
            "getMin"
        ]
        params = [[], [-2], [0], [-3], [], [], [], []]
        res = [None, None, None, None, -3, None, 0, -2]

        test_by_reflect(self, 'm2212_amazon', commands, params, res)
Example #5
0
 def test_implement_trie_prefix_tree(self):
     commands = [
         "Trie", "insert", "search", "search", "startsWith", "insert",
         "search"
     ]
     params = [[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]]
     res = [None, None, True, False, True, None, True]
     test_by_reflect(self, 'q208_implement_trie_prefix_tree', commands,
                     params, res)
Example #6
0
    def test_design_phone_directory(self):
        commands = [
            "PhoneDirectory", "get", "get", "check", "get", "check", "release",
            "check"
        ]
        params = [[3], [], [], [2], [], [2], [2], [2]]
        res = [None, 0, 1, True, 2, False, None, True]

        test_by_reflect(self, 'q379_design_phone_directory', commands, params,
                        res)
    def test_design_compressed_string_iterator(self):
        commands = [
            "StringIterator4", "next", "next", "next", "next", "next", "next",
            "hasNext", "next", "hasNext"
        ]
        params = [["L1e2t1C1o1d1e1"], [], [], [], [], [], [], [], [], []]
        res = [None, "L", "e", "e", "t", "C", "o", True, "d", True]

        test_by_reflect(self, 'q604_design_compressed_string_iterator',
                        commands, params, res)
    def test_two_sum_iii_data_structure_design(self):
        commands = ["TwoSum1", "add", "add", "add", "find", "find"]
        params = [[], [1], [3], [5], [4], [7]]
        res = [None, None, None, None, True, False]
        test_by_reflect(self, 'q170_two_sum_iii_data_structure_design',
                        commands, params, res)

        commands = ["TwoSum1", "add", "find"]
        params = [[], [0], [0]]
        res = [None, None, False]
        test_by_reflect(self, 'q170_two_sum_iii_data_structure_design',
                        commands, params, res)
    def test_logger_rate_limiter(self):
        commands = [
            "Logger", "shouldPrintMessage", "shouldPrintMessage",
            "shouldPrintMessage", "shouldPrintMessage", "shouldPrintMessage",
            "shouldPrintMessage"
        ]
        params = [[], [1, "foo"], [2, "bar"], [3, "foo"], [8, "bar"],
                  [10, "foo"], [11, "foo"]]
        res = [None, True, True, False, False, False, True]

        test_by_reflect(self, 'q359_logger_rate_limiter', commands, params,
                        res)
Example #10
0
    def test_flatten_2d_vector(self):
        commands = [
            "Vector2D", "next", "next", "next", "hasNext", "hasNext", "next",
            "hasNext"
        ]
        params = [[[[1, 2], [3], [4]]], [], [], [], [], [], [], []]
        res = [None, 1, 2, 3, True, True, 4, False]
        test_by_reflect(self, 'q251_flatten_2d_vector', commands, params, res)

        commands = ["Vector2D", "hasNext", "next", "hasNext"]
        params = [[[[], [3]]], [], [], []]
        res = [None, True, 3, False]
        test_by_reflect(self, 'q251_flatten_2d_vector', commands, params, res)
Example #11
0
    def test_lru_cache(self):
        commands = [
            "LRUCache", "put", "put", "get", "put", "get", "put", "get", "get",
            "get"
        ]
        params = [[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]
        res = [None, None, None, 1, None, -1, None, -1, 3, 4]

        test_by_reflect(self, 'm4314_microsoft', commands, params, res)

        commands = ["LRUCache", "put", "put", "get", "put", "put", "get"]
        params = [[2], [2, 1], [2, 2], [2], [1, 1], [4, 1], [2]]
        res = [None, None, None, 2, None, None, -1]
        test_by_reflect(self, 'm4314_microsoft', commands, params, res)
    def test_microsoft(self):
        commands = [
            "TicTacToe", "move", "move", "move", "move", "move", "move", "move"
        ]
        params = [[3], [0, 0, 1], [0, 2, 2], [2, 2, 1], [1, 1, 2], [2, 0, 1],
                  [1, 0, 2], [2, 1, 1]]
        res = [None, 0, 0, 0, 0, 0, 0, 1]

        test_by_reflect(self, 'm4323_microsoft', commands, params, res)

        commands = ["TicTacToe", "move", "move", "move"]
        params = [[2], [0, 1, 1], [1, 1, 2], [1, 0, 1]]
        res = [None, 0, 0, 1]

        test_by_reflect(self, 'm4323_microsoft', commands, params, res)
Example #13
0
    def test_design_tic_tac_toe(self):
        commands = [
            "TicTacToe", "move", "move", "move", "move", "move", "move", "move"
        ]
        params = [[3], [0, 0, 1], [0, 2, 2], [2, 2, 1], [1, 1, 2], [2, 0, 1],
                  [1, 0, 2], [2, 1, 1]]
        res = [None, 0, 0, 0, 0, 0, 0, 1]

        test_by_reflect(self, 'q348_design_tic_tac_toe', commands, params, res)

        commands = ["TicTacToe", "move", "move", "move"]
        params = [[2], [0, 1, 1], [1, 1, 2], [1, 0, 1]]
        res = [None, 0, 0, 1]

        test_by_reflect(self, 'q348_design_tic_tac_toe', commands, params, res)
Example #14
0
    def test_design_snake_game(self):
        commands = [
            "SnakeGame", "move", "move", "move", "move", "move", "move"
        ]
        params = [[3, 2, [[1, 2], [0, 1]]], ["R"], ["D"], ["R"], ["U"], ["L"],
                  ["U"]]
        res = [None, 0, 0, 1, 1, 2, -1]
        test_by_reflect(self, 'q353_design_snake_game', commands, params, res)

        commands = [
            "SnakeGame", "move", "move", "move", "move", "move", "move",
            "move", "move", "move", "move", "move", "move"
        ]
        params = [[3, 3, [[2, 0], [0, 0], [0, 2],
                          [2, 2]]], ["D"], ["D"], ["R"], ["U"], ["U"], ["L"],
                  ["D"], ["R"], ["R"], ["U"], ["L"], ["D"]]
        res = [None, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3]
        test_by_reflect(self, 'q353_design_snake_game', commands, params, res)
    def test_design_search_autocomplete_system(self):
        commands = ["AutocompleteSystem", "input", "input", "input", "input"]
        params = [[["i love you", "island", "iroman", "i love leetcode"],
                   [5, 3, 2, 2]], ["i"], [" "], ["a"], ["#"]]
        res = [
            None, ["i love you", "island", "i love leetcode"],
            ["i love you", "i love leetcode"], [], []
        ]
        test_by_reflect(self, 'q642_design_search_autocomplete_system',
                        commands, params, res)

        commands = [
            "AutocompleteSystem", "input", "input", "input", "input", "input",
            "input", "input", "input", "input", "input", "input", "input",
            "input", "input"
        ]
        params = [[["abc", "abbc", "a"],
                   [3, 3, 3]], ["b"], ["c"], ["#"], ["b"], ["c"], ["#"], ["a"],
                  ["b"], ["c"], ["#"], ["a"], ["b"], ["c"], ["#"]]
        res = [
            None, [], [], [], ["bc"], ["bc"], [], ["a", "abbc", "abc"],
            ["abbc", "abc"], ["abc"], [], ["abc", "a", "abbc"],
            ["abc", "abbc"], ["abc"], []
        ]
        test_by_reflect(self, 'q642_design_search_autocomplete_system',
                        commands, params, res)

        commands = [
            "AutocompleteSystem", "input", "input", "input", "input", "input",
            "input", "input", "input", "input", "input", "input", "input"
        ]
        params = [[["i love you", "island", "iroman", "i love leetcode"],
                   [5, 3, 2, 2]], ["i"], [" "], ["a"], ["#"], ["i"], [" "],
                  ["a"], ["#"], ["i"], [" "], ["a"], ["#"]]
        res = [
            None, ["i love you", "island", "i love leetcode"],
            ["i love you", "i love leetcode"], [], [],
            ["i love you", "island", "i love leetcode"],
            ["i love you", "i love leetcode", "i a"], ["i a"], [],
            ["i love you", "island", "i a"],
            ["i love you", "i a", "i love leetcode"], ["i a"], []
        ]
        test_by_reflect(self, 'q642_design_search_autocomplete_system',
                        commands, params, res)
Example #16
0
    def test_google(self):
        commands = ["AutocompleteSystem", "input", "input", "input", "input"]
        params = [[["i love you", "island", "iroman", "i love leetcode"], [5, 3, 2, 2]], ["i"], [" "], ["a"], ["#"]]
        res = [None, ["i love you", "island", "i love leetcode"], ["i love you", "i love leetcode"], [], []]
        test_by_reflect(self, 'm1314_google', commands, params, res)

        commands = ["AutocompleteSystem", "input", "input", "input", "input", "input", "input", "input", "input",
                    "input", "input", "input", "input", "input", "input"]
        params = [[["abc", "abbc", "a"], [3, 3, 3]], ["b"], ["c"], ["#"], ["b"], ["c"], ["#"], ["a"], ["b"], ["c"],
                  ["#"], ["a"], ["b"], ["c"], ["#"]]
        res = [None, [], [], [], ["bc"], ["bc"], [], ["a", "abbc", "abc"], ["abbc", "abc"], ["abc"], [],
               ["abc", "a", "abbc"], ["abc", "abbc"], ["abc"], []]
        test_by_reflect(self, 'm1314_google', commands, params, res)

        commands = ["AutocompleteSystem", "input", "input", "input", "input", "input", "input", "input", "input", "input", "input",
         "input", "input"]
        params = [[["i love you", "island", "iroman", "i love leetcode"], [5, 3, 2, 2]], ["i"], [" "], ["a"], ["#"], ["i"], [" "],
         ["a"], ["#"], ["i"], [" "], ["a"], ["#"]]
        res = [None, ["i love you", "island", "i love leetcode"], ["i love you", "i love leetcode"], [], [],
         ["i love you", "island", "i love leetcode"], ["i love you", "i love leetcode", "i a"], ["i a"], [],
         ["i love you", "island", "i a"], ["i love you", "i a", "i love leetcode"], ["i a"], []]
        test_by_reflect(self, 'm1314_google', commands, params, res)
 def test_implement_queue_using_stacks(self):
     commands = ["MyQueue", "push", "push", "peek", "pop", "empty"]
     params = [[], [1], [2], [], [], []]
     res = [None, None, None, 1, 1, False]
     test_by_reflect(self, 'q232_implement_queue_using_stacks', commands,
                     params, res)
 def test_min_stack(self):
     commands = ["MinStack", "push", "push", "push", "getMin", "pop", "top", "getMin"]
     params = [[], [-2], [0], [-3], [], [], [], []]
     res = [None, None, None, None, -3, None, 0, -2]
     test_by_reflect(self, 'q155_min_stack', commands, params, res)
 def test_moving_average_from_data_stream(self):
     commands = ["MovingAverage", "next", "next", "next", "next"]
     params = [[3], [1], [10], [3], [5]]
     res = [None, 1.0, 5.5, 4.666666666666667, 6.0]
     test_by_reflect(self, 'q346_moving_average_from_data_stream', commands,
                     params, res)