From 963ebd210bd3337bcf0c313e4f8ca8dbff03ee53 Mon Sep 17 00:00:00 2001 From: openset Date: Fri, 15 Nov 2019 10:57:13 +0800 Subject: [PATCH] Update: test --- internal/leetcode/question_data.go | 20 ++--- problems/01-matrix/01_matrix_test.go | 24 ++--- .../1_bit_and_2_bit_characters_test.go | 24 ++--- problems/132-pattern/132_pattern_test.go | 28 +++--- .../2-keys-keyboard/2_keys_keyboard_test.go | 32 +++---- problems/24-game/24_game_test.go | 24 ++--- problems/3sum-closest/3sum_closest_test.go | 48 +++++----- problems/3sum/3sum_test.go | 32 +++---- problems/4sum-ii/4sum_ii_test.go | 32 +++---- problems/4sum/4sum_test.go | 46 +++++----- .../accounts-merge/accounts_merge_test.go | 40 ++++----- problems/add-binary/add_binary_test.go | 36 ++++---- problems/add-digits/add_digits_test.go | 20 ++--- .../add_one_row_to_tree_test.go | 56 ++++++------ problems/add-strings/add_strings_test.go | 42 ++++----- .../add_to_array_form_of_integer_test.go | 36 ++++---- .../add_two_numbers_ii_test.go | 46 +++++----- .../add-two-numbers/add_two_numbers_test.go | 40 ++++----- .../arithmetic_slices_test.go | 44 ++++----- .../arranging-coins/arranging_coins_test.go | 48 +++++----- problems/array-nesting/array_nesting_test.go | 32 +++---- .../array_partition_i_test.go | 20 ++--- .../assign-cookies/assign_cookies_test.go | 30 +++---- .../available_captures_for_rook_test.go | 32 +++---- problems/base-7/base_7_test.go | 32 +++---- ...best_time_to_buy_and_sell_stock_ii_test.go | 28 +++--- .../best_time_to_buy_and_sell_stock_test.go | 32 +++---- .../binary_prefix_divisible_by_5_test.go | 36 ++++---- problems/buddy-strings/buddy_strings_test.go | 60 ++++++------- problems/bulb-switcher/bulb_switcher_test.go | 28 +++--- .../camelcase_matching_test.go | 48 +++++----- .../can_place_flowers_test.go | 34 +++---- .../climbing-stairs/climbing_stairs_test.go | 28 +++--- .../compare_version_numbers_test.go | 84 ++++++++--------- .../complement_of_base_10_integer_test.go | 32 +++---- .../construct_string_from_binary_tree_test.go | 24 ++--- .../container_with_most_water_test.go | 24 ++--- .../contains_duplicate_ii_test.go | 36 ++++---- ...sorted_array_to_binary_search_tree_test.go | 20 ++--- problems/count-and-say/count_and_say_test.go | 8 +- .../count_binary_substrings_test.go | 24 ++--- problems/count-primes/count_primes_test.go | 8 +- .../cousins_in_binary_tree_test.go | 60 ++++++------- .../day-of-the-week/day_of_the_week_test.go | 60 ++++++------- .../day-of-the-year/day_of_the_year_test.go | 40 ++++----- .../defanging_an_ip_address_test.go | 24 ++--- .../degree_of_an_array_test.go | 36 ++++---- .../delete_columns_to_make_sorted_test.go | 28 +++--- .../delete_node_in_a_linked_list_test.go | 52 +++++------ .../design-hashmap/design_hashmap_test.go | 12 +-- .../design-hashset/design_hashset_test.go | 12 +-- .../design_linked_list_test.go | 14 +-- .../detect-capital/detect_capital_test.go | 32 +++---- .../di-string-match/di_string_match_test.go | 28 +++--- problems/divisor-game/divisor_game_test.go | 24 ++--- .../excel_sheet_column_number_test.go | 48 +++++----- .../excel_sheet_column_title_test.go | 60 ++++++------- .../factorial_trailing_zeroes_test.go | 44 ++++----- .../fair-candy-swap/fair_candy_swap_test.go | 48 +++++----- .../fibonacci-number/fibonacci_number_test.go | 32 +++---- ...ll_numbers_disappeared_in_an_array_test.go | 28 +++--- .../find_common_characters_test.go | 24 ++--- .../find-pivot-index/find_pivot_index_test.go | 40 ++++----- ...mallest_letter_greater_than_target_test.go | 54 +++++------ .../find_the_town_judge_test.go | 34 +++---- ...first_unique_character_in_a_string_test.go | 8 +- problems/fizz-buzz/fizz_buzz_test.go | 28 +++--- .../flipping_an_image_test.go | 24 ++--- .../flower_planting_with_no_adjacent_test.go | 24 ++--- .../generate_parentheses_test.go | 36 ++++---- problems/goat-latin/goat_latin_test.go | 24 ++--- ...oups_of_special_equivalent_strings_test.go | 32 +++---- .../hamming-distance/hamming_distance_test.go | 24 ++--- problems/happy-number/happy_number_test.go | 28 +++--- .../height-checker/height_checker_test.go | 20 ++--- problems/house-robber/house_robber_test.go | 24 ++--- .../image-smoother/image_smoother_test.go | 24 ++--- .../implement-strstr/implement_strstr_test.go | 18 ++-- .../integer-to-roman/integer_to_roman_test.go | 44 ++++----- .../intersection_of_two_arrays_ii_test.go | 36 ++++---- .../intersection_of_two_linked_lists_test.go | 18 ++-- .../jewels_and_stones_test.go | 36 ++++---- .../k_closest_points_to_origin_test.go | 26 +++--- .../k_diff_pairs_in_an_array_test.go | 42 ++++----- .../kth_largest_element_in_an_array_test.go | 30 +++---- ...st_number_at_least_twice_of_others_test.go | 36 ++++---- .../largest_perimeter_triangle_test.go | 32 +++---- .../largest_time_for_given_digits_test.go | 28 +++--- .../last_stone_weight_test.go | 28 +++--- ...substring_in_lexicographical_order_test.go | 32 +++---- .../length_of_last_word_test.go | 8 +- ...ter_combinations_of_a_phone_number_test.go | 24 ++--- .../linked_list_cycle_test.go | 50 +++++------ .../long_pressed_name_test.go | 72 +++++++-------- .../longest_common_prefix_test.go | 28 +++--- ..._continuous_increasing_subsequence_test.go | 32 +++---- .../longest_palindromic_substring_test.go | 36 ++++---- ...tring_without_repeating_characters_test.go | 8 +- .../longest_uncommon_subsequence_i_test.go | 42 ++++----- .../magic_squares_in_grid_test.go | 28 +++--- .../majority-element/majority_element_test.go | 32 +++---- .../max_consecutive_ones_test.go | 24 ++--- ...aximize_distance_to_closest_person_test.go | 44 ++++----- ...ize_sum_of_array_after_k_negations_test.go | 36 ++++---- .../maximum_average_subarray_i_test.go | 24 ++--- .../maximum_depth_of_binary_tree_test.go | 32 +++---- .../maximum_number_of_balloons_test.go | 32 +++---- .../maximum_product_of_three_numbers_test.go | 32 +++---- .../maximum-subarray/maximum_subarray_test.go | 20 ++--- .../median_of_two_sorted_arrays_test.go | 90 +++++++++---------- .../merge_sorted_array_test.go | 52 +++++------ .../merge_two_binary_trees_test.go | 26 +++--- .../merge_two_sorted_lists_test.go | 52 +++++------ .../min_cost_climbing_stairs_test.go | 24 ++--- problems/min-stack/min_stack_test.go | 28 +++--- .../missing-number/missing_number_test.go | 28 +++--- .../monotonic-array/monotonic_array_test.go | 40 ++++----- .../most-common-word/most_common_word_test.go | 20 ++--- problems/move-zeroes/move_zeroes_test.go | 32 +++---- ..._repeated_element_in_size_2n_array_test.go | 32 +++---- problems/nim-game/nim_game_test.go | 24 ++--- .../non_decreasing_array_test.go | 36 ++++---- .../number-of-1-bits/number_of_1_bits_test.go | 32 +++---- .../number_of_digit_one_test.go | 64 ++++++------- .../number_of_recent_calls_test.go | 24 ++--- .../number_of_segments_in_a_string_test.go | 40 ++++----- ...th_total_durations_divisible_by_60_test.go | 24 ++--- .../palindrome_linked_list_test.go | 28 +++--- .../palindrome_number_test.go | 8 +- ...ay_into_three_parts_with_equal_sum_test.go | 36 ++++---- .../pascals_triangle_ii_test.go | 28 +++--- .../pascals-triangle/pascals_triangle_test.go | 20 ++--- problems/plus-one/plus_one_test.go | 32 +++---- .../positions_of_large_groups_test.go | 32 +++---- problems/power-of-four/power_of_four_test.go | 40 ++++----- .../power-of-three/power_of_three_test.go | 36 ++++---- problems/power-of-two/power_of_two_test.go | 36 ++++---- .../powerful_integers_test.go | 36 ++++---- problems/powx-n/powx_n_test.go | 38 ++++---- ..._size_of_factorial_zeroes_function_test.go | 32 +++---- .../range-sum-of-bst/range_sum_of_bst_test.go | 36 ++++---- .../range_sum_query_immutable_test.go | 36 ++++---- problems/ransom-note/ransom_note_test.go | 20 ++--- .../regular_expression_matching_test.go | 54 +++++------ ..._all_adjacent_duplicates_in_string_test.go | 24 ++--- ...emove_duplicates_from_sorted_array_test.go | 40 ++++----- ...remove_duplicates_from_sorted_list_test.go | 28 +++--- .../remove-element/remove_element_test.go | 54 +++++------ .../remove_outermost_parentheses_test.go | 28 +++--- .../reorder_data_in_log_files_test.go | 32 +++---- .../repeated_string_match_test.go | 42 ++++----- .../repeated_substring_pattern_test.go | 52 +++++------ .../reshape_the_matrix_test.go | 24 ++--- problems/reverse-bits/reverse_bits_test.go | 24 ++--- .../reverse-integer/reverse_integer_test.go | 8 +- .../reverse_linked_list_test.go | 20 ++--- .../reverse_only_letters_test.go | 28 +++--- .../reverse_string_ii_test.go | 42 ++++----- .../reverse-string/reverse_string_test.go | 28 +++--- .../reverse_vowels_of_a_string_test.go | 24 ++--- .../reverse_words_in_a_string_iii_test.go | 20 ++--- .../reverse_words_in_a_string_test.go | 28 +++--- .../robot_bounded_in_circle_test.go | 44 ++++----- .../robot_return_to_origin_test.go | 32 +++---- .../roman-to-integer/roman_to_integer_test.go | 8 +- problems/rotate-array/rotate_array_test.go | 36 ++++---- problems/rotate-image/rotate_image_test.go | 32 +++---- problems/rotate-string/rotate_string_test.go | 36 ++++---- .../rotated-digits/rotated_digits_test.go | 32 +++---- .../rotting-oranges/rotting_oranges_test.go | 32 +++---- problems/same-tree/same_tree_test.go | 36 ++++---- .../search_insert_position_test.go | 48 +++++----- .../self_dividing_numbers_test.go | 24 ++--- ...rtest_unsorted_continuous_subarray_test.go | 28 +++--- problems/simplify-path/simplify_path_test.go | 40 ++++----- .../single-number-ii/single_number_ii_test.go | 24 ++--- problems/single-number/single_number_test.go | 28 +++--- .../smallest-range-i/smallest_range_i_test.go | 48 +++++----- .../sort_array_by_parity_ii_test.go | 24 ++--- .../sort_array_by_parity_test.go | 20 ++--- ...split_a_string_in_balanced_strings_test.go | 28 +++--- problems/sqrtx/sqrtx_test.go | 32 +++---- .../squares_of_a_sorted_array_test.go | 24 ++--- problems/stone-game/stone_game_test.go | 24 ++--- .../string_compression_test.go | 32 +++---- .../string_to_integer_atoi_test.go | 8 +- .../string_without_aaa_or_bbb_test.go | 42 ++++----- .../student_attendance_record_i_test.go | 24 ++--- .../sum_of_even_numbers_after_queries_test.go | 24 ++--- ...sum_of_root_to_leaf_binary_numbers_test.go | 28 +++--- .../sum_of_two_integers_test.go | 30 +++---- .../symmetric-tree/symmetric_tree_test.go | 24 ++--- .../third_maximum_number_test.go | 40 ++++----- problems/to-lower-case/to_lower_case_test.go | 8 +- .../toeplitz-matrix/toeplitz_matrix_test.go | 24 ++--- .../transpose-matrix/transpose_matrix_test.go | 24 ++--- .../two_city_scheduling_test.go | 28 +++--- .../two_sum_ii_input_array_is_sorted_test.go | 42 ++++----- problems/two-sum/two_sum_test.go | 36 ++++---- .../ugly-number-ii/ugly_number_ii_test.go | 36 ++++---- problems/ugly-number/ugly_number_test.go | 40 ++++----- .../unique_email_addresses_test.go | 24 ++--- .../unique_morse_code_words_test.go | 24 ++--- .../univalued_binary_tree_test.go | 28 +++--- .../utf-8-validation/utf_8_validation_test.go | 36 ++++---- problems/valid-anagram/valid_anagram_test.go | 48 +++++----- .../valid-boomerang/valid_boomerang_test.go | 24 ++--- .../valid_mountain_array_test.go | 40 ++++----- problems/valid-number/valid_number_test.go | 76 ++++++++-------- .../valid_palindrome_ii_test.go | 36 ++++---- .../valid-palindrome/valid_palindrome_test.go | 40 ++++----- .../valid_parentheses_test.go | 8 +- problems/valid-sudoku/valid_sudoku_test.go | 36 ++++---- .../validate_ip_address_test.go | 44 ++++----- .../verifying_an_alien_dictionary_test.go | 36 ++++---- problems/word-break/word_break_test.go | 28 +++--- problems/word-pattern/word_pattern_test.go | 60 ++++++------- .../x_of_a_kind_in_a_deck_of_cards_test.go | 36 ++++---- .../zigzag_conversion_test.go | 36 ++++---- 219 files changed, 3575 insertions(+), 3575 deletions(-) diff --git a/internal/leetcode/question_data.go b/internal/leetcode/question_data.go index 4d23998f3..2b6c01d68 100644 --- a/internal/leetcode/question_data.go +++ b/internal/leetcode/question_data.go @@ -332,22 +332,22 @@ const testTpl = `package {{packageName}} import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func Test{{funcName}}(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 0, - expected: 0, + in: 0, + want: 0, }, } - for _, tc := range tests { - output := 0 - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := 0 + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/01-matrix/01_matrix_test.go b/problems/01-matrix/01_matrix_test.go index 2f5922b1c..c7178e416 100644 --- a/problems/01-matrix/01_matrix_test.go +++ b/problems/01-matrix/01_matrix_test.go @@ -5,42 +5,42 @@ import ( "testing" ) -type caseType struct { - input [][]int - expected [][]int +type testType struct { + in [][]int + want [][]int } func TestUpdateMatrix(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]int{ + in: [][]int{ {0, 0, 0}, {0, 1, 0}, {0, 0, 0}, }, - expected: [][]int{ + want: [][]int{ {0, 0, 0}, {0, 1, 0}, {0, 0, 0}, }, }, { - input: [][]int{ + in: [][]int{ {0, 0, 0}, {0, 1, 0}, {1, 1, 1}, }, - expected: [][]int{ + want: [][]int{ {0, 0, 0}, {0, 1, 0}, {1, 2, 1}, }, }, } - for _, tc := range tests { - output := updateMatrix(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := updateMatrix(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/1-bit-and-2-bit-characters/1_bit_and_2_bit_characters_test.go b/problems/1-bit-and-2-bit-characters/1_bit_and_2_bit_characters_test.go index 55b4e294b..f70c45639 100644 --- a/problems/1-bit-and-2-bit-characters/1_bit_and_2_bit_characters_test.go +++ b/problems/1-bit-and-2-bit-characters/1_bit_and_2_bit_characters_test.go @@ -2,26 +2,26 @@ package problem717 import "testing" -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestIsOneBitCharacter(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 0, 0}, - expected: true, + in: []int{1, 0, 0}, + want: true, }, { - input: []int{1, 1, 1, 0}, - expected: false, + in: []int{1, 1, 1, 0}, + want: false, }, } - for _, tc := range tests { - output := isOneBitCharacter(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isOneBitCharacter(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/132-pattern/132_pattern_test.go b/problems/132-pattern/132_pattern_test.go index 4f6a9d64a..eeaa7b8d7 100644 --- a/problems/132-pattern/132_pattern_test.go +++ b/problems/132-pattern/132_pattern_test.go @@ -2,30 +2,30 @@ package problem456 import "testing" -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestFind132pattern(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 3, 4}, - expected: false, + in: []int{1, 2, 3, 4}, + want: false, }, { - input: []int{3, 1, 4, 2}, - expected: true, + in: []int{3, 1, 4, 2}, + want: true, }, { - input: []int{-1, 3, 2, 0}, - expected: true, + in: []int{-1, 3, 2, 0}, + want: true, }, } - for _, tc := range tests { - output := find132pattern(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := find132pattern(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/2-keys-keyboard/2_keys_keyboard_test.go b/problems/2-keys-keyboard/2_keys_keyboard_test.go index c5fa9a9e2..f5dc7cd19 100644 --- a/problems/2-keys-keyboard/2_keys_keyboard_test.go +++ b/problems/2-keys-keyboard/2_keys_keyboard_test.go @@ -2,34 +2,34 @@ package problem650 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestMinSteps(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 1, - expected: 0, + in: 1, + want: 0, }, { - input: 3, - expected: 3, + in: 3, + want: 3, }, { - input: 30, - expected: 10, + in: 30, + want: 10, }, { - input: 97, - expected: 97, + in: 97, + want: 97, }, } - for _, tc := range tests { - output := minSteps(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := minSteps(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/24-game/24_game_test.go b/problems/24-game/24_game_test.go index bfc768743..d01352b98 100644 --- a/problems/24-game/24_game_test.go +++ b/problems/24-game/24_game_test.go @@ -2,26 +2,26 @@ package problem679 import "testing" -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestJudgePoint24(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{4, 1, 8, 7}, - expected: true, + in: []int{4, 1, 8, 7}, + want: true, }, { - input: []int{1, 2, 1, 2}, - expected: false, + in: []int{1, 2, 1, 2}, + want: false, }, } - for _, tc := range tests { - output := judgePoint24(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := judgePoint24(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/3sum-closest/3sum_closest_test.go b/problems/3sum-closest/3sum_closest_test.go index bf75c4b27..90cd6c8ec 100644 --- a/problems/3sum-closest/3sum_closest_test.go +++ b/problems/3sum-closest/3sum_closest_test.go @@ -2,44 +2,44 @@ package problem16 import "testing" -type caseType struct { - input []int - target int - expected int +type testType struct { + in []int + target int + want int } func TestThreeSumClosest(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{-1, 2, 1, -4}, - target: 1, - expected: 2, + in: []int{-1, 2, 1, -4}, + target: 1, + want: 2, }, { - input: []int{-1, 0, 1, 2, -1, -4}, - target: 1, - expected: 1, + in: []int{-1, 0, 1, 2, -1, -4}, + target: 1, + want: 1, }, { - input: []int{0, 0, 0, 0}, - target: 1, - expected: 0, + in: []int{0, 0, 0, 0}, + target: 1, + want: 0, }, { - input: []int{-2, 0, 0, 2, 2, 2}, - target: 2, - expected: 2, + in: []int{-2, 0, 0, 2, 2, 2}, + target: 2, + want: 2, }, { - input: []int{-2, 0, 0, 2, 2, 2, 2}, - target: 1, - expected: 0, + in: []int{-2, 0, 0, 2, 2, 2, 2}, + target: 1, + want: 0, }, } - for _, tc := range tests { - output := threeSumClosest(tc.input, tc.target) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := threeSumClosest(tt.in, tt.target) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/3sum/3sum_test.go b/problems/3sum/3sum_test.go index 7be0c7874..fa8763b85 100644 --- a/problems/3sum/3sum_test.go +++ b/problems/3sum/3sum_test.go @@ -5,43 +5,43 @@ import ( "testing" ) -type caseType struct { - input []int - expected [][]int +type testType struct { + in []int + want [][]int } func TestThreeSum(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{-1, 0, 1, 2, -1, -4}, - expected: [][]int{ + in: []int{-1, 0, 1, 2, -1, -4}, + want: [][]int{ {-1, -1, 2}, {-1, 0, 1}, }, }, { - input: []int{0, 0, 0, 0}, - expected: [][]int{ + in: []int{0, 0, 0, 0}, + want: [][]int{ {0, 0, 0}, }, }, { - input: []int{-2, 0, 0, 2, 2, 2}, - expected: [][]int{ + in: []int{-2, 0, 0, 2, 2, 2}, + want: [][]int{ {-2, 0, 2}, }, }, { - input: []int{-2, 0, 0, 2, 2, 2, 2}, - expected: [][]int{ + in: []int{-2, 0, 0, 2, 2, 2, 2}, + want: [][]int{ {-2, 0, 2}, }, }, } - for _, tc := range tests { - output := threeSum(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := threeSum(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/4sum-ii/4sum_ii_test.go b/problems/4sum-ii/4sum_ii_test.go index c8bf426d0..ed19e4509 100644 --- a/problems/4sum-ii/4sum_ii_test.go +++ b/problems/4sum-ii/4sum_ii_test.go @@ -2,28 +2,28 @@ package problem454 import "testing" -type caseType struct { - a []int - b []int - c []int - d []int - expected int +type testType struct { + a []int + b []int + c []int + d []int + want int } func TestFourSumCount(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - a: []int{1, 2}, - b: []int{-2, -1}, - c: []int{-1, 2}, - d: []int{0, 2}, - expected: 2, + a: []int{1, 2}, + b: []int{-2, -1}, + c: []int{-1, 2}, + d: []int{0, 2}, + want: 2, }, } - for _, tc := range tests { - output := fourSumCount(tc.a, tc.b, tc.c, tc.d) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc, output, tc.expected) + for _, tt := range tests { + got := fourSumCount(tt.a, tt.b, tt.c, tt.d) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt, got, tt.want) } } } diff --git a/problems/4sum/4sum_test.go b/problems/4sum/4sum_test.go index 44b306547..183b928e6 100644 --- a/problems/4sum/4sum_test.go +++ b/problems/4sum/4sum_test.go @@ -5,55 +5,55 @@ import ( "testing" ) -type caseType struct { - input []int - target int - expected [][]int +type testType struct { + in []int + target int + want [][]int } func TestFourSum(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 0, -1, 0, -2, 2}, + in: []int{1, 0, -1, 0, -2, 2}, target: 0, - expected: [][]int{ + want: [][]int{ {-2, -1, 1, 2}, {-2, 0, 0, 2}, {-1, 0, 0, 1}, }, }, { - input: []int{-1, 0, 1, 2, -1, -4}, + in: []int{-1, 0, 1, 2, -1, -4}, target: 0, - expected: [][]int{ + want: [][]int{ {-1, -1, 0, 2}, }, }, { - input: []int{0, 0, 0, 0}, + in: []int{0, 0, 0, 0}, target: 0, - expected: [][]int{ + want: [][]int{ {0, 0, 0, 0}, }, }, { - input: []int{-2, 0, 0, 2, 2, 2}, + in: []int{-2, 0, 0, 2, 2, 2}, target: 0, - expected: [][]int{ + want: [][]int{ {-2, 0, 0, 2}, }, }, { - input: []int{-2, 0, 0, 2, 2, 2, 2}, + in: []int{-2, 0, 0, 2, 2, 2, 2}, target: 0, - expected: [][]int{ + want: [][]int{ {-2, 0, 0, 2}, }, }, { - input: []int{-3, -2, -1, 0, 0, 1, 2, 3}, + in: []int{-3, -2, -1, 0, 0, 1, 2, 3}, target: 0, - expected: [][]int{ + want: [][]int{ {-3, -2, 2, 3}, {-3, -1, 1, 3}, {-3, 0, 0, 3}, @@ -65,17 +65,17 @@ func TestFourSum(t *testing.T) { }, }, { - input: []int{1, -2, -5, -4, -3, 3, 3, 5}, + in: []int{1, -2, -5, -4, -3, 3, 3, 5}, target: -11, - expected: [][]int{ + want: [][]int{ {-5, -4, -3, 1}, }, }, } - for _, tc := range tests { - output := fourSum(tc.input, tc.target) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := fourSum(tt.in, tt.target) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/accounts-merge/accounts_merge_test.go b/problems/accounts-merge/accounts_merge_test.go index 0c0ca7264..e95d5d934 100644 --- a/problems/accounts-merge/accounts_merge_test.go +++ b/problems/accounts-merge/accounts_merge_test.go @@ -6,35 +6,35 @@ import ( "testing" ) -type caseType struct { - input [][]string - expected [][]string +type testType struct { + in [][]string + want [][]string } func TestAccountsMerge(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]string{ + in: [][]string{ {"John", "johnsmith@mail.com", "john00@mail.com"}, {"John", "johnnybravo@mail.com"}, {"John", "johnsmith@mail.com", "john_newyork@mail.com"}, {"Mary", "mary@mail.com"}, }, - expected: [][]string{ + want: [][]string{ {"John", "john00@mail.com", "john_newyork@mail.com", "johnsmith@mail.com"}, {"John", "johnnybravo@mail.com"}, {"Mary", "mary@mail.com"}, }, }, { - input: [][]string{ + in: [][]string{ {"Alex", "Alex5@m.co", "Alex4@m.co", "Alex0@m.co"}, {"Ethan", "Ethan3@m.co", "Ethan3@m.co", "Ethan0@m.co"}, {"Kevin", "Kevin4@m.co", "Kevin2@m.co", "Kevin2@m.co"}, {"Gabe", "Gabe0@m.co", "Gabe3@m.co", "Gabe2@m.co"}, {"Gabe", "Gabe3@m.co", "Gabe4@m.co", "Gabe2@m.co"}, }, - expected: [][]string{ + want: [][]string{ {"Alex", "Alex0@m.co", "Alex4@m.co", "Alex5@m.co"}, {"Ethan", "Ethan0@m.co", "Ethan3@m.co"}, {"Gabe", "Gabe0@m.co", "Gabe2@m.co", "Gabe3@m.co", "Gabe4@m.co"}, @@ -42,40 +42,40 @@ func TestAccountsMerge(t *testing.T) { }, }, { - input: [][]string{ + in: [][]string{ {"David", "David0@m.co", "David4@m.co", "David3@m.co"}, {"David", "David5@m.co", "David5@m.co", "David0@m.co"}, {"David", "David1@m.co", "David4@m.co", "David0@m.co"}, {"David", "David0@m.co", "David1@m.co", "David3@m.co"}, {"David", "David4@m.co", "David1@m.co", "David3@m.co"}, }, - expected: [][]string{ + want: [][]string{ {"David", "David0@m.co", "David1@m.co", "David3@m.co", "David4@m.co", "David5@m.co"}, }, }, { - input: [][]string{ + in: [][]string{ {"David", "David0@m.co", "David1@m.co"}, {"David", "David3@m.co", "David4@m.co"}, {"David", "David4@m.co", "David5@m.co"}, {"David", "David2@m.co", "David3@m.co"}, {"David", "David1@m.co", "David2@m.co"}, }, - expected: [][]string{ + want: [][]string{ {"David", "David0@m.co", "David1@m.co", "David2@m.co", "David3@m.co", "David4@m.co", "David5@m.co"}, }, }, } - for _, tc := range tests { - output := accountsMerge(tc.input) - sort.Slice(output, func(i, j int) bool { - if output[i][0] == output[i][0] { - return output[i][1] < output[j][1] + for _, tt := range tests { + got := accountsMerge(tt.in) + sort.Slice(got, func(i, j int) bool { + if got[i][0] == got[i][0] { + return got[i][1] < got[j][1] } - return output[i][0] < output[i][0] + return got[i][0] < got[i][0] }) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/add-binary/add_binary_test.go b/problems/add-binary/add_binary_test.go index 4eafe3f8f..d4dcd93f2 100644 --- a/problems/add-binary/add_binary_test.go +++ b/problems/add-binary/add_binary_test.go @@ -2,34 +2,34 @@ package problem67 import "testing" -type caseType struct { - a string - b string - expected string +type testType struct { + a string + b string + want string } func TestAddBinary(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - a: "11", - b: "1", - expected: "100", + a: "11", + b: "1", + want: "100", }, { - a: "1010", - b: "1011", - expected: "10101", + a: "1010", + b: "1011", + want: "10101", }, { - a: "111", - b: "111", - expected: "1110", + a: "111", + b: "111", + want: "1110", }, } - for _, tc := range tests { - output := addBinary(tc.a, tc.b) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.a, tc.b, output, tc.expected) + for _, tt := range tests { + got := addBinary(tt.a, tt.b) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.a, tt.b, got, tt.want) } } } diff --git a/problems/add-digits/add_digits_test.go b/problems/add-digits/add_digits_test.go index 5cfcca721..4272d203f 100644 --- a/problems/add-digits/add_digits_test.go +++ b/problems/add-digits/add_digits_test.go @@ -2,22 +2,22 @@ package problem258 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestAddDigits(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 38, - expected: 2, + in: 38, + want: 2, }, } - for _, tc := range tests { - output := addDigits(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := addDigits(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/add-one-row-to-tree/add_one_row_to_tree_test.go b/problems/add-one-row-to-tree/add_one_row_to_tree_test.go index e3a3c6cdc..71d1f281d 100644 --- a/problems/add-one-row-to-tree/add_one_row_to_tree_test.go +++ b/problems/add-one-row-to-tree/add_one_row_to_tree_test.go @@ -7,46 +7,46 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - v int - d int - expected []int +type testType struct { + in []int + v int + d int + want []int } func TestAddOneRow(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{4, 2, 6, 3, 1, 5}, - v: 1, - d: 2, - expected: []int{4, 1, 1, 2, kit.NULL, kit.NULL, 6, 3, 1, 5}, + in: []int{4, 2, 6, 3, 1, 5}, + v: 1, + d: 2, + want: []int{4, 1, 1, 2, kit.NULL, kit.NULL, 6, 3, 1, 5}, }, { - input: []int{4, 2, kit.NULL, 3, 1}, - v: 1, - d: 3, - expected: []int{4, 2, kit.NULL, 1, 1, 3, kit.NULL, kit.NULL, 1}, + in: []int{4, 2, kit.NULL, 3, 1}, + v: 1, + d: 3, + want: []int{4, 2, kit.NULL, 1, 1, 3, kit.NULL, kit.NULL, 1}, }, { - input: []int{3, 1}, - v: 1, - d: 1, - expected: []int{1, 3, kit.NULL, 1}, + in: []int{3, 1}, + v: 1, + d: 1, + want: []int{1, 3, kit.NULL, 1}, }, { - input: []int{3, kit.NULL, 2}, - v: 1, - d: 3, - expected: []int{3, kit.NULL, 2, 1, 1}, + in: []int{3, kit.NULL, 2}, + v: 1, + d: 3, + want: []int{3, kit.NULL, 2, 1, 1}, }, } - for _, tc := range tests { - root := kit.SliceInt2TreeNode(tc.input) - root = addOneRow(root, tc.v, tc.d) - output := kit.TreeNode2SliceInt(root) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + root := kit.SliceInt2TreeNode(tt.in) + root = addOneRow(root, tt.v, tt.d) + got := kit.TreeNode2SliceInt(root) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/add-strings/add_strings_test.go b/problems/add-strings/add_strings_test.go index cba0a1cc8..66ff5596e 100644 --- a/problems/add-strings/add_strings_test.go +++ b/problems/add-strings/add_strings_test.go @@ -2,39 +2,39 @@ package problem415 import "testing" -type caseType struct { - num1 string - num2 string - expected string +type testType struct { + num1 string + num2 string + want string } func TestAddStrings(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - num1: "0", - num2: "0", - expected: "0", + num1: "0", + num2: "0", + want: "0", }, { - num1: "1", - num2: "2", - expected: "3", + num1: "1", + num2: "2", + want: "3", }, { - num1: "9", - num2: "9", - expected: "18", + num1: "9", + num2: "9", + want: "18", }, { - num1: "100", - num2: "999", - expected: "1099", + num1: "100", + num2: "999", + want: "1099", }, } - for _, tc := range tests { - output := addStrings(tc.num1, tc.num2) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc, output, tc.expected) + for _, tt := range tests { + got := addStrings(tt.num1, tt.num2) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt, got, tt.want) } } } diff --git a/problems/add-to-array-form-of-integer/add_to_array_form_of_integer_test.go b/problems/add-to-array-form-of-integer/add_to_array_form_of_integer_test.go index f7926c21a..bba949e63 100644 --- a/problems/add-to-array-form-of-integer/add_to_array_form_of_integer_test.go +++ b/problems/add-to-array-form-of-integer/add_to_array_form_of_integer_test.go @@ -5,34 +5,34 @@ import ( "testing" ) -type caseType struct { - input []int - k int - expected []int +type testType struct { + in []int + k int + want []int } func TestAddToArrayForm(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 0, 0}, - k: 34, - expected: []int{1, 2, 3, 4}, + in: []int{1, 2, 0, 0}, + k: 34, + want: []int{1, 2, 3, 4}, }, { - input: []int{2, 1, 5}, - k: 806, - expected: []int{1, 0, 2, 1}, + in: []int{2, 1, 5}, + k: 806, + want: []int{1, 0, 2, 1}, }, { - input: []int{9, 9, 9, 9, 9, 9, 9, 9, 9, 9}, - k: 1, - expected: []int{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + in: []int{9, 9, 9, 9, 9, 9, 9, 9, 9, 9}, + k: 1, + want: []int{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, }, } - for _, tc := range tests { - output := addToArrayForm(tc.input, tc.k) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := addToArrayForm(tt.in, tt.k) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/add-two-numbers-ii/add_two_numbers_ii_test.go b/problems/add-two-numbers-ii/add_two_numbers_ii_test.go index 67d9ffe26..f0f49ac1d 100644 --- a/problems/add-two-numbers-ii/add_two_numbers_ii_test.go +++ b/problems/add-two-numbers-ii/add_two_numbers_ii_test.go @@ -7,41 +7,41 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - l1 []int - l2 []int - expected []int +type testType struct { + l1 []int + l2 []int + want []int } func TestAddTwoNumbers(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - l1: []int{7, 2, 4, 3}, - l2: []int{5, 6, 4}, - expected: []int{7, 8, 0, 7}, + l1: []int{7, 2, 4, 3}, + l2: []int{5, 6, 4}, + want: []int{7, 8, 0, 7}, }, { - l1: []int{2, 4, 3}, - l2: []int{5, 6, 4}, - expected: []int{8, 0, 7}, + l1: []int{2, 4, 3}, + l2: []int{5, 6, 4}, + want: []int{8, 0, 7}, }, { - l1: []int{5}, - l2: []int{5}, - expected: []int{1, 0}, + l1: []int{5}, + l2: []int{5}, + want: []int{1, 0}, }, { - l1: []int{5}, - l2: []int{5, 9, 9}, - expected: []int{6, 0, 4}, + l1: []int{5}, + l2: []int{5, 9, 9}, + want: []int{6, 0, 4}, }, } - for _, tc := range tests { - l1 := kit.SliceInt2ListNode(tc.l1) - l2 := kit.SliceInt2ListNode(tc.l2) - output := kit.ListNode2SliceInt(addTwoNumbers(l1, l2)) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.l1, tc.l2, output, tc.expected) + for _, tt := range tests { + l1 := kit.SliceInt2ListNode(tt.l1) + l2 := kit.SliceInt2ListNode(tt.l2) + got := kit.ListNode2SliceInt(addTwoNumbers(l1, l2)) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.l1, tt.l2, got, tt.want) } } } diff --git a/problems/add-two-numbers/add_two_numbers_test.go b/problems/add-two-numbers/add_two_numbers_test.go index cc1be1d20..e60a3c521 100644 --- a/problems/add-two-numbers/add_two_numbers_test.go +++ b/problems/add-two-numbers/add_two_numbers_test.go @@ -7,36 +7,36 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - l1 []int - l2 []int - expected []int +type testType struct { + l1 []int + l2 []int + want []int } func TestAddTwoNumbers(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - l1: []int{2, 4, 3}, - l2: []int{5, 6, 4}, - expected: []int{7, 0, 8}, + l1: []int{2, 4, 3}, + l2: []int{5, 6, 4}, + want: []int{7, 0, 8}, }, { - l1: []int{5}, - l2: []int{5}, - expected: []int{0, 1}, + l1: []int{5}, + l2: []int{5}, + want: []int{0, 1}, }, { - l1: []int{5}, - l2: []int{5, 9, 9}, - expected: []int{0, 0, 0, 1}, + l1: []int{5}, + l2: []int{5, 9, 9}, + want: []int{0, 0, 0, 1}, }, } - for _, tc := range tests { - l1 := kit.SliceInt2ListNode(tc.l1) - l2 := kit.SliceInt2ListNode(tc.l2) - output := kit.ListNode2SliceInt(addTwoNumbers(l1, l2)) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.l1, tc.l2, output, tc.expected) + for _, tt := range tests { + l1 := kit.SliceInt2ListNode(tt.l1) + l2 := kit.SliceInt2ListNode(tt.l2) + got := kit.ListNode2SliceInt(addTwoNumbers(l1, l2)) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.l1, tt.l2, got, tt.want) } } } diff --git a/problems/arithmetic-slices/arithmetic_slices_test.go b/problems/arithmetic-slices/arithmetic_slices_test.go index 4d84df8d0..8859800eb 100644 --- a/problems/arithmetic-slices/arithmetic_slices_test.go +++ b/problems/arithmetic-slices/arithmetic_slices_test.go @@ -2,46 +2,46 @@ package problem413 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestNumberOfArithmeticSlices(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 3, 5, 7, 9}, - expected: 6, + in: []int{1, 3, 5, 7, 9}, + want: 6, }, { - input: []int{7, 7, 7, 7}, - expected: 3, + in: []int{7, 7, 7, 7}, + want: 3, }, { - input: []int{3, -1, -5, -9}, - expected: 3, + in: []int{3, -1, -5, -9}, + want: 3, }, { - input: []int{1, 2, 3, 4}, - expected: 3, + in: []int{1, 2, 3, 4}, + want: 3, }, { - input: []int{1, 2, 3, 4, 6, 8, 10}, - expected: 6, + in: []int{1, 2, 3, 4, 6, 8, 10}, + want: 6, }, { - input: []int{1, 2}, - expected: 0, + in: []int{1, 2}, + want: 0, }, { - input: []int{1, 2, 4, 5, 7}, - expected: 0, + in: []int{1, 2, 4, 5, 7}, + want: 0, }, } - for _, tc := range tests { - output := numberOfArithmeticSlices(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := numberOfArithmeticSlices(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/arranging-coins/arranging_coins_test.go b/problems/arranging-coins/arranging_coins_test.go index c2d51080c..e290120f8 100644 --- a/problems/arranging-coins/arranging_coins_test.go +++ b/problems/arranging-coins/arranging_coins_test.go @@ -2,50 +2,50 @@ package problem441 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestArrangeCoins(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 5, - expected: 2, + in: 5, + want: 2, }, { - input: 8, - expected: 3, + in: 8, + want: 3, }, { - input: 0, - expected: 0, + in: 0, + want: 0, }, { - input: 1, - expected: 1, + in: 1, + want: 1, }, { - input: 2, - expected: 1, + in: 2, + want: 1, }, { - input: 3, - expected: 2, + in: 3, + want: 2, }, { - input: 13, - expected: 4, + in: 13, + want: 4, }, { - input: 130, - expected: 15, + in: 130, + want: 15, }, } - for _, tc := range tests { - output := arrangeCoins(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := arrangeCoins(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/array-nesting/array_nesting_test.go b/problems/array-nesting/array_nesting_test.go index 899d9b67f..d9d3f068c 100644 --- a/problems/array-nesting/array_nesting_test.go +++ b/problems/array-nesting/array_nesting_test.go @@ -4,34 +4,34 @@ import ( "testing" ) -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestArrayNesting(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{5, 4, 0, 3, 1, 6, 2}, - expected: 4, + in: []int{5, 4, 0, 3, 1, 6, 2}, + want: 4, }, { - input: []int{0, 3, 1, 5, 4, 6, 2}, - expected: 5, + in: []int{0, 3, 1, 5, 4, 6, 2}, + want: 5, }, { - input: []int{6, 2, 5, 4, 0, 3, 1}, - expected: 7, + in: []int{6, 2, 5, 4, 0, 3, 1}, + want: 7, }, { - input: []int{3, 1, 5, 4, 0, 6, 2}, - expected: 3, + in: []int{3, 1, 5, 4, 0, 6, 2}, + want: 3, }, } - for _, tc := range tests { - output := arrayNesting(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := arrayNesting(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/array-partition-i/array_partition_i_test.go b/problems/array-partition-i/array_partition_i_test.go index e87160ecb..58d398f4b 100644 --- a/problems/array-partition-i/array_partition_i_test.go +++ b/problems/array-partition-i/array_partition_i_test.go @@ -2,22 +2,22 @@ package problem561 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestArrayPairSum(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 4, 3, 2}, - expected: 4, + in: []int{1, 4, 3, 2}, + want: 4, }, } - for _, tc := range tests { - output := arrayPairSum(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := arrayPairSum(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/assign-cookies/assign_cookies_test.go b/problems/assign-cookies/assign_cookies_test.go index 9a3e41bca..df6fa1b7e 100644 --- a/problems/assign-cookies/assign_cookies_test.go +++ b/problems/assign-cookies/assign_cookies_test.go @@ -2,29 +2,29 @@ package problem455 import "testing" -type caseType struct { - g []int - s []int - expected int +type testType struct { + g []int + s []int + want int } func TestFindContentChildren(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - g: []int{1, 2, 3}, - s: []int{1, 1}, - expected: 1, + g: []int{1, 2, 3}, + s: []int{1, 1}, + want: 1, }, { - g: []int{1, 2}, - s: []int{1, 2, 3}, - expected: 2, + g: []int{1, 2}, + s: []int{1, 2, 3}, + want: 2, }, } - for _, tc := range tests { - output := findContentChildren(tc.g, tc.s) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.g, output, tc.expected) + for _, tt := range tests { + got := findContentChildren(tt.g, tt.s) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.g, got, tt.want) } } } diff --git a/problems/available-captures-for-rook/available_captures_for_rook_test.go b/problems/available-captures-for-rook/available_captures_for_rook_test.go index 4a035e464..39348f3a6 100644 --- a/problems/available-captures-for-rook/available_captures_for_rook_test.go +++ b/problems/available-captures-for-rook/available_captures_for_rook_test.go @@ -2,15 +2,15 @@ package problem999 import "testing" -type caseType struct { - input [][]byte - expected int +type testType struct { + in [][]byte + want int } func TestNumRookCaptures(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]byte{ + in: [][]byte{ {'.', '.', '.', '.', '.', '.', '.', '.'}, {'.', '.', '.', 'p', '.', '.', '.', '.'}, {'.', '.', '.', 'R', '.', '.', '.', 'p'}, @@ -20,10 +20,10 @@ func TestNumRookCaptures(t *testing.T) { {'.', '.', '.', '.', '.', '.', '.', '.'}, {'.', '.', '.', '.', '.', '.', '.', '.'}, }, - expected: 3, + want: 3, }, { - input: [][]byte{ + in: [][]byte{ {'.', '.', '.', '.', '.', '.', '.', '.'}, {'.', 'p', 'p', 'p', 'p', 'p', '.', '.'}, {'.', 'p', 'p', 'B', 'p', 'p', '.', '.'}, @@ -33,10 +33,10 @@ func TestNumRookCaptures(t *testing.T) { {'.', '.', '.', '.', '.', '.', '.', '.'}, {'.', '.', '.', '.', '.', '.', '.', '.'}, }, - expected: 0, + want: 0, }, { - input: [][]byte{ + in: [][]byte{ {'.', '.', '.', '.', '.', '.', '.', '.'}, {'.', '.', '.', 'p', '.', '.', '.', '.'}, {'.', '.', '.', 'p', '.', '.', '.', '.'}, @@ -46,10 +46,10 @@ func TestNumRookCaptures(t *testing.T) { {'.', '.', '.', 'p', '.', '.', '.', '.'}, {'.', '.', '.', '.', '.', '.', '.', '.'}, }, - expected: 3, + want: 3, }, { - input: [][]byte{ + in: [][]byte{ {'.', '.', '.', '.', '.', '.', '.', '.'}, {'.', '.', '.', 'p', '.', '.', '.', '.'}, {'.', '.', '.', 'p', '.', '.', '.', '.'}, @@ -59,13 +59,13 @@ func TestNumRookCaptures(t *testing.T) { {'.', '.', 'p', '.', 'p', '.', '.', '.'}, {'.', '.', '.', '.', '.', '.', '.', '.'}, }, - expected: 2, + want: 2, }, } - for _, tc := range tests { - output := numRookCaptures(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := numRookCaptures(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/base-7/base_7_test.go b/problems/base-7/base_7_test.go index f38bbfb0a..81e455a9a 100644 --- a/problems/base-7/base_7_test.go +++ b/problems/base-7/base_7_test.go @@ -2,34 +2,34 @@ package problem504 import "testing" -type caseType struct { - input int - expected string +type testType struct { + in int + want string } func TestConvertToBase7(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 100, - expected: "202", + in: 100, + want: "202", }, { - input: -7, - expected: "-10", + in: -7, + want: "-10", }, { - input: -1, - expected: "-1", + in: -1, + want: "-1", }, { - input: 0, - expected: "0", + in: 0, + want: "0", }, } - for _, tc := range tests { - output := convertToBase7(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := convertToBase7(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/best-time-to-buy-and-sell-stock-ii/best_time_to_buy_and_sell_stock_ii_test.go b/problems/best-time-to-buy-and-sell-stock-ii/best_time_to_buy_and_sell_stock_ii_test.go index 28f746ff0..ce9cfbb4e 100644 --- a/problems/best-time-to-buy-and-sell-stock-ii/best_time_to_buy_and_sell_stock_ii_test.go +++ b/problems/best-time-to-buy-and-sell-stock-ii/best_time_to_buy_and_sell_stock_ii_test.go @@ -2,31 +2,31 @@ package problem122 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestMaxProfit(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{7, 1, 5, 3, 6, 4}, - expected: 7, + in: []int{7, 1, 5, 3, 6, 4}, + want: 7, }, { - input: []int{1, 2, 3, 4, 5}, - expected: 4, + in: []int{1, 2, 3, 4, 5}, + want: 4, }, { - input: []int{7, 6, 4, 3, 1}, - expected: 0, + in: []int{7, 6, 4, 3, 1}, + want: 0, }, } - for _, tc := range tests { - output := maxProfit(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := maxProfit(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/best-time-to-buy-and-sell-stock/best_time_to_buy_and_sell_stock_test.go b/problems/best-time-to-buy-and-sell-stock/best_time_to_buy_and_sell_stock_test.go index 8701108e0..6f7bb2251 100644 --- a/problems/best-time-to-buy-and-sell-stock/best_time_to_buy_and_sell_stock_test.go +++ b/problems/best-time-to-buy-and-sell-stock/best_time_to_buy_and_sell_stock_test.go @@ -2,34 +2,34 @@ package problem121 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestMaxProfit(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{7, 1, 5, 3, 6, 4}, - expected: 5, + in: []int{7, 1, 5, 3, 6, 4}, + want: 5, }, { - input: []int{7, 6, 4, 3, 1}, - expected: 0, + in: []int{7, 6, 4, 3, 1}, + want: 0, }, { - input: []int{1, 1, 1, 1, 1}, - expected: 0, + in: []int{1, 1, 1, 1, 1}, + want: 0, }, { - input: []int{}, - expected: 0, + in: []int{}, + want: 0, }, } - for _, tc := range tests { - output := maxProfit(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := maxProfit(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/binary-prefix-divisible-by-5/binary_prefix_divisible_by_5_test.go b/problems/binary-prefix-divisible-by-5/binary_prefix_divisible_by_5_test.go index 8b3da57dd..113d6d1c8 100644 --- a/problems/binary-prefix-divisible-by-5/binary_prefix_divisible_by_5_test.go +++ b/problems/binary-prefix-divisible-by-5/binary_prefix_divisible_by_5_test.go @@ -5,38 +5,38 @@ import ( "testing" ) -type caseType struct { - input []int - expected []bool +type testType struct { + in []int + want []bool } func TestPrefixesDivBy5(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{0, 1, 1}, - expected: []bool{true, false, false}, + in: []int{0, 1, 1}, + want: []bool{true, false, false}, }, { - input: []int{1, 1, 1}, - expected: []bool{false, false, false}, + in: []int{1, 1, 1}, + want: []bool{false, false, false}, }, { - input: []int{0, 1, 1, 1, 1, 1}, - expected: []bool{true, false, false, false, true, false}, + in: []int{0, 1, 1, 1, 1, 1}, + want: []bool{true, false, false, false, true, false}, }, { - input: []int{1, 1, 1, 0, 1}, - expected: []bool{false, false, false, false, false}, + in: []int{1, 1, 1, 0, 1}, + want: []bool{false, false, false, false, false}, }, { - input: []int{1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0}, - expected: []bool{false, false, true, false, false, false, false, false, false, false, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, true, false, false, true, true, true, true, true, true, true, false, false, true, false, false, false, false, true, true}, + in: []int{1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0}, + want: []bool{false, false, true, false, false, false, false, false, false, false, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, true, false, false, true, true, true, true, true, true, true, false, false, true, false, false, false, false, true, true}, }, } - for _, tc := range tests { - output := prefixesDivBy5(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := prefixesDivBy5(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/buddy-strings/buddy_strings_test.go b/problems/buddy-strings/buddy_strings_test.go index c8145998a..28ab9045e 100644 --- a/problems/buddy-strings/buddy_strings_test.go +++ b/problems/buddy-strings/buddy_strings_test.go @@ -2,54 +2,54 @@ package problem859 import "testing" -type caseType struct { - a string - b string - expected bool +type testType struct { + a string + b string + want bool } func TestBuddyStrings(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - a: "ab", - b: "ba", - expected: true, + a: "ab", + b: "ba", + want: true, }, { - a: "aa", - b: "aa", - expected: true, + a: "aa", + b: "aa", + want: true, }, { - a: "ab", - b: "ab", - expected: false, + a: "ab", + b: "ab", + want: false, }, { - a: "aaaaaaabc", - b: "aaaaaaacb", - expected: true, + a: "aaaaaaabc", + b: "aaaaaaacb", + want: true, }, { - a: "", - b: "aa", - expected: false, + a: "", + b: "aa", + want: false, }, { - a: "hello", - b: "h0lle", - expected: false, + a: "hello", + b: "h0lle", + want: false, }, { - a: "hello", - b: "hanna", - expected: false, + a: "hello", + b: "hanna", + want: false, }, } - for _, tc := range tests { - output := buddyStrings(tc.a, tc.b) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.a, tc.b, output, tc.expected) + for _, tt := range tests { + got := buddyStrings(tt.a, tt.b) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.a, tt.b, got, tt.want) } } } diff --git a/problems/bulb-switcher/bulb_switcher_test.go b/problems/bulb-switcher/bulb_switcher_test.go index 014dae211..dadcb2c53 100644 --- a/problems/bulb-switcher/bulb_switcher_test.go +++ b/problems/bulb-switcher/bulb_switcher_test.go @@ -2,30 +2,30 @@ package problem319 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestBulbSwitch(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 3, - expected: 1, + in: 3, + want: 1, }, { - input: 4, - expected: 2, + in: 4, + want: 2, }, { - input: 5, - expected: 2, + in: 5, + want: 2, }, } - for _, tc := range tests { - output := bulbSwitch(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := bulbSwitch(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/camelcase-matching/camelcase_matching_test.go b/problems/camelcase-matching/camelcase_matching_test.go index 1825941d8..550fd2226 100644 --- a/problems/camelcase-matching/camelcase_matching_test.go +++ b/problems/camelcase-matching/camelcase_matching_test.go @@ -5,44 +5,44 @@ import ( "testing" ) -type caseType struct { - queries []string - pattern string - expected []bool +type testType struct { + queries []string + pattern string + want []bool } func TestCamelMatch(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - queries: []string{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, - pattern: "FB", - expected: []bool{true, false, true, true, false}, + queries: []string{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, + pattern: "FB", + want: []bool{true, false, true, true, false}, }, { - queries: []string{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, - pattern: "FoBa", - expected: []bool{true, false, true, false, false}, + queries: []string{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, + pattern: "FoBa", + want: []bool{true, false, true, false, false}, }, { - queries: []string{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, - pattern: "FoBaT", - expected: []bool{false, true, false, false, false}, + queries: []string{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"}, + pattern: "FoBaT", + want: []bool{false, true, false, false, false}, }, { - queries: []string{"CompetitiveProgramming", "CounterPick", "ControlPanel"}, - pattern: "CooP", - expected: []bool{false, false, true}, + queries: []string{"CompetitiveProgramming", "CounterPick", "ControlPanel"}, + pattern: "CooP", + want: []bool{false, false, true}, }, { - queries: []string{"aksvbjLiknuTzqon", "ksvjLimflkpnTzqn", "mmkasvjLiknTxzqn", "ksvjLiurknTzzqbn", "ksvsjLctikgnTzqn", "knzsvzjLiknTszqn"}, - pattern: "ksvjLiknTzqn", - expected: []bool{true, true, true, true, true, true}, + queries: []string{"aksvbjLiknuTzqon", "ksvjLimflkpnTzqn", "mmkasvjLiknTxzqn", "ksvjLiurknTzzqbn", "ksvsjLctikgnTzqn", "knzsvzjLiknTszqn"}, + pattern: "ksvjLiknTzqn", + want: []bool{true, true, true, true, true, true}, }, } - for _, tc := range tests { - output := camelMatch(tc.queries, tc.pattern) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.pattern, output, tc.expected) + for _, tt := range tests { + got := camelMatch(tt.queries, tt.pattern) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.pattern, got, tt.want) } } } diff --git a/problems/can-place-flowers/can_place_flowers_test.go b/problems/can-place-flowers/can_place_flowers_test.go index 14647e1b2..f3a5097bc 100644 --- a/problems/can-place-flowers/can_place_flowers_test.go +++ b/problems/can-place-flowers/can_place_flowers_test.go @@ -2,69 +2,69 @@ package problem605 import "testing" -type caseType struct { +type testType struct { flowerbed []int n int - expected bool + want bool } func TestCanPlaceFlowers(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { flowerbed: []int{0, 1, 0, 0, 0, 0, 1, 0}, n: 2, - expected: false, + want: false, }, { flowerbed: []int{1, 0, 0, 0, 1}, n: 1, - expected: true, + want: true, }, { flowerbed: []int{1, 0, 0, 0, 1}, n: 2, - expected: false, + want: false, }, { flowerbed: []int{0, 0, 1, 0}, n: 1, - expected: true, + want: true, }, { flowerbed: []int{0, 1, 0, 0}, n: 1, - expected: true, + want: true, }, { flowerbed: []int{0, 1, 0, 0, 1, 0}, n: 1, - expected: false, + want: false, }, { flowerbed: []int{0, 0, 0, 0, 0}, n: 3, - expected: true, + want: true, }, { flowerbed: []int{0, 0}, n: 2, - expected: false, + want: false, }, { flowerbed: []int{0}, n: 1, - expected: true, + want: true, }, { flowerbed: []int{0, 1}, n: 1, - expected: false, + want: false, }, } - for _, tc := range tests { - output := canPlaceFlowers(tc.flowerbed, tc.n) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.flowerbed, tc.n, output, tc.expected) + for _, tt := range tests { + got := canPlaceFlowers(tt.flowerbed, tt.n) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.flowerbed, tt.n, got, tt.want) } } } diff --git a/problems/climbing-stairs/climbing_stairs_test.go b/problems/climbing-stairs/climbing_stairs_test.go index 5439f6bc0..9f9aba81b 100644 --- a/problems/climbing-stairs/climbing_stairs_test.go +++ b/problems/climbing-stairs/climbing_stairs_test.go @@ -2,30 +2,30 @@ package problem70 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestClimbStairs(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 1, - expected: 1, + in: 1, + want: 1, }, { - input: 2, - expected: 2, + in: 2, + want: 2, }, { - input: 3, - expected: 3, + in: 3, + want: 3, }, } - for _, tc := range tests { - output := climbStairs(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := climbStairs(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/compare-version-numbers/compare_version_numbers_test.go b/problems/compare-version-numbers/compare_version_numbers_test.go index a8489f2e8..730b8e16b 100644 --- a/problems/compare-version-numbers/compare_version_numbers_test.go +++ b/problems/compare-version-numbers/compare_version_numbers_test.go @@ -2,75 +2,75 @@ package problem165 import "testing" -type caseType struct { - v1 string - v2 string - expected int +type testType struct { + v1 string + v2 string + want int } func TestCompareVersion(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - v1: "1.0.01", - v2: "1.00.1", - expected: 0, + v1: "1.0.01", + v2: "1.00.1", + want: 0, }, { - v1: "1.0.0", - v2: "1", - expected: 0, + v1: "1.0.0", + v2: "1", + want: 0, }, { - v1: "1.01", - v2: "1.001", - expected: 0, + v1: "1.01", + v2: "1.001", + want: 0, }, { - v1: "1.0", - v2: "1.0.0", - expected: 0, + v1: "1.0", + v2: "1.0.0", + want: 0, }, { - v1: "0.1", - v2: "1.1", - expected: -1, + v1: "0.1", + v2: "1.1", + want: -1, }, { - v1: "7.5.2.4", - v2: "7.5.3", - expected: -1, + v1: "7.5.2.4", + v2: "7.5.3", + want: -1, }, { - v1: "7.00", - v2: "7.001", - expected: -1, + v1: "7.00", + v2: "7.001", + want: -1, }, { - v1: "1.1", - v2: "1.10", - expected: -1, + v1: "1.1", + v2: "1.10", + want: -1, }, { - v1: "1.0.1", - v2: "1", - expected: 1, + v1: "1.0.1", + v2: "1", + want: 1, }, { - v1: "1.10", - v2: "1.2", - expected: 1, + v1: "1.10", + v2: "1.2", + want: 1, }, { - v1: "1.10.05", - v2: "1.9.10", - expected: 1, + v1: "1.10.05", + v2: "1.9.10", + want: 1, }, } - for _, tc := range tests { - output := compareVersion(tc.v1, tc.v2) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.v1, tc.v2, output, tc.expected) + for _, tt := range tests { + got := compareVersion(tt.v1, tt.v2) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.v1, tt.v2, got, tt.want) } } } diff --git a/problems/complement-of-base-10-integer/complement_of_base_10_integer_test.go b/problems/complement-of-base-10-integer/complement_of_base_10_integer_test.go index 6163b55ab..02f48e6ce 100644 --- a/problems/complement-of-base-10-integer/complement_of_base_10_integer_test.go +++ b/problems/complement-of-base-10-integer/complement_of_base_10_integer_test.go @@ -2,34 +2,34 @@ package problem1009 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestBitwiseComplement(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 5, - expected: 2, + in: 5, + want: 2, }, { - input: 7, - expected: 0, + in: 7, + want: 0, }, { - input: 10, - expected: 5, + in: 10, + want: 5, }, { - input: 0, - expected: 1, + in: 0, + want: 1, }, } - for _, tc := range tests { - output := bitwiseComplement(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := bitwiseComplement(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/construct-string-from-binary-tree/construct_string_from_binary_tree_test.go b/problems/construct-string-from-binary-tree/construct_string_from_binary_tree_test.go index 2412e5372..1cea179af 100644 --- a/problems/construct-string-from-binary-tree/construct_string_from_binary_tree_test.go +++ b/problems/construct-string-from-binary-tree/construct_string_from_binary_tree_test.go @@ -6,26 +6,26 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - expected string +type testType struct { + in []int + want string } func TestTree2str(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 3, 4}, - expected: "1(2(4))(3)", + in: []int{1, 2, 3, 4}, + want: "1(2(4))(3)", }, { - input: []int{1, 2, 3, kit.NULL, 4}, - expected: "1(2()(4))(3)", + in: []int{1, 2, 3, kit.NULL, 4}, + want: "1(2()(4))(3)", }, } - for _, tc := range tests { - output := tree2str(kit.SliceInt2TreeNode(tc.input)) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := tree2str(kit.SliceInt2TreeNode(tt.in)) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/container-with-most-water/container_with_most_water_test.go b/problems/container-with-most-water/container_with_most_water_test.go index 1fcf83aaf..643acc4cf 100644 --- a/problems/container-with-most-water/container_with_most_water_test.go +++ b/problems/container-with-most-water/container_with_most_water_test.go @@ -2,26 +2,26 @@ package problem11 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestMaxArea(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 8, 6, 2, 5, 4, 8, 3, 7}, - expected: 49, + in: []int{1, 8, 6, 2, 5, 4, 8, 3, 7}, + want: 49, }, { - input: []int{1, 8, 6, 30, 20, 6, 9, 10, 1}, - expected: 48, + in: []int{1, 8, 6, 30, 20, 6, 9, 10, 1}, + want: 48, }, } - for _, tc := range tests { - output := maxArea(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := maxArea(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/contains-duplicate-ii/contains_duplicate_ii_test.go b/problems/contains-duplicate-ii/contains_duplicate_ii_test.go index 9714dbed7..71cde41cd 100644 --- a/problems/contains-duplicate-ii/contains_duplicate_ii_test.go +++ b/problems/contains-duplicate-ii/contains_duplicate_ii_test.go @@ -2,34 +2,34 @@ package problem219 import "testing" -type caseType struct { - nums []int - k int - expected bool +type testType struct { + nums []int + k int + want bool } func TestContainsNearbyDuplicate(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - nums: []int{1, 2, 3, 1}, - k: 3, - expected: true, + nums: []int{1, 2, 3, 1}, + k: 3, + want: true, }, { - nums: []int{1, 0, 1, 1}, - k: 1, - expected: true, + nums: []int{1, 0, 1, 1}, + k: 1, + want: true, }, { - nums: []int{1, 2, 3, 1, 2, 3}, - k: 2, - expected: false, + nums: []int{1, 2, 3, 1, 2, 3}, + k: 2, + want: false, }, } - for _, tc := range tests { - output := containsNearbyDuplicate(tc.nums, tc.k) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.nums, tc.k, output, tc.expected) + for _, tt := range tests { + got := containsNearbyDuplicate(tt.nums, tt.k) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.nums, tt.k, got, tt.want) } } } diff --git a/problems/convert-sorted-array-to-binary-search-tree/convert_sorted_array_to_binary_search_tree_test.go b/problems/convert-sorted-array-to-binary-search-tree/convert_sorted_array_to_binary_search_tree_test.go index 6816a286d..6f1116063 100644 --- a/problems/convert-sorted-array-to-binary-search-tree/convert_sorted_array_to_binary_search_tree_test.go +++ b/problems/convert-sorted-array-to-binary-search-tree/convert_sorted_array_to_binary_search_tree_test.go @@ -7,22 +7,22 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - expected []int +type testType struct { + in []int + want []int } func TestSortedArrayToBST(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{-10, -3, 0, 5, 9}, - expected: []int{0, -3, 9, -10, kit.NULL, 5}, + in: []int{-10, -3, 0, 5, 9}, + want: []int{0, -3, 9, -10, kit.NULL, 5}, }, } - for _, tc := range tests { - output := kit.TreeNode2SliceInt(sortedArrayToBST(tc.input)) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := kit.TreeNode2SliceInt(sortedArrayToBST(tt.in)) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/count-and-say/count_and_say_test.go b/problems/count-and-say/count_and_say_test.go index 4c807591c..95704ed75 100644 --- a/problems/count-and-say/count_and_say_test.go +++ b/problems/count-and-say/count_and_say_test.go @@ -11,10 +11,10 @@ func TestCountAndSay(t *testing.T) { 9: "31131211131221", } - for input, expected := range tests { - output := countAndSay(input) - if output != expected { - t.Fatalf("input: %v, output: %v, expected: %v", input, output, expected) + for in, want := range tests { + got := countAndSay(in) + if got != want { + t.Fatalf("in: %v, got: %v, want: %v", in, got, want) } } } diff --git a/problems/count-binary-substrings/count_binary_substrings_test.go b/problems/count-binary-substrings/count_binary_substrings_test.go index cf68582ab..606c5a873 100644 --- a/problems/count-binary-substrings/count_binary_substrings_test.go +++ b/problems/count-binary-substrings/count_binary_substrings_test.go @@ -2,26 +2,26 @@ package problem696 import "testing" -type caseType struct { - input string - expected int +type testType struct { + in string + want int } func TestCountBinarySubstrings(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "00110011", - expected: 6, + in: "00110011", + want: 6, }, { - input: "10101", - expected: 4, + in: "10101", + want: 4, }, } - for _, tc := range tests { - output := countBinarySubstrings(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := countBinarySubstrings(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/count-primes/count_primes_test.go b/problems/count-primes/count_primes_test.go index b34b612d6..f31d9bf31 100644 --- a/problems/count-primes/count_primes_test.go +++ b/problems/count-primes/count_primes_test.go @@ -16,10 +16,10 @@ func TestCountPrimes(t *testing.T) { 300: 62, } - for input, expected := range tests { - output := countPrimes(input) - if output != expected { - t.Fatalf("input: %v, output: %v, expected: %v", input, output, expected) + for in, want := range tests { + got := countPrimes(in) + if got != want { + t.Fatalf("in: %v, got: %v, want: %v", in, got, want) } } } diff --git a/problems/cousins-in-binary-tree/cousins_in_binary_tree_test.go b/problems/cousins-in-binary-tree/cousins_in_binary_tree_test.go index b22d9e0be..3d28c3ff7 100644 --- a/problems/cousins-in-binary-tree/cousins_in_binary_tree_test.go +++ b/problems/cousins-in-binary-tree/cousins_in_binary_tree_test.go @@ -6,50 +6,50 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - x int - y int - expected bool +type testType struct { + in []int + x int + y int + want bool } func TestIsCousins(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 3, 4}, - x: 4, - y: 3, - expected: false, + in: []int{1, 2, 3, 4}, + x: 4, + y: 3, + want: false, }, { - input: []int{1, 2, 3, kit.NULL, 4, kit.NULL, 5}, - x: 5, - y: 4, - expected: true, + in: []int{1, 2, 3, kit.NULL, 4, kit.NULL, 5}, + x: 5, + y: 4, + want: true, }, { - input: []int{1, 2, 3, kit.NULL, 4}, - x: 2, - y: 3, - expected: false, + in: []int{1, 2, 3, kit.NULL, 4}, + x: 2, + y: 3, + want: false, }, { - input: []int{1, 2, 3, kit.NULL, 4, 5}, - x: 4, - y: 5, - expected: true, + in: []int{1, 2, 3, kit.NULL, 4, 5}, + x: 4, + y: 5, + want: true, }, { - input: []int{1, 2, 3, kit.NULL, 4, 5}, - x: 5, - y: 4, - expected: true, + in: []int{1, 2, 3, kit.NULL, 4, 5}, + x: 5, + y: 4, + want: true, }, } - for _, tc := range tests { - output := isCousins(kit.SliceInt2TreeNode(tc.input), tc.x, tc.y) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isCousins(kit.SliceInt2TreeNode(tt.in), tt.x, tt.y) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/day-of-the-week/day_of_the_week_test.go b/problems/day-of-the-week/day_of_the_week_test.go index 4be992806..1533f28e0 100644 --- a/problems/day-of-the-week/day_of_the_week_test.go +++ b/problems/day-of-the-week/day_of_the_week_test.go @@ -2,50 +2,50 @@ package problem1185 import "testing" -type caseType struct { - day int - month int - year int - expected string +type testType struct { + day int + month int + year int + want string } func TestDayOfTheWeek(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - day: 31, - month: 8, - year: 2019, - expected: "Saturday", + day: 31, + month: 8, + year: 2019, + want: "Saturday", }, { - day: 15, - month: 8, - year: 1993, - expected: "Sunday", + day: 15, + month: 8, + year: 1993, + want: "Sunday", }, { - day: 1, - month: 1, - year: 1970, - expected: "Thursday", + day: 1, + month: 1, + year: 1970, + want: "Thursday", }, { - day: 25, - month: 3, - year: 1993, - expected: "Thursday", + day: 25, + month: 3, + year: 1993, + want: "Thursday", }, { - day: 30, - month: 6, - year: 2000, - expected: "Friday", + day: 30, + month: 6, + year: 2000, + want: "Friday", }, } - for _, tc := range tests { - output := dayOfTheWeek(tc.day, tc.month, tc.year) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc, output, tc.expected) + for _, tt := range tests { + got := dayOfTheWeek(tt.day, tt.month, tt.year) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt, got, tt.want) } } } diff --git a/problems/day-of-the-year/day_of_the_year_test.go b/problems/day-of-the-year/day_of_the_year_test.go index 5166db4e1..607af2434 100644 --- a/problems/day-of-the-year/day_of_the_year_test.go +++ b/problems/day-of-the-year/day_of_the_year_test.go @@ -2,42 +2,42 @@ package problem1154 import "testing" -type caseType struct { - input string - expected int +type testType struct { + in string + want int } func TestDayOfYear(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "2019-01-09", - expected: 9, + in: "2019-01-09", + want: 9, }, { - input: "2019-02-10", - expected: 41, + in: "2019-02-10", + want: 41, }, { - input: "2003-03-01", - expected: 60, + in: "2003-03-01", + want: 60, }, { - input: "2004-03-01", - expected: 61, + in: "2004-03-01", + want: 61, }, { - input: "2000-08-01", - expected: 214, + in: "2000-08-01", + want: 214, }, { - input: "1993-12-11", - expected: 345, + in: "1993-12-11", + want: 345, }, } - for _, tc := range tests { - output := dayOfYear(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := dayOfYear(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/defanging-an-ip-address/defanging_an_ip_address_test.go b/problems/defanging-an-ip-address/defanging_an_ip_address_test.go index 42d9de312..b3401e99f 100644 --- a/problems/defanging-an-ip-address/defanging_an_ip_address_test.go +++ b/problems/defanging-an-ip-address/defanging_an_ip_address_test.go @@ -2,26 +2,26 @@ package problem1108 import "testing" -type caseType struct { - input string - expected string +type testType struct { + in string + want string } func TestDefangIPaddr(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "1.1.1.1", - expected: "1[.]1[.]1[.]1", + in: "1.1.1.1", + want: "1[.]1[.]1[.]1", }, { - input: "255.100.50.0", - expected: "255[.]100[.]50[.]0", + in: "255.100.50.0", + want: "255[.]100[.]50[.]0", }, } - for _, tc := range tests { - output := defangIPaddr(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := defangIPaddr(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/degree-of-an-array/degree_of_an_array_test.go b/problems/degree-of-an-array/degree_of_an_array_test.go index f2d78bf1c..e9a9e7d4e 100644 --- a/problems/degree-of-an-array/degree_of_an_array_test.go +++ b/problems/degree-of-an-array/degree_of_an_array_test.go @@ -2,38 +2,38 @@ package problem697 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestFindShortestSubArray(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 2, 3, 1}, - expected: 2, + in: []int{1, 2, 2, 3, 1}, + want: 2, }, { - input: []int{1, 2, 2, 3, 1, 4, 2}, - expected: 6, + in: []int{1, 2, 2, 3, 1, 4, 2}, + want: 6, }, { - input: []int{1}, - expected: 1, + in: []int{1}, + want: 1, }, { - input: []int{2, 1, 1, 2, 1, 3, 3, 3, 1, 3, 1, 3, 2}, - expected: 7, + in: []int{2, 1, 1, 2, 1, 3, 3, 3, 1, 3, 1, 3, 2}, + want: 7, }, { - input: []int{1, 2, 2, 3, 1}, - expected: 2, + in: []int{1, 2, 2, 3, 1}, + want: 2, }, } - for _, tc := range tests { - output := findShortestSubArray(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := findShortestSubArray(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/delete-columns-to-make-sorted/delete_columns_to_make_sorted_test.go b/problems/delete-columns-to-make-sorted/delete_columns_to_make_sorted_test.go index f35f03936..a7c21ed02 100644 --- a/problems/delete-columns-to-make-sorted/delete_columns_to_make_sorted_test.go +++ b/problems/delete-columns-to-make-sorted/delete_columns_to_make_sorted_test.go @@ -2,30 +2,30 @@ package problem944 import "testing" -type caseType struct { - input []string - expected int +type testType struct { + in []string + want int } func TestMinDeletionSize(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []string{"cba", "daf", "ghi"}, - expected: 1, + in: []string{"cba", "daf", "ghi"}, + want: 1, }, { - input: []string{"a", "b"}, - expected: 0, + in: []string{"a", "b"}, + want: 0, }, { - input: []string{"zyx", "wvu", "tsr"}, - expected: 3, + in: []string{"zyx", "wvu", "tsr"}, + want: 3, }, } - for _, tc := range tests { - output := minDeletionSize(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := minDeletionSize(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/delete-node-in-a-linked-list/delete_node_in_a_linked_list_test.go b/problems/delete-node-in-a-linked-list/delete_node_in_a_linked_list_test.go index 204271be9..66e611bf3 100644 --- a/problems/delete-node-in-a-linked-list/delete_node_in_a_linked_list_test.go +++ b/problems/delete-node-in-a-linked-list/delete_node_in_a_linked_list_test.go @@ -7,50 +7,50 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - node int - expected []int +type testType struct { + in []int + node int + want []int } func TestDeleteNode(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{4, 5, 1, 9}, - node: 5, - expected: []int{4, 1, 9}, + in: []int{4, 5, 1, 9}, + node: 5, + want: []int{4, 1, 9}, }, { - input: []int{4, 5, 1, 9}, - node: 1, - expected: []int{4, 5, 9}, + in: []int{4, 5, 1, 9}, + node: 1, + want: []int{4, 5, 9}, }, { - input: []int{4, 5, 1, 9}, - node: 4, - expected: []int{5, 1, 9}, + in: []int{4, 5, 1, 9}, + node: 4, + want: []int{5, 1, 9}, }, { - input: []int{4, 5, 1, 9}, - node: 9, - expected: []int{4, 5, 1, 9}, + in: []int{4, 5, 1, 9}, + node: 9, + want: []int{4, 5, 1, 9}, }, { - input: []int{4, 5, 1, 9}, - node: 2, - expected: []int{4, 5, 1, 9}, + in: []int{4, 5, 1, 9}, + node: 2, + want: []int{4, 5, 1, 9}, }, } - for _, tc := range tests { - head := kit.SliceInt2ListNode(tc.input) + for _, tt := range tests { + head := kit.SliceInt2ListNode(tt.in) node := head - for node != nil && node.Val != tc.node { + for node != nil && node.Val != tt.node { node = node.Next } deleteNode(node) - output := kit.ListNode2SliceInt(head) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + got := kit.ListNode2SliceInt(head) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/design-hashmap/design_hashmap_test.go b/problems/design-hashmap/design_hashmap_test.go index 78316b948..5f4ed59d0 100644 --- a/problems/design-hashmap/design_hashmap_test.go +++ b/problems/design-hashmap/design_hashmap_test.go @@ -6,13 +6,13 @@ func TestDesignHashmap(t *testing.T) { obj := Constructor() obj.Put(1, 1) obj.Put(2, 2) - output := obj.Get(1) == 1 - output = obj.Get(3) == -1 && output + got := obj.Get(1) == 1 + got = obj.Get(3) == -1 && got obj.Put(2, 1) - output = obj.Get(2) == 1 && output + got = obj.Get(2) == 1 && got obj.Remove(2) - output = obj.Get(2) == -1 && output - if !output { - t.Fatalf("output: %v, expected: %v", output, true) + got = obj.Get(2) == -1 && got + if !got { + t.Fatalf("got: %v, want: %v", got, true) } } diff --git a/problems/design-hashset/design_hashset_test.go b/problems/design-hashset/design_hashset_test.go index f54a649d6..8bb60f2ee 100644 --- a/problems/design-hashset/design_hashset_test.go +++ b/problems/design-hashset/design_hashset_test.go @@ -6,13 +6,13 @@ func TestDesignHashset(t *testing.T) { obj := Constructor() obj.Add(1) obj.Add(2) - output := obj.Contains(1) - output = !obj.Contains(3) && output + got := obj.Contains(1) + got = !obj.Contains(3) && got obj.Add(2) - output = obj.Contains(2) && output + got = obj.Contains(2) && got obj.Remove(2) - output = !obj.Contains(2) && output - if !output { - t.Fatalf("output: %v, expected: %v", output, true) + got = !obj.Contains(2) && got + if !got { + t.Fatalf("got: %v, want: %v", got, true) } } diff --git a/problems/design-linked-list/design_linked_list_test.go b/problems/design-linked-list/design_linked_list_test.go index f8edbd694..bfcad69fb 100644 --- a/problems/design-linked-list/design_linked_list_test.go +++ b/problems/design-linked-list/design_linked_list_test.go @@ -6,13 +6,13 @@ func TestConstructor(t *testing.T) { obj := Constructor() obj.AddAtHead(1) obj.AddAtTail(3) - obj.AddAtIndex(1, 2) // linked list becomes 1->2->3 - output := obj.Get(1) == 2 // returns 2 - obj.DeleteAtIndex(1) // now the linked list is 1->3 - output = obj.Get(1) == 3 && output + obj.AddAtIndex(1, 2) // linked list becomes 1->2->3 + got := obj.Get(1) == 2 // returns 2 + obj.DeleteAtIndex(1) // now the linked list is 1->3 + got = obj.Get(1) == 3 && got obj.AddAtIndex(2, 2) // linked list becomes 1->3->2 - output = obj.Get(5) == -1 && output - if !output { - t.Fatalf("output: %v, expected: %v", output, true) + got = obj.Get(5) == -1 && got + if !got { + t.Fatalf("got: %v, want: %v", got, true) } } diff --git a/problems/detect-capital/detect_capital_test.go b/problems/detect-capital/detect_capital_test.go index 76e5627fa..4f6a3435d 100644 --- a/problems/detect-capital/detect_capital_test.go +++ b/problems/detect-capital/detect_capital_test.go @@ -2,34 +2,34 @@ package problem520 import "testing" -type caseType struct { - input string - expected bool +type testType struct { + in string + want bool } func TestDetectCapitalUse(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "USA", - expected: true, + in: "USA", + want: true, }, { - input: "leetcode", - expected: true, + in: "leetcode", + want: true, }, { - input: "Google", - expected: true, + in: "Google", + want: true, }, { - input: "FlaG", - expected: false, + in: "FlaG", + want: false, }, } - for _, tc := range tests { - output := detectCapitalUse(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := detectCapitalUse(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/di-string-match/di_string_match_test.go b/problems/di-string-match/di_string_match_test.go index 07fff5113..ef44d3764 100644 --- a/problems/di-string-match/di_string_match_test.go +++ b/problems/di-string-match/di_string_match_test.go @@ -5,30 +5,30 @@ import ( "testing" ) -type caseType struct { - input string - expected []int +type testType struct { + in string + want []int } func TestDiStringMatch(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "IDID", - expected: []int{0, 4, 1, 3, 2}, + in: "IDID", + want: []int{0, 4, 1, 3, 2}, }, { - input: "III", - expected: []int{0, 1, 2, 3}, + in: "III", + want: []int{0, 1, 2, 3}, }, { - input: "DDI", - expected: []int{3, 2, 0, 1}, + in: "DDI", + want: []int{3, 2, 0, 1}, }, } - for _, tc := range tests { - output := diStringMatch(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := diStringMatch(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/divisor-game/divisor_game_test.go b/problems/divisor-game/divisor_game_test.go index e5a2341b5..af1ba4b2d 100644 --- a/problems/divisor-game/divisor_game_test.go +++ b/problems/divisor-game/divisor_game_test.go @@ -2,26 +2,26 @@ package problem1025 import "testing" -type caseType struct { - input int - expected bool +type testType struct { + in int + want bool } func TestDivisorGame(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 2, - expected: true, + in: 2, + want: true, }, { - input: 3, - expected: false, + in: 3, + want: false, }, } - for _, tc := range tests { - output := divisorGame(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := divisorGame(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/excel-sheet-column-number/excel_sheet_column_number_test.go b/problems/excel-sheet-column-number/excel_sheet_column_number_test.go index ac2b7faaa..52dcaf158 100644 --- a/problems/excel-sheet-column-number/excel_sheet_column_number_test.go +++ b/problems/excel-sheet-column-number/excel_sheet_column_number_test.go @@ -2,49 +2,49 @@ package problem171 import "testing" -type caseType struct { - input string - expected int +type testType struct { + in string + want int } func TestTitleToNumber(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "A", - expected: 1, + in: "A", + want: 1, }, { - input: "C", - expected: 3, + in: "C", + want: 3, }, { - input: "Z", - expected: 26, + in: "Z", + want: 26, }, { - input: "AA", - expected: 27, + in: "AA", + want: 27, }, { - input: "AB", - expected: 28, + in: "AB", + want: 28, }, { - input: "ZY", - expected: 701, + in: "ZY", + want: 701, }, { - input: "AAA", - expected: 703, + in: "AAA", + want: 703, }, { - input: "XYZ", - expected: 16900, + in: "XYZ", + want: 16900, }, } - for _, tc := range tests { - output := titleToNumber(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := titleToNumber(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/excel-sheet-column-title/excel_sheet_column_title_test.go b/problems/excel-sheet-column-title/excel_sheet_column_title_test.go index 833f28140..97e289abe 100644 --- a/problems/excel-sheet-column-title/excel_sheet_column_title_test.go +++ b/problems/excel-sheet-column-title/excel_sheet_column_title_test.go @@ -2,62 +2,62 @@ package problem168 import "testing" -type caseType struct { - input int - expected string +type testType struct { + in int + want string } func TestConvertToTitle(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 1, - expected: "A", + in: 1, + want: "A", }, { - input: 3, - expected: "C", + in: 3, + want: "C", }, { - input: 26, - expected: "Z", + in: 26, + want: "Z", }, { - input: 52, - expected: "AZ", + in: 52, + want: "AZ", }, { - input: 27, - expected: "AA", + in: 27, + want: "AA", }, { - input: 28, - expected: "AB", + in: 28, + want: "AB", }, { - input: 701, - expected: "ZY", + in: 701, + want: "ZY", }, { - input: 703, - expected: "AAA", + in: 703, + want: "AAA", }, { - input: 16900, - expected: "XYZ", + in: 16900, + want: "XYZ", }, } // Solution 1 - for _, tc := range tests { - output := convertToTitle(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := convertToTitle(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } // Solution 2 - for _, tc := range tests { - output := convertToTitle2(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := convertToTitle2(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/factorial-trailing-zeroes/factorial_trailing_zeroes_test.go b/problems/factorial-trailing-zeroes/factorial_trailing_zeroes_test.go index c566aaf1c..31a453ee2 100644 --- a/problems/factorial-trailing-zeroes/factorial_trailing_zeroes_test.go +++ b/problems/factorial-trailing-zeroes/factorial_trailing_zeroes_test.go @@ -2,46 +2,46 @@ package problem172 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestTrailingZeroes(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 3, - expected: 0, + in: 3, + want: 0, }, { - input: 5, - expected: 1, + in: 5, + want: 1, }, { - input: 7, - expected: 1, + in: 7, + want: 1, }, { - input: 8, - expected: 1, + in: 8, + want: 1, }, { - input: 10, - expected: 2, + in: 10, + want: 2, }, { - input: 12, - expected: 2, + in: 12, + want: 2, }, { - input: 25, - expected: 6, + in: 25, + want: 6, }, } - for _, tc := range tests { - output := trailingZeroes(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := trailingZeroes(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/fair-candy-swap/fair_candy_swap_test.go b/problems/fair-candy-swap/fair_candy_swap_test.go index 822e9eeec..125a9771b 100644 --- a/problems/fair-candy-swap/fair_candy_swap_test.go +++ b/problems/fair-candy-swap/fair_candy_swap_test.go @@ -5,44 +5,44 @@ import ( "testing" ) -type caseType struct { - a []int - b []int - expected []int +type testType struct { + a []int + b []int + want []int } func TestFairCandySwap(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - a: []int{1, 1}, - b: []int{2, 2}, - expected: []int{1, 2}, + a: []int{1, 1}, + b: []int{2, 2}, + want: []int{1, 2}, }, { - a: []int{1, 2}, - b: []int{2, 3}, - expected: []int{1, 2}, + a: []int{1, 2}, + b: []int{2, 3}, + want: []int{1, 2}, }, { - a: []int{2}, - b: []int{1, 3}, - expected: []int{2, 3}, + a: []int{2}, + b: []int{1, 3}, + want: []int{2, 3}, }, { - a: []int{1, 2, 5}, - b: []int{2, 4}, - expected: []int{5, 4}, + a: []int{1, 2, 5}, + b: []int{2, 4}, + want: []int{5, 4}, }, { - a: []int{1, 2, 3}, - b: []int{11, 15, 17}, - expected: nil, + a: []int{1, 2, 3}, + b: []int{11, 15, 17}, + want: nil, }, } - for _, tc := range tests { - output := fairCandySwap(tc.a, tc.b) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.a, tc.b, output, tc.expected) + for _, tt := range tests { + got := fairCandySwap(tt.a, tt.b) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.a, tt.b, got, tt.want) } } } diff --git a/problems/fibonacci-number/fibonacci_number_test.go b/problems/fibonacci-number/fibonacci_number_test.go index acb5298ae..368a379a1 100644 --- a/problems/fibonacci-number/fibonacci_number_test.go +++ b/problems/fibonacci-number/fibonacci_number_test.go @@ -2,34 +2,34 @@ package problem509 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestFib(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 2, - expected: 1, + in: 2, + want: 1, }, { - input: 3, - expected: 2, + in: 3, + want: 2, }, { - input: 4, - expected: 3, + in: 4, + want: 3, }, { - input: 1, - expected: 1, + in: 1, + want: 1, }, } - for _, tc := range tests { - output := fib(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := fib(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/find-all-numbers-disappeared-in-an-array/find_all_numbers_disappeared_in_an_array_test.go b/problems/find-all-numbers-disappeared-in-an-array/find_all_numbers_disappeared_in_an_array_test.go index 62a0e2b12..14d09516c 100644 --- a/problems/find-all-numbers-disappeared-in-an-array/find_all_numbers_disappeared_in_an_array_test.go +++ b/problems/find-all-numbers-disappeared-in-an-array/find_all_numbers_disappeared_in_an_array_test.go @@ -5,30 +5,30 @@ import ( "testing" ) -type caseType struct { - input []int - expected []int +type testType struct { + in []int + want []int } func TestFindDisappearedNumbers(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{4, 3, 2, 7, 8, 2, 3, 1}, - expected: []int{5, 6}, + in: []int{4, 3, 2, 7, 8, 2, 3, 1}, + want: []int{5, 6}, }, { - input: []int{5, 4, 2, 3, 1}, - expected: []int{}, + in: []int{5, 4, 2, 3, 1}, + want: []int{}, }, { - input: []int{1, 1}, - expected: []int{2}, + in: []int{1, 1}, + want: []int{2}, }, } - for _, tc := range tests { - output := findDisappearedNumbers(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := findDisappearedNumbers(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/find-common-characters/find_common_characters_test.go b/problems/find-common-characters/find_common_characters_test.go index 54bc0cf4a..09ce43df3 100644 --- a/problems/find-common-characters/find_common_characters_test.go +++ b/problems/find-common-characters/find_common_characters_test.go @@ -5,26 +5,26 @@ import ( "testing" ) -type caseType struct { - input []string - expected []string +type testType struct { + in []string + want []string } func TestCommonChars(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []string{"bella", "label", "roller"}, - expected: []string{"e", "l", "l"}, + in: []string{"bella", "label", "roller"}, + want: []string{"e", "l", "l"}, }, { - input: []string{"cool", "lock", "cook"}, - expected: []string{"c", "o"}, + in: []string{"cool", "lock", "cook"}, + want: []string{"c", "o"}, }, } - for _, tc := range tests { - output := commonChars(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := commonChars(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/find-pivot-index/find_pivot_index_test.go b/problems/find-pivot-index/find_pivot_index_test.go index 9635bd421..e1d79c6e5 100644 --- a/problems/find-pivot-index/find_pivot_index_test.go +++ b/problems/find-pivot-index/find_pivot_index_test.go @@ -2,42 +2,42 @@ package problem724 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestPivotIndex(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 7, 3, 6, 5, 6}, - expected: 3, + in: []int{1, 7, 3, 6, 5, 6}, + want: 3, }, { - input: []int{1, 2, 3}, - expected: -1, + in: []int{1, 2, 3}, + want: -1, }, { - input: []int{0}, - expected: 0, + in: []int{0}, + want: 0, }, { - input: []int{0, 0}, - expected: 0, + in: []int{0, 0}, + want: 0, }, { - input: []int{1, 2, 1}, - expected: 1, + in: []int{1, 2, 1}, + want: 1, }, { - input: []int{}, - expected: -1, + in: []int{}, + want: -1, }, } - for _, tc := range tests { - output := pivotIndex(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := pivotIndex(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/find-smallest-letter-greater-than-target/find_smallest_letter_greater_than_target_test.go b/problems/find-smallest-letter-greater-than-target/find_smallest_letter_greater_than_target_test.go index 147c0babc..aa9ca5644 100644 --- a/problems/find-smallest-letter-greater-than-target/find_smallest_letter_greater_than_target_test.go +++ b/problems/find-smallest-letter-greater-than-target/find_smallest_letter_greater_than_target_test.go @@ -2,49 +2,49 @@ package problem744 import "testing" -type caseType struct { - input []byte - target byte - expected byte +type testType struct { + in []byte + target byte + want byte } func TestNextGreatestLetter(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []byte{'c', 'f', 'j'}, - target: 'a', - expected: 'c', + in: []byte{'c', 'f', 'j'}, + target: 'a', + want: 'c', }, { - input: []byte{'c', 'f', 'j'}, - target: 'c', - expected: 'f', + in: []byte{'c', 'f', 'j'}, + target: 'c', + want: 'f', }, { - input: []byte{'c', 'f', 'j'}, - target: 'd', - expected: 'f', + in: []byte{'c', 'f', 'j'}, + target: 'd', + want: 'f', }, { - input: []byte{'c', 'f', 'j'}, - target: 'g', - expected: 'j', + in: []byte{'c', 'f', 'j'}, + target: 'g', + want: 'j', }, { - input: []byte{'c', 'f', 'j'}, - target: 'j', - expected: 'c', + in: []byte{'c', 'f', 'j'}, + target: 'j', + want: 'c', }, { - input: []byte{'c', 'f', 'j'}, - target: 'k', - expected: 'c', + in: []byte{'c', 'f', 'j'}, + target: 'k', + want: 'c', }, } - for _, tc := range tests { - output := nextGreatestLetter(tc.input, tc.target) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := nextGreatestLetter(tt.in, tt.target) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/find-the-town-judge/find_the_town_judge_test.go b/problems/find-the-town-judge/find_the_town_judge_test.go index 3a4d90a6c..73eca79a9 100644 --- a/problems/find-the-town-judge/find_the_town_judge_test.go +++ b/problems/find-the-town-judge/find_the_town_judge_test.go @@ -2,20 +2,20 @@ package problem997 import "testing" -type caseType struct { - N int - trust [][]int - expected int +type testType struct { + N int + trust [][]int + want int } func TestFindJudge(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { N: 2, trust: [][]int{ {1, 2}, }, - expected: 2, + want: 2, }, { N: 3, @@ -23,7 +23,7 @@ func TestFindJudge(t *testing.T) { {1, 3}, {2, 3}, }, - expected: 3, + want: 3, }, { N: 3, @@ -32,7 +32,7 @@ func TestFindJudge(t *testing.T) { {2, 3}, {3, 1}, }, - expected: -1, + want: -1, }, { N: 3, @@ -40,7 +40,7 @@ func TestFindJudge(t *testing.T) { {1, 2}, {2, 3}, }, - expected: -1, + want: -1, }, { N: 4, @@ -51,18 +51,18 @@ func TestFindJudge(t *testing.T) { {2, 4}, {4, 3}, }, - expected: 3, + want: 3, }, { - N: 1, - trust: [][]int{}, - expected: 1, + N: 1, + trust: [][]int{}, + want: 1, }, } - for _, tc := range tests { - output := findJudge(tc.N, tc.trust) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.N, tc.trust, output, tc.expected) + for _, tt := range tests { + got := findJudge(tt.N, tt.trust) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.N, tt.trust, got, tt.want) } } } diff --git a/problems/first-unique-character-in-a-string/first_unique_character_in_a_string_test.go b/problems/first-unique-character-in-a-string/first_unique_character_in_a_string_test.go index 4179f315b..2f905c371 100644 --- a/problems/first-unique-character-in-a-string/first_unique_character_in_a_string_test.go +++ b/problems/first-unique-character-in-a-string/first_unique_character_in_a_string_test.go @@ -10,10 +10,10 @@ func TestFirstUniqChar(t *testing.T) { "aabbccddeeff": -1, } - for input, expected := range tests { - output := firstUniqChar(input) - if output != expected { - t.Fatalf("input: %v, output: %v, expected: %v", input, output, expected) + for in, want := range tests { + got := firstUniqChar(in) + if got != want { + t.Fatalf("in: %v, got: %v, want: %v", in, got, want) } } } diff --git a/problems/fizz-buzz/fizz_buzz_test.go b/problems/fizz-buzz/fizz_buzz_test.go index edb9ad571..4aba58f6d 100644 --- a/problems/fizz-buzz/fizz_buzz_test.go +++ b/problems/fizz-buzz/fizz_buzz_test.go @@ -5,16 +5,16 @@ import ( "testing" ) -type caseType struct { - input int - expected []string +type testType struct { + in int + want []string } func TestFizzBuzz(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 15, - expected: []string{ + in: 15, + want: []string{ "1", "2", "Fizz", @@ -33,8 +33,8 @@ func TestFizzBuzz(t *testing.T) { }, }, { - input: 5, - expected: []string{ + in: 5, + want: []string{ "1", "2", "Fizz", @@ -43,8 +43,8 @@ func TestFizzBuzz(t *testing.T) { }, }, { - input: 10, - expected: []string{ + in: 10, + want: []string{ "1", "2", "Fizz", @@ -59,10 +59,10 @@ func TestFizzBuzz(t *testing.T) { }, } - for _, tc := range tests { - output := fizzBuzz(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := fizzBuzz(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/flipping-an-image/flipping_an_image_test.go b/problems/flipping-an-image/flipping_an_image_test.go index 707d95aa0..d16d5e97b 100644 --- a/problems/flipping-an-image/flipping_an_image_test.go +++ b/problems/flipping-an-image/flipping_an_image_test.go @@ -5,33 +5,33 @@ import ( "testing" ) -type caseType struct { - input [][]int - expected [][]int +type testType struct { + in [][]int + want [][]int } func TestFlipAndInvertImage(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]int{ + in: [][]int{ {1, 1, 0}, {1, 0, 1}, {0, 0, 0}, }, - expected: [][]int{ + want: [][]int{ {1, 0, 0}, {0, 1, 0}, {1, 1, 1}, }, }, { - input: [][]int{ + in: [][]int{ {1, 1, 0, 0}, {1, 0, 0, 1}, {0, 1, 1, 1}, {1, 0, 1, 0}, }, - expected: [][]int{ + want: [][]int{ {1, 1, 0, 0}, {0, 1, 1, 0}, {0, 0, 0, 1}, @@ -39,10 +39,10 @@ func TestFlipAndInvertImage(t *testing.T) { }, }, } - for _, tc := range tests { - output := flipAndInvertImage(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := flipAndInvertImage(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/flower-planting-with-no-adjacent/flower_planting_with_no_adjacent_test.go b/problems/flower-planting-with-no-adjacent/flower_planting_with_no_adjacent_test.go index 36d11b5bb..5abf05d23 100644 --- a/problems/flower-planting-with-no-adjacent/flower_planting_with_no_adjacent_test.go +++ b/problems/flower-planting-with-no-adjacent/flower_planting_with_no_adjacent_test.go @@ -5,14 +5,14 @@ import ( "testing" ) -type caseType struct { - n int - paths [][]int - expected []int +type testType struct { + n int + paths [][]int + want []int } func TestGardenNoAdj(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { n: 3, paths: [][]int{ @@ -20,7 +20,7 @@ func TestGardenNoAdj(t *testing.T) { {2, 3}, {3, 1}, }, - expected: []int{1, 2, 3}, + want: []int{1, 2, 3}, }, { n: 4, @@ -28,7 +28,7 @@ func TestGardenNoAdj(t *testing.T) { {1, 2}, {3, 4}, }, - expected: []int{1, 2, 1, 2}, + want: []int{1, 2, 1, 2}, }, { n: 4, @@ -40,13 +40,13 @@ func TestGardenNoAdj(t *testing.T) { {1, 3}, {2, 4}, }, - expected: []int{1, 2, 3, 4}, + want: []int{1, 2, 3, 4}, }, } - for _, tc := range tests { - output := gardenNoAdj(tc.n, tc.paths) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.n, output, tc.expected) + for _, tt := range tests { + got := gardenNoAdj(tt.n, tt.paths) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.n, got, tt.want) } } } diff --git a/problems/generate-parentheses/generate_parentheses_test.go b/problems/generate-parentheses/generate_parentheses_test.go index 266b61599..3f61694ee 100644 --- a/problems/generate-parentheses/generate_parentheses_test.go +++ b/problems/generate-parentheses/generate_parentheses_test.go @@ -5,16 +5,16 @@ import ( "testing" ) -type caseType struct { - input int - expected []string +type testType struct { + in int + want []string } func TestGenerateParenthesis(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 3, - expected: []string{ + in: 3, + want: []string{ "((()))", "(()())", "(())()", @@ -23,23 +23,23 @@ func TestGenerateParenthesis(t *testing.T) { }, }, { - input: 2, - expected: []string{ + in: 2, + want: []string{ "(())", "()()", }, }, { - input: 1, - expected: []string{"()"}, + in: 1, + want: []string{"()"}, }, { - input: 0, - expected: []string{}, + in: 0, + want: []string{}, }, { - input: 5, - expected: []string{ + in: 5, + want: []string{ "((((()))))", "(((()())))", "(((())()))", @@ -85,10 +85,10 @@ func TestGenerateParenthesis(t *testing.T) { }, }, } - for _, tc := range tests { - output := generateParenthesis(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := generateParenthesis(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/goat-latin/goat_latin_test.go b/problems/goat-latin/goat_latin_test.go index 49f29fb8c..2f0d8b971 100644 --- a/problems/goat-latin/goat_latin_test.go +++ b/problems/goat-latin/goat_latin_test.go @@ -2,26 +2,26 @@ package problem824 import "testing" -type caseType struct { - input string - expected string +type testType struct { + in string + want string } func TestToGoatLatin(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "I speak Goat Latin", - expected: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa", + in: "I speak Goat Latin", + want: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa", }, { - input: "The quick brown fox jumped over the lazy dog", - expected: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa", + in: "The quick brown fox jumped over the lazy dog", + want: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa", }, } - for _, tc := range tests { - output := toGoatLatin(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := toGoatLatin(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/groups-of-special-equivalent-strings/groups_of_special_equivalent_strings_test.go b/problems/groups-of-special-equivalent-strings/groups_of_special_equivalent_strings_test.go index 483c64fa6..be141f771 100644 --- a/problems/groups-of-special-equivalent-strings/groups_of_special_equivalent_strings_test.go +++ b/problems/groups-of-special-equivalent-strings/groups_of_special_equivalent_strings_test.go @@ -2,34 +2,34 @@ package problem893 import "testing" -type caseType struct { - input []string - expected int +type testType struct { + in []string + want int } func TestNumSpecialEquivGroups(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []string{"a", "b", "c", "a", "c", "c"}, - expected: 3, + in: []string{"a", "b", "c", "a", "c", "c"}, + want: 3, }, { - input: []string{"aa", "bb", "ab", "ba"}, - expected: 4, + in: []string{"aa", "bb", "ab", "ba"}, + want: 4, }, { - input: []string{"abc", "acb", "bac", "bca", "cab", "cba"}, - expected: 3, + in: []string{"abc", "acb", "bac", "bca", "cab", "cba"}, + want: 3, }, { - input: []string{"abcd", "cdab", "adcb", "cbad"}, - expected: 1, + in: []string{"abcd", "cdab", "adcb", "cbad"}, + want: 1, }, } - for _, tc := range tests { - output := numSpecialEquivGroups(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := numSpecialEquivGroups(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/hamming-distance/hamming_distance_test.go b/problems/hamming-distance/hamming_distance_test.go index b5616066f..c932a0c13 100644 --- a/problems/hamming-distance/hamming_distance_test.go +++ b/problems/hamming-distance/hamming_distance_test.go @@ -2,24 +2,24 @@ package problem461 import "testing" -type caseType struct { - x int - y int - expected int +type testType struct { + x int + y int + want int } func TestHammingDistance(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - x: 1, - y: 4, - expected: 2, + x: 1, + y: 4, + want: 2, }, } - for _, tc := range tests { - output := hammingDistance(tc.x, tc.y) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.x, tc.y, output, tc.expected) + for _, tt := range tests { + got := hammingDistance(tt.x, tt.y) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.x, tt.y, got, tt.want) } } } diff --git a/problems/happy-number/happy_number_test.go b/problems/happy-number/happy_number_test.go index b8b8e0981..4428de6d1 100644 --- a/problems/happy-number/happy_number_test.go +++ b/problems/happy-number/happy_number_test.go @@ -2,30 +2,30 @@ package problem202 import "testing" -type caseType struct { - input int - expected bool +type testType struct { + in int + want bool } func TestIsHappy(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 19, - expected: true, + in: 19, + want: true, }, { - input: 1, - expected: true, + in: 1, + want: true, }, { - input: 0, - expected: false, + in: 0, + want: false, }, } - for _, tc := range tests { - output := isHappy(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isHappy(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/height-checker/height_checker_test.go b/problems/height-checker/height_checker_test.go index 4e77b23cc..d0461e31f 100644 --- a/problems/height-checker/height_checker_test.go +++ b/problems/height-checker/height_checker_test.go @@ -2,22 +2,22 @@ package problem1051 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestHeightChecker(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 1, 4, 2, 1, 3}, - expected: 3, + in: []int{1, 1, 4, 2, 1, 3}, + want: 3, }, } - for _, tc := range tests { - output := heightChecker(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := heightChecker(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/house-robber/house_robber_test.go b/problems/house-robber/house_robber_test.go index cc7956634..680d832b9 100644 --- a/problems/house-robber/house_robber_test.go +++ b/problems/house-robber/house_robber_test.go @@ -2,26 +2,26 @@ package problem198 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestRob(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 3, 1}, - expected: 4, + in: []int{1, 2, 3, 1}, + want: 4, }, { - input: []int{2, 7, 9, 3, 1}, - expected: 12, + in: []int{2, 7, 9, 3, 1}, + want: 12, }, } - for _, tc := range tests { - output := rob(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := rob(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/image-smoother/image_smoother_test.go b/problems/image-smoother/image_smoother_test.go index e4d2e9e2c..af0f48502 100644 --- a/problems/image-smoother/image_smoother_test.go +++ b/problems/image-smoother/image_smoother_test.go @@ -5,42 +5,42 @@ import ( "testing" ) -type caseType struct { - input [][]int - expected [][]int +type testType struct { + in [][]int + want [][]int } func TestImageSmoother(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]int{ + in: [][]int{ {1, 1, 1}, {1, 0, 1}, {1, 1, 1}, }, - expected: [][]int{ + want: [][]int{ {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, }, }, { - input: [][]int{ + in: [][]int{ {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, }, - expected: [][]int{ + want: [][]int{ {3, 3, 4}, {4, 5, 5}, {6, 6, 7}, }, }, } - for _, tc := range tests { - output := imageSmoother(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := imageSmoother(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/implement-strstr/implement_strstr_test.go b/problems/implement-strstr/implement_strstr_test.go index 5ad6682ee..9cc25a1d9 100644 --- a/problems/implement-strstr/implement_strstr_test.go +++ b/problems/implement-strstr/implement_strstr_test.go @@ -2,29 +2,29 @@ package problem28 import "testing" -type caseType struct { +type testType struct { haystack string needle string - expected int + want int } func TestStrStr(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { haystack: "hello", needle: "ll", - expected: 2, + want: 2, }, { haystack: "this is test string", needle: "a", - expected: -1, + want: -1, }, } - for _, tc := range tests { - output := strStr(tc.haystack, tc.needle) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.haystack, tc.needle, output, tc.expected) + for _, tt := range tests { + got := strStr(tt.haystack, tt.needle) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.haystack, tt.needle, got, tt.want) } } } diff --git a/problems/integer-to-roman/integer_to_roman_test.go b/problems/integer-to-roman/integer_to_roman_test.go index 35629a67a..4146e85c6 100644 --- a/problems/integer-to-roman/integer_to_roman_test.go +++ b/problems/integer-to-roman/integer_to_roman_test.go @@ -2,46 +2,46 @@ package problem12 import "testing" -type caseType struct { - input int - expected string +type testType struct { + in int + want string } func TestIntToRoman(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 3, - expected: "III", + in: 3, + want: "III", }, { - input: 4, - expected: "IV", + in: 4, + want: "IV", }, { - input: 9, - expected: "IX", + in: 9, + want: "IX", }, { - input: 20, - expected: "XX", + in: 20, + want: "XX", }, { - input: 58, - expected: "LVIII", + in: 58, + want: "LVIII", }, { - input: 1994, - expected: "MCMXCIV", + in: 1994, + want: "MCMXCIV", }, { - input: 11111, - expected: "MMMMMMMMMMMCXI", + in: 11111, + want: "MMMMMMMMMMMCXI", }, } - for _, tc := range tests { - output := intToRoman(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := intToRoman(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/intersection-of-two-arrays-ii/intersection_of_two_arrays_ii_test.go b/problems/intersection-of-two-arrays-ii/intersection_of_two_arrays_ii_test.go index b9126856d..a25703034 100644 --- a/problems/intersection-of-two-arrays-ii/intersection_of_two_arrays_ii_test.go +++ b/problems/intersection-of-two-arrays-ii/intersection_of_two_arrays_ii_test.go @@ -6,34 +6,34 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - nums1 []int - nums2 []int - expected []int +type testType struct { + nums1 []int + nums2 []int + want []int } func TestIntersect(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - nums1: []int{1, 2, 2, 1}, - nums2: []int{2, 2}, - expected: []int{2, 2}, + nums1: []int{1, 2, 2, 1}, + nums2: []int{2, 2}, + want: []int{2, 2}, }, { - nums1: []int{4, 9, 5}, - nums2: []int{9, 4, 9, 8, 4}, - expected: []int{4, 9}, + nums1: []int{4, 9, 5}, + nums2: []int{9, 4, 9, 8, 4}, + want: []int{4, 9}, }, { - nums1: []int{1, 3, 3, 5, 5, 5, 7, 7, 7, 9}, - nums2: []int{2, 3, 3, 5, 5, 5, 7, 8}, - expected: []int{3, 3, 5, 5, 5, 7}, + nums1: []int{1, 3, 3, 5, 5, 5, 7, 7, 7, 9}, + nums2: []int{2, 3, 3, 5, 5, 5, 7, 8}, + want: []int{3, 3, 5, 5, 5, 7}, }, } - for _, tc := range tests { - output := intersect(tc.nums1, tc.nums2) - if !kit.IsEqualSliceInt(output, tc.expected) { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.nums1, tc.nums2, output, tc.expected) + for _, tt := range tests { + got := intersect(tt.nums1, tt.nums2) + if !kit.IsEqualSliceInt(got, tt.want) { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.nums1, tt.nums2, got, tt.want) } } } diff --git a/problems/intersection-of-two-linked-lists/intersection_of_two_linked_lists_test.go b/problems/intersection-of-two-linked-lists/intersection_of_two_linked_lists_test.go index 2889d0aa6..ff9e48259 100644 --- a/problems/intersection-of-two-linked-lists/intersection_of_two_linked_lists_test.go +++ b/problems/intersection-of-two-linked-lists/intersection_of_two_linked_lists_test.go @@ -6,14 +6,14 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { +type testType struct { headA []int headB []int intersection []int } func TestGetIntersectionNode(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { headA: []int{4, 1}, headB: []int{5, 0, 1}, @@ -35,10 +35,10 @@ func TestGetIntersectionNode(t *testing.T) { intersection: []int{}, }, } - for _, tc := range tests { - intersection := kit.SliceInt2ListNode(tc.intersection) - headA := kit.SliceInt2ListNode(tc.headA) - headB := kit.SliceInt2ListNode(tc.headB) + for _, tt := range tests { + intersection := kit.SliceInt2ListNode(tt.intersection) + headA := kit.SliceInt2ListNode(tt.headA) + headB := kit.SliceInt2ListNode(tt.headB) for n := headA; n != nil; n = n.Next { if n.Next == nil { n.Next = intersection @@ -51,9 +51,9 @@ func TestGetIntersectionNode(t *testing.T) { break } } - output := getIntersectionNode(headA, headB) - if output != intersection { - t.Fatalf("input: %v, output: %v %v, expected: %v", tc.headA, tc.headB, output, tc.intersection) + got := getIntersectionNode(headA, headB) + if got != intersection { + t.Fatalf("in: %v, got: %v %v, want: %v", tt.headA, tt.headB, got, tt.intersection) } } } diff --git a/problems/jewels-and-stones/jewels_and_stones_test.go b/problems/jewels-and-stones/jewels_and_stones_test.go index 67302634f..9d172224f 100644 --- a/problems/jewels-and-stones/jewels_and_stones_test.go +++ b/problems/jewels-and-stones/jewels_and_stones_test.go @@ -2,35 +2,35 @@ package problem771 import "testing" -type caseType struct { - j string - s string - expected int +type testType struct { + j string + s string + want int } func TestNumJewelsInStones(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - j: "aA", - s: "aAAbbbb", - expected: 3, + j: "aA", + s: "aAAbbbb", + want: 3, }, { - j: "z", - s: "ZZ", - expected: 0, + j: "z", + s: "ZZ", + want: 0, }, { - j: "Tb", - s: "abcdefhelloaabads", - expected: 2, + j: "Tb", + s: "abcdefhelloaabads", + want: 2, }, } - for _, tc := range tests { - output := numJewelsInStones(tc.j, tc.s) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.j, tc.s, output, tc.expected) + for _, tt := range tests { + got := numJewelsInStones(tt.j, tt.s) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.j, tt.s, got, tt.want) } } } diff --git a/problems/k-closest-points-to-origin/k_closest_points_to_origin_test.go b/problems/k-closest-points-to-origin/k_closest_points_to_origin_test.go index 7656cab55..3fb34c3fe 100644 --- a/problems/k-closest-points-to-origin/k_closest_points_to_origin_test.go +++ b/problems/k-closest-points-to-origin/k_closest_points_to_origin_test.go @@ -5,41 +5,41 @@ import ( "testing" ) -type caseType struct { - input [][]int - k int - expected [][]int +type testType struct { + in [][]int + k int + want [][]int } func TestKClosest(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]int{ + in: [][]int{ {1, 3}, {-2, 2}, }, k: 1, - expected: [][]int{ + want: [][]int{ {-2, 2}, }, }, { - input: [][]int{ + in: [][]int{ {3, 3}, {5, -1}, {-2, 4}, }, k: 2, - expected: [][]int{ + want: [][]int{ {3, 3}, {-2, 4}, }, }, } - for _, tc := range tests { - output := kClosest(tc.input, tc.k) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := kClosest(tt.in, tt.k) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/k-diff-pairs-in-an-array/k_diff_pairs_in_an_array_test.go b/problems/k-diff-pairs-in-an-array/k_diff_pairs_in_an_array_test.go index 66f695c29..6fe5b4a3a 100644 --- a/problems/k-diff-pairs-in-an-array/k_diff_pairs_in_an_array_test.go +++ b/problems/k-diff-pairs-in-an-array/k_diff_pairs_in_an_array_test.go @@ -2,39 +2,39 @@ package problem532 import "testing" -type caseType struct { - nums []int - k int - expected int +type testType struct { + nums []int + k int + want int } func TestFindPairs(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - nums: []int{1, 3, 1, 5, 4}, - k: 0, - expected: 1, + nums: []int{1, 3, 1, 5, 4}, + k: 0, + want: 1, }, { - nums: []int{3, 1, 4, 1, 5}, - k: 2, - expected: 2, + nums: []int{3, 1, 4, 1, 5}, + k: 2, + want: 2, }, { - nums: []int{1, 2, 3, 4, 5}, - k: 1, - expected: 4, + nums: []int{1, 2, 3, 4, 5}, + k: 1, + want: 4, }, { - nums: []int{1, 2, 3, 4, 5}, - k: -1, - expected: 0, + nums: []int{1, 2, 3, 4, 5}, + k: -1, + want: 0, }, } - for _, tc := range tests { - output := findPairs(tc.nums, tc.k) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.nums, tc.k, output, tc.expected) + for _, tt := range tests { + got := findPairs(tt.nums, tt.k) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.nums, tt.k, got, tt.want) } } } diff --git a/problems/kth-largest-element-in-an-array/kth_largest_element_in_an_array_test.go b/problems/kth-largest-element-in-an-array/kth_largest_element_in_an_array_test.go index 61aab54fb..0f9840280 100644 --- a/problems/kth-largest-element-in-an-array/kth_largest_element_in_an_array_test.go +++ b/problems/kth-largest-element-in-an-array/kth_largest_element_in_an_array_test.go @@ -2,28 +2,28 @@ package problem215 import "testing" -type caseType struct { - input []int - k int - expected int +type testType struct { + in []int + k int + want int } func TestFindKthLargest(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{3, 2, 1, 5, 6, 4}, - k: 2, - expected: 5, + in: []int{3, 2, 1, 5, 6, 4}, + k: 2, + want: 5, }, { - input: []int{3, 2, 3, 1, 2, 4, 5, 5, 6}, - k: 4, - expected: 4, + in: []int{3, 2, 3, 1, 2, 4, 5, 5, 6}, + k: 4, + want: 4, }, } - for _, tc := range tests { - output := findKthLargest(tc.input, tc.k) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := findKthLargest(tt.in, tt.k) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/largest-number-at-least-twice-of-others/largest_number_at_least_twice_of_others_test.go b/problems/largest-number-at-least-twice-of-others/largest_number_at_least_twice_of_others_test.go index dff898997..babf59dd5 100644 --- a/problems/largest-number-at-least-twice-of-others/largest_number_at_least_twice_of_others_test.go +++ b/problems/largest-number-at-least-twice-of-others/largest_number_at_least_twice_of_others_test.go @@ -2,38 +2,38 @@ package problem747 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestDominantIndex(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{3, 6, 1, 0}, - expected: 1, + in: []int{3, 6, 1, 0}, + want: 1, }, { - input: []int{1, 2, 3, 4}, - expected: -1, + in: []int{1, 2, 3, 4}, + want: -1, }, { - input: []int{1}, - expected: 0, + in: []int{1}, + want: 0, }, { - input: []int{0, 0, 3, 2}, - expected: -1, + in: []int{0, 0, 3, 2}, + want: -1, }, { - input: []int{3, 0, 0, 2}, - expected: -1, + in: []int{3, 0, 0, 2}, + want: -1, }, } - for _, tc := range tests { - output := dominantIndex(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := dominantIndex(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/largest-perimeter-triangle/largest_perimeter_triangle_test.go b/problems/largest-perimeter-triangle/largest_perimeter_triangle_test.go index 4d43a07ee..9719d3c1b 100644 --- a/problems/largest-perimeter-triangle/largest_perimeter_triangle_test.go +++ b/problems/largest-perimeter-triangle/largest_perimeter_triangle_test.go @@ -2,34 +2,34 @@ package problem976 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestLargestPerimeter(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{2, 1, 2}, - expected: 5, + in: []int{2, 1, 2}, + want: 5, }, { - input: []int{1, 2, 1}, - expected: 0, + in: []int{1, 2, 1}, + want: 0, }, { - input: []int{3, 2, 3, 4}, - expected: 10, + in: []int{3, 2, 3, 4}, + want: 10, }, { - input: []int{3, 6, 2, 3}, - expected: 8, + in: []int{3, 6, 2, 3}, + want: 8, }, } - for _, tc := range tests { - output := largestPerimeter(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := largestPerimeter(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/largest-time-for-given-digits/largest_time_for_given_digits_test.go b/problems/largest-time-for-given-digits/largest_time_for_given_digits_test.go index 9c17c6208..012db5c04 100644 --- a/problems/largest-time-for-given-digits/largest_time_for_given_digits_test.go +++ b/problems/largest-time-for-given-digits/largest_time_for_given_digits_test.go @@ -2,30 +2,30 @@ package problem949 import "testing" -type caseType struct { - input []int - expected string +type testType struct { + in []int + want string } func TestLargestTimeFromDigits(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 3, 4}, - expected: "23:41", + in: []int{1, 2, 3, 4}, + want: "23:41", }, { - input: []int{5, 5, 5, 5}, - expected: "", + in: []int{5, 5, 5, 5}, + want: "", }, { - input: []int{2, 0, 6, 6}, - expected: "06:26", + in: []int{2, 0, 6, 6}, + want: "06:26", }, } - for _, tc := range tests { - output := largestTimeFromDigits(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := largestTimeFromDigits(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/last-stone-weight/last_stone_weight_test.go b/problems/last-stone-weight/last_stone_weight_test.go index ed097948d..413f1d538 100644 --- a/problems/last-stone-weight/last_stone_weight_test.go +++ b/problems/last-stone-weight/last_stone_weight_test.go @@ -2,30 +2,30 @@ package problem1046 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestLastStoneWeight(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{2, 7, 4, 1, 8, 1}, - expected: 1, + in: []int{2, 7, 4, 1, 8, 1}, + want: 1, }, { - input: []int{2, 7, 4, 1, 8, 1, 5}, - expected: 0, + in: []int{2, 7, 4, 1, 8, 1, 5}, + want: 0, }, { - input: []int{316, 157, 73, 106, 771, 828}, - expected: 37, + in: []int{316, 157, 73, 106, 771, 828}, + want: 37, }, } - for _, tc := range tests { - output := lastStoneWeight(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := lastStoneWeight(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/last-substring-in-lexicographical-order/last_substring_in_lexicographical_order_test.go b/problems/last-substring-in-lexicographical-order/last_substring_in_lexicographical_order_test.go index 313012080..1e78a9171 100644 --- a/problems/last-substring-in-lexicographical-order/last_substring_in_lexicographical_order_test.go +++ b/problems/last-substring-in-lexicographical-order/last_substring_in_lexicographical_order_test.go @@ -2,34 +2,34 @@ package problem1163 import "testing" -type caseType struct { - input string - expected string +type testType struct { + in string + want string } func TestLastSubstring(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "abab", - expected: "bab", + in: "abab", + want: "bab", }, { - input: "abcdabc", - expected: "dabc", + in: "abcdabc", + want: "dabc", }, { - input: "ffbcdfeda", - expected: "ffbcdfeda", + in: "ffbcdfeda", + want: "ffbcdfeda", }, { - input: "hksljkjsfjv", - expected: "v", + in: "hksljkjsfjv", + want: "v", }, } - for _, tc := range tests { - output := lastSubstring(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := lastSubstring(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/length-of-last-word/length_of_last_word_test.go b/problems/length-of-last-word/length_of_last_word_test.go index 31d0a1fd5..0ce4d9c57 100644 --- a/problems/length-of-last-word/length_of_last_word_test.go +++ b/problems/length-of-last-word/length_of_last_word_test.go @@ -13,10 +13,10 @@ func TestLengthOfLastWord(t *testing.T) { "b ": 1, } - for input, expected := range tests { - output := lengthOfLastWord(input) - if output != expected { - t.Fatalf("input: %v, output: %v, expected: %v", input, output, expected) + for in, want := range tests { + got := lengthOfLastWord(in) + if got != want { + t.Fatalf("in: %v, got: %v, want: %v", in, got, want) } } } diff --git a/problems/letter-combinations-of-a-phone-number/letter_combinations_of_a_phone_number_test.go b/problems/letter-combinations-of-a-phone-number/letter_combinations_of_a_phone_number_test.go index 582dced9c..8f44f3aa3 100644 --- a/problems/letter-combinations-of-a-phone-number/letter_combinations_of_a_phone_number_test.go +++ b/problems/letter-combinations-of-a-phone-number/letter_combinations_of_a_phone_number_test.go @@ -5,26 +5,26 @@ import ( "testing" ) -type caseType struct { - input string - expected []string +type testType struct { + in string + want []string } func TestLetterCombinations(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "", - expected: nil, + in: "", + want: nil, }, { - input: "23", - expected: []string{"ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"}, + in: "23", + want: []string{"ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"}, }, } - for _, tc := range tests { - output := letterCombinations(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := letterCombinations(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/linked-list-cycle/linked_list_cycle_test.go b/problems/linked-list-cycle/linked_list_cycle_test.go index 56e2e6630..12b1a01af 100644 --- a/problems/linked-list-cycle/linked_list_cycle_test.go +++ b/problems/linked-list-cycle/linked_list_cycle_test.go @@ -6,40 +6,40 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - pos int - expected bool +type testType struct { + in []int + pos int + want bool } func TestHasCycle(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{3, 2, 0, -4}, - pos: 1, - expected: true, + in: []int{3, 2, 0, -4}, + pos: 1, + want: true, }, { - input: []int{1, 2}, - pos: 0, - expected: true, + in: []int{1, 2}, + pos: 0, + want: true, }, { - input: []int{1, 2, 3, 4, 5}, - pos: -1, - expected: false, + in: []int{1, 2, 3, 4, 5}, + pos: -1, + want: false, }, { - input: []int{1}, - pos: -1, - expected: false, + in: []int{1}, + pos: -1, + want: false, }, } - for _, tc := range tests { - input := kit.SliceInt2ListNode(tc.input) - p, curr := input, input - for i := 0; curr != nil && tc.pos >= 0; i, curr = i+1, curr.Next { - if i == tc.pos { + for _, tt := range tests { + in := kit.SliceInt2ListNode(tt.in) + p, curr := in, in + for i := 0; curr != nil && tt.pos >= 0; i, curr = i+1, curr.Next { + if i == tt.pos { p = curr } if curr.Next == nil { @@ -47,9 +47,9 @@ func TestHasCycle(t *testing.T) { break } } - output := hasCycle(input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + got := hasCycle(in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/long-pressed-name/long_pressed_name_test.go b/problems/long-pressed-name/long_pressed_name_test.go index c62049e35..25697c9c1 100644 --- a/problems/long-pressed-name/long_pressed_name_test.go +++ b/problems/long-pressed-name/long_pressed_name_test.go @@ -2,64 +2,64 @@ package problem925 import "testing" -type caseType struct { - name string - typed string - expected bool +type testType struct { + name string + typed string + want bool } func TestIsLongPressedName(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - name: "alex", - typed: "aaleex", - expected: true, + name: "alex", + typed: "aaleex", + want: true, }, { - name: "saeed", - typed: "ssaaedd", - expected: false, + name: "saeed", + typed: "ssaaedd", + want: false, }, { - name: "leelee", - typed: "lleeelee", - expected: true, + name: "leelee", + typed: "lleeelee", + want: true, }, { - name: "laiden", - typed: "laiden", - expected: true, + name: "laiden", + typed: "laiden", + want: true, }, { - name: "laiden", - typed: "laidef", - expected: false, + name: "laiden", + typed: "laidef", + want: false, }, { - name: "a", - typed: "a", - expected: true, + name: "a", + typed: "a", + want: true, }, { - name: "a", - typed: "b", - expected: false, + name: "a", + typed: "b", + want: false, }, { - name: "pyplrz", - typed: "ppyypllr", - expected: false, + name: "pyplrz", + typed: "ppyypllr", + want: false, }, { - name: "vtkgn", - typed: "vttkgnn", - expected: true, + name: "vtkgn", + typed: "vttkgnn", + want: true, }, } - for _, tc := range tests { - output := isLongPressedName(tc.name, tc.typed) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.name, tc.typed, output, tc.expected) + for _, tt := range tests { + got := isLongPressedName(tt.name, tt.typed) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.name, tt.typed, got, tt.want) } } } diff --git a/problems/longest-common-prefix/longest_common_prefix_test.go b/problems/longest-common-prefix/longest_common_prefix_test.go index f042981a9..3953de3e3 100644 --- a/problems/longest-common-prefix/longest_common_prefix_test.go +++ b/problems/longest-common-prefix/longest_common_prefix_test.go @@ -2,31 +2,31 @@ package problem14 import "testing" -type caseType struct { - input []string - expected string +type testType struct { + in []string + want string } func TestLongestCommonPrefix(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []string{"flower", "flow", "flight"}, - expected: "fl", + in: []string{"flower", "flow", "flight"}, + want: "fl", }, { - input: []string{"dog", "race", "car"}, - expected: "", + in: []string{"dog", "race", "car"}, + want: "", }, { - input: nil, - expected: "", + in: nil, + want: "", }, } - for _, tc := range tests { - output := longestCommonPrefix(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := longestCommonPrefix(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/longest-continuous-increasing-subsequence/longest_continuous_increasing_subsequence_test.go b/problems/longest-continuous-increasing-subsequence/longest_continuous_increasing_subsequence_test.go index 43305213d..fb0f01746 100644 --- a/problems/longest-continuous-increasing-subsequence/longest_continuous_increasing_subsequence_test.go +++ b/problems/longest-continuous-increasing-subsequence/longest_continuous_increasing_subsequence_test.go @@ -2,34 +2,34 @@ package problem674 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestFindLengthOfLCIS(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 3, 5, 4, 7}, - expected: 3, + in: []int{1, 3, 5, 4, 7}, + want: 3, }, { - input: []int{2, 2, 2, 2, 2}, - expected: 1, + in: []int{2, 2, 2, 2, 2}, + want: 1, }, { - input: []int{}, - expected: 0, + in: []int{}, + want: 0, }, { - input: []int{1, 3, 5, 7}, - expected: 4, + in: []int{1, 3, 5, 7}, + want: 4, }, } - for _, tc := range tests { - output := findLengthOfLCIS(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := findLengthOfLCIS(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/longest-palindromic-substring/longest_palindromic_substring_test.go b/problems/longest-palindromic-substring/longest_palindromic_substring_test.go index 43b122aa6..60612ce84 100644 --- a/problems/longest-palindromic-substring/longest_palindromic_substring_test.go +++ b/problems/longest-palindromic-substring/longest_palindromic_substring_test.go @@ -2,38 +2,38 @@ package problem5 import "testing" -type caseType struct { - input string - expected string +type testType struct { + in string + want string } func TestLongestPalindrome(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "babad", - expected: "bab", + in: "babad", + want: "bab", }, { - input: "cbbd", - expected: "bb", + in: "cbbd", + want: "bb", }, { - input: "", - expected: "", + in: "", + want: "", }, { - input: "a", - expected: "a", + in: "a", + want: "a", }, { - input: "abbba", - expected: "abbba", + in: "abbba", + want: "abbba", }, } - for _, tc := range tests { - output := longestPalindrome(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := longestPalindrome(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/longest-substring-without-repeating-characters/longest_substring_without_repeating_characters_test.go b/problems/longest-substring-without-repeating-characters/longest_substring_without_repeating_characters_test.go index 1f29ab6d9..d1048a179 100644 --- a/problems/longest-substring-without-repeating-characters/longest_substring_without_repeating_characters_test.go +++ b/problems/longest-substring-without-repeating-characters/longest_substring_without_repeating_characters_test.go @@ -10,10 +10,10 @@ func TestLengthOfLongestSubstring(t *testing.T) { "abcdef": 6, } - for input, expected := range tests { - output := lengthOfLongestSubstring(input) - if output != expected { - t.Fatalf("input: %v, output: %v, expected: %v", input, output, expected) + for in, want := range tests { + got := lengthOfLongestSubstring(in) + if got != want { + t.Fatalf("in: %v, got: %v, want: %v", in, got, want) } } } diff --git a/problems/longest-uncommon-subsequence-i/longest_uncommon_subsequence_i_test.go b/problems/longest-uncommon-subsequence-i/longest_uncommon_subsequence_i_test.go index c1f748a14..2836f24df 100644 --- a/problems/longest-uncommon-subsequence-i/longest_uncommon_subsequence_i_test.go +++ b/problems/longest-uncommon-subsequence-i/longest_uncommon_subsequence_i_test.go @@ -2,39 +2,39 @@ package problem521 import "testing" -type caseType struct { - a string - b string - expected int +type testType struct { + a string + b string + want int } func TestFindLUSlength(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - a: "aba", - b: "cdc", - expected: 3, + a: "aba", + b: "cdc", + want: 3, }, { - a: "aba", - b: "abcdef", - expected: 6, + a: "aba", + b: "abcdef", + want: 6, }, { - a: "abcdef", - b: "cdc", - expected: 6, + a: "abcdef", + b: "cdc", + want: 6, }, { - a: "abc", - b: "abc", - expected: -1, + a: "abc", + b: "abc", + want: -1, }, } - for _, tc := range tests { - output := findLUSlength(tc.a, tc.b) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.a, tc.b, output, tc.expected) + for _, tt := range tests { + got := findLUSlength(tt.a, tt.b) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.a, tt.b, got, tt.want) } } } diff --git a/problems/magic-squares-in-grid/magic_squares_in_grid_test.go b/problems/magic-squares-in-grid/magic_squares_in_grid_test.go index 630ba541a..38c8d222a 100644 --- a/problems/magic-squares-in-grid/magic_squares_in_grid_test.go +++ b/problems/magic-squares-in-grid/magic_squares_in_grid_test.go @@ -2,42 +2,42 @@ package problem840 import "testing" -type caseType struct { - input [][]int - expected int +type testType struct { + in [][]int + want int } func TestNumMagicSquaresInside(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]int{ + in: [][]int{ {4, 3, 8, 4}, {9, 5, 1, 9}, {2, 7, 6, 2}, }, - expected: 1, + want: 1, }, { - input: [][]int{ + in: [][]int{ {5, 5, 5}, {5, 5, 5}, {5, 5, 5}, }, - expected: 0, + want: 0, }, { - input: [][]int{ + in: [][]int{ {1, 8, 6}, {10, 5, 0}, {4, 2, 9}, }, - expected: 0, + want: 0, }, } - for _, tc := range tests { - output := numMagicSquaresInside(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := numMagicSquaresInside(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/majority-element/majority_element_test.go b/problems/majority-element/majority_element_test.go index 80b48ccfa..168a96e87 100644 --- a/problems/majority-element/majority_element_test.go +++ b/problems/majority-element/majority_element_test.go @@ -2,34 +2,34 @@ package problem169 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestMajorityElement(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{3, 2, 3}, - expected: 3, + in: []int{3, 2, 3}, + want: 3, }, { - input: []int{2, 2, 1, 1, 1, 2, 2}, - expected: 2, + in: []int{2, 2, 1, 1, 1, 2, 2}, + want: 2, }, { - input: []int{2, 2, 2, 2, 1, 1, 1}, - expected: 2, + in: []int{2, 2, 2, 2, 1, 1, 1}, + want: 2, }, { - input: []int{1}, - expected: 1, + in: []int{1}, + want: 1, }, } - for _, tc := range tests { - output := majorityElement(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := majorityElement(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/max-consecutive-ones/max_consecutive_ones_test.go b/problems/max-consecutive-ones/max_consecutive_ones_test.go index 049b9060e..ef665ebe0 100644 --- a/problems/max-consecutive-ones/max_consecutive_ones_test.go +++ b/problems/max-consecutive-ones/max_consecutive_ones_test.go @@ -2,26 +2,26 @@ package problem485 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestFindMaxConsecutiveOnes(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 1, 0, 1, 1, 1}, - expected: 3, + in: []int{1, 1, 0, 1, 1, 1}, + want: 3, }, { - input: []int{1, 0, 1, 1, 0, 1}, - expected: 2, + in: []int{1, 0, 1, 1, 0, 1}, + want: 2, }, } - for _, tc := range tests { - output := findMaxConsecutiveOnes(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := findMaxConsecutiveOnes(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/maximize-distance-to-closest-person/maximize_distance_to_closest_person_test.go b/problems/maximize-distance-to-closest-person/maximize_distance_to_closest_person_test.go index cfb94db07..1d5e65f7c 100644 --- a/problems/maximize-distance-to-closest-person/maximize_distance_to_closest_person_test.go +++ b/problems/maximize-distance-to-closest-person/maximize_distance_to_closest_person_test.go @@ -2,46 +2,46 @@ package problem849 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestMaxDistToClosest(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 0, 0, 0, 1, 0, 1}, - expected: 2, + in: []int{1, 0, 0, 0, 1, 0, 1}, + want: 2, }, { - input: []int{1, 0, 0, 0}, - expected: 3, + in: []int{1, 0, 0, 0}, + want: 3, }, { - input: []int{0, 0, 0, 1}, - expected: 3, + in: []int{0, 0, 0, 1}, + want: 3, }, { - input: []int{0, 0, 0, 0, 0, 1, 0}, - expected: 5, + in: []int{0, 0, 0, 0, 0, 1, 0}, + want: 5, }, { - input: []int{0, 1, 0, 0, 0, 1, 0}, - expected: 2, + in: []int{0, 1, 0, 0, 0, 1, 0}, + want: 2, }, { - input: []int{0, 1, 0, 0, 0, 0, 0}, - expected: 5, + in: []int{0, 1, 0, 0, 0, 0, 0}, + want: 5, }, { - input: []int{1, 0, 1}, - expected: 1, + in: []int{1, 0, 1}, + want: 1, }, } - for _, tc := range tests { - output := maxDistToClosest(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := maxDistToClosest(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/maximize-sum-of-array-after-k-negations/maximize_sum_of_array_after_k_negations_test.go b/problems/maximize-sum-of-array-after-k-negations/maximize_sum_of_array_after_k_negations_test.go index 632b5bf44..d506d5842 100644 --- a/problems/maximize-sum-of-array-after-k-negations/maximize_sum_of_array_after_k_negations_test.go +++ b/problems/maximize-sum-of-array-after-k-negations/maximize_sum_of_array_after_k_negations_test.go @@ -2,34 +2,34 @@ package problem1005 import "testing" -type caseType struct { - input []int - k int - expected int +type testType struct { + in []int + k int + want int } func TestLargestSumAfterKNegations(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{4, 2, 3}, - k: 1, - expected: 5, + in: []int{4, 2, 3}, + k: 1, + want: 5, }, { - input: []int{3, -1, 0, 2}, - k: 3, - expected: 6, + in: []int{3, -1, 0, 2}, + k: 3, + want: 6, }, { - input: []int{2, -3, -1, 5, -4}, - k: 2, - expected: 13, + in: []int{2, -3, -1, 5, -4}, + k: 2, + want: 13, }, } - for _, tc := range tests { - output := largestSumAfterKNegations(tc.input, tc.k) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := largestSumAfterKNegations(tt.in, tt.k) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/maximum-average-subarray-i/maximum_average_subarray_i_test.go b/problems/maximum-average-subarray-i/maximum_average_subarray_i_test.go index b278af3ef..17738a5fe 100644 --- a/problems/maximum-average-subarray-i/maximum_average_subarray_i_test.go +++ b/problems/maximum-average-subarray-i/maximum_average_subarray_i_test.go @@ -2,24 +2,24 @@ package problem643 import "testing" -type caseType struct { - nums []int - k int - expected float64 +type testType struct { + nums []int + k int + want float64 } func TestFindMaxAverage(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - nums: []int{1, 12, -5, -6, 50, 3}, - k: 4, - expected: 12.75, + nums: []int{1, 12, -5, -6, 50, 3}, + k: 4, + want: 12.75, }, } - for _, tc := range tests { - output := findMaxAverage(tc.nums, tc.k) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.nums, tc.k, output, tc.expected) + for _, tt := range tests { + got := findMaxAverage(tt.nums, tt.k) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.nums, tt.k, got, tt.want) } } } diff --git a/problems/maximum-depth-of-binary-tree/maximum_depth_of_binary_tree_test.go b/problems/maximum-depth-of-binary-tree/maximum_depth_of_binary_tree_test.go index da2787c5c..ec8b137c6 100644 --- a/problems/maximum-depth-of-binary-tree/maximum_depth_of_binary_tree_test.go +++ b/problems/maximum-depth-of-binary-tree/maximum_depth_of_binary_tree_test.go @@ -6,34 +6,34 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestMaxDepth(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{3, 9, 20, kit.NULL, kit.NULL, 15, 7}, - expected: 3, + in: []int{3, 9, 20, kit.NULL, kit.NULL, 15, 7}, + want: 3, }, { - input: []int{1, 2, 3, kit.NULL, 5, 6}, - expected: 3, + in: []int{1, 2, 3, kit.NULL, 5, 6}, + want: 3, }, { - input: []int{1, 2, kit.NULL, kit.NULL, 5}, - expected: 3, + in: []int{1, 2, kit.NULL, kit.NULL, 5}, + want: 3, }, { - input: []int{1, kit.NULL, 3, kit.NULL, 5}, - expected: 3, + in: []int{1, kit.NULL, 3, kit.NULL, 5}, + want: 3, }, } - for _, tc := range tests { - output := maxDepth(kit.SliceInt2TreeNode(tc.input)) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := maxDepth(kit.SliceInt2TreeNode(tt.in)) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/maximum-number-of-balloons/maximum_number_of_balloons_test.go b/problems/maximum-number-of-balloons/maximum_number_of_balloons_test.go index aeed1f9e4..14206e51b 100644 --- a/problems/maximum-number-of-balloons/maximum_number_of_balloons_test.go +++ b/problems/maximum-number-of-balloons/maximum_number_of_balloons_test.go @@ -2,34 +2,34 @@ package problem1189 import "testing" -type caseType struct { - input string - expected int +type testType struct { + in string + want int } func TestMaxNumberOfBalloons(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "nlaebolko", - expected: 1, + in: "nlaebolko", + want: 1, }, { - input: "loonbalxballpoon", - expected: 2, + in: "loonbalxballpoon", + want: 2, }, { - input: "leetcode", - expected: 0, + in: "leetcode", + want: 0, }, { - input: "lloo", - expected: 0, + in: "lloo", + want: 0, }, } - for _, tc := range tests { - output := maxNumberOfBalloons(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := maxNumberOfBalloons(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/maximum-product-of-three-numbers/maximum_product_of_three_numbers_test.go b/problems/maximum-product-of-three-numbers/maximum_product_of_three_numbers_test.go index c2f56e203..546f836ac 100644 --- a/problems/maximum-product-of-three-numbers/maximum_product_of_three_numbers_test.go +++ b/problems/maximum-product-of-three-numbers/maximum_product_of_three_numbers_test.go @@ -2,34 +2,34 @@ package problem628 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestMaximumProduct(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 3}, - expected: 6, + in: []int{1, 2, 3}, + want: 6, }, { - input: []int{1, 2, 3, 4}, - expected: 24, + in: []int{1, 2, 3, 4}, + want: 24, }, { - input: []int{-2, -1, 0, 2, 3}, - expected: 6, + in: []int{-2, -1, 0, 2, 3}, + want: 6, }, { - input: []int{-1, -2, -3, 5, 4, 3, 2, 1}, - expected: 60, + in: []int{-1, -2, -3, 5, 4, 3, 2, 1}, + want: 60, }, } - for _, tc := range tests { - output := maximumProduct(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := maximumProduct(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/maximum-subarray/maximum_subarray_test.go b/problems/maximum-subarray/maximum_subarray_test.go index 4e5859d52..d57167732 100644 --- a/problems/maximum-subarray/maximum_subarray_test.go +++ b/problems/maximum-subarray/maximum_subarray_test.go @@ -2,22 +2,22 @@ package problem53 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestMaxSubArray(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{-2, 1, -3, 4, -1, 2, 1, -5, 4}, - expected: 6, + in: []int{-2, 1, -3, 4, -1, 2, 1, -5, 4}, + want: 6, }, } - for _, tc := range tests { - output := maxSubArray(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := maxSubArray(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/median-of-two-sorted-arrays/median_of_two_sorted_arrays_test.go b/problems/median-of-two-sorted-arrays/median_of_two_sorted_arrays_test.go index 79b74dbab..6bc60dc53 100644 --- a/problems/median-of-two-sorted-arrays/median_of_two_sorted_arrays_test.go +++ b/problems/median-of-two-sorted-arrays/median_of_two_sorted_arrays_test.go @@ -2,80 +2,80 @@ package problem4 import "testing" -type caseType struct { - num1 []int - num2 []int - expected float64 +type testType struct { + num1 []int + num2 []int + want float64 } func TestFindMedianSortedArrays(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - num1: []int{1, 3}, - num2: []int{2}, - expected: 2.0, + num1: []int{1, 3}, + num2: []int{2}, + want: 2.0, }, { - num1: []int{1, 2}, - num2: []int{3, 4}, - expected: 2.5, + num1: []int{1, 2}, + num2: []int{3, 4}, + want: 2.5, }, { - num1: []int{1, 3, 5, 7}, - num2: []int{2, 4}, - expected: 3.5, + num1: []int{1, 3, 5, 7}, + num2: []int{2, 4}, + want: 3.5, }, { - num1: []int{1, 3, 5}, - num2: []int{}, - expected: 3, + num1: []int{1, 3, 5}, + num2: []int{}, + want: 3, }, { - num1: []int{1, 2}, - num2: []int{3}, - expected: 2, + num1: []int{1, 2}, + num2: []int{3}, + want: 2, }, { - num1: []int{1, 1}, - num2: []int{1, 1}, - expected: 1, + num1: []int{1, 1}, + num2: []int{1, 1}, + want: 1, }, { - num1: []int{1, 1, 1}, - num2: []int{1, 1}, - expected: 1, + num1: []int{1, 1, 1}, + num2: []int{1, 1}, + want: 1, }, { - num1: []int{1, 1}, - num2: []int{1, 1, 1}, - expected: 1, + num1: []int{1, 1}, + num2: []int{1, 1, 1}, + want: 1, }, { - num1: []int{1}, - num2: []int{2, 3, 4}, - expected: 2.5, + num1: []int{1}, + num2: []int{2, 3, 4}, + want: 2.5, }, { - num1: []int{2, 3, 4}, - num2: []int{1}, - expected: 2.5, + num1: []int{2, 3, 4}, + num2: []int{1}, + want: 2.5, }, { - num1: []int{}, - num2: []int{1}, - expected: 1, + num1: []int{}, + num2: []int{1}, + want: 1, }, { - num1: []int{}, - num2: []int{1, 1}, - expected: 1, + num1: []int{}, + num2: []int{1, 1}, + want: 1, }, } - for _, tc := range tests { - output := findMedianSortedArrays(tc.num1, tc.num2) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.num1, tc.num2, output, tc.expected) + for _, tt := range tests { + got := findMedianSortedArrays(tt.num1, tt.num2) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.num1, tt.num2, got, tt.want) } } } diff --git a/problems/merge-sorted-array/merge_sorted_array_test.go b/problems/merge-sorted-array/merge_sorted_array_test.go index d51558a8a..95dd0667d 100644 --- a/problems/merge-sorted-array/merge_sorted_array_test.go +++ b/problems/merge-sorted-array/merge_sorted_array_test.go @@ -5,42 +5,42 @@ import ( "testing" ) -type caseType struct { - nums1 []int - m int - nums2 []int - n int - expected []int +type testType struct { + nums1 []int + m int + nums2 []int + n int + want []int } func TestMerge(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - nums1: []int{1, 2, 3, 0, 0, 0}, - m: 3, - nums2: []int{2, 5, 6}, - n: 3, - expected: []int{1, 2, 2, 3, 5, 6}, + nums1: []int{1, 2, 3, 0, 0, 0}, + m: 3, + nums2: []int{2, 5, 6}, + n: 3, + want: []int{1, 2, 2, 3, 5, 6}, }, { - nums1: []int{-9, -6, -3, 0, 0, 0}, - m: 3, - nums2: []int{-7, -5, -3}, - n: 3, - expected: []int{-9, -7, -6, -5, -3, -3}, + nums1: []int{-9, -6, -3, 0, 0, 0}, + m: 3, + nums2: []int{-7, -5, -3}, + n: 3, + want: []int{-9, -7, -6, -5, -3, -3}, }, { - nums1: []int{1, 2, 4, 5, 6, 0}, - m: 5, - nums2: []int{3}, - n: 1, - expected: []int{1, 2, 3, 4, 5, 6}, + nums1: []int{1, 2, 4, 5, 6, 0}, + m: 5, + nums2: []int{3}, + n: 1, + want: []int{1, 2, 3, 4, 5, 6}, }, } - for _, tc := range tests { - merge(tc.nums1, tc.m, tc.nums2, tc.n) - if !reflect.DeepEqual(tc.nums1, tc.expected) { - t.Fatalf("input: %v %v %v %v, output: %v, expected: %v", tc.nums1, tc.m, tc.nums2, tc.n, tc.nums1, tc.expected) + for _, tt := range tests { + merge(tt.nums1, tt.m, tt.nums2, tt.n) + if !reflect.DeepEqual(tt.nums1, tt.want) { + t.Fatalf("in: %v %v %v %v, got: %v, want: %v", tt.nums1, tt.m, tt.nums2, tt.n, tt.nums1, tt.want) } } } diff --git a/problems/merge-two-binary-trees/merge_two_binary_trees_test.go b/problems/merge-two-binary-trees/merge_two_binary_trees_test.go index 8f7287886..c7795e8f4 100644 --- a/problems/merge-two-binary-trees/merge_two_binary_trees_test.go +++ b/problems/merge-two-binary-trees/merge_two_binary_trees_test.go @@ -7,25 +7,25 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - t1 []int - t2 []int - expected []int +type testType struct { + t1 []int + t2 []int + want []int } func TestMergeTrees(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - t1: []int{1, 3, 2, 5}, - t2: []int{2, 1, 3, kit.NULL, 4, kit.NULL, 7}, - expected: []int{3, 4, 5, 5, 4, kit.NULL, 7}, + t1: []int{1, 3, 2, 5}, + t2: []int{2, 1, 3, kit.NULL, 4, kit.NULL, 7}, + want: []int{3, 4, 5, 5, 4, kit.NULL, 7}, }, } - for _, tc := range tests { - t3 := mergeTrees(kit.SliceInt2TreeNode(tc.t1), kit.SliceInt2TreeNode(tc.t2)) - output := kit.TreeNode2SliceInt(t3) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.t1, tc.t2, output, tc.expected) + for _, tt := range tests { + t3 := mergeTrees(kit.SliceInt2TreeNode(tt.t1), kit.SliceInt2TreeNode(tt.t2)) + got := kit.TreeNode2SliceInt(t3) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.t1, tt.t2, got, tt.want) } } } diff --git a/problems/merge-two-sorted-lists/merge_two_sorted_lists_test.go b/problems/merge-two-sorted-lists/merge_two_sorted_lists_test.go index 19dcbe256..905fe5fd2 100644 --- a/problems/merge-two-sorted-lists/merge_two_sorted_lists_test.go +++ b/problems/merge-two-sorted-lists/merge_two_sorted_lists_test.go @@ -7,46 +7,46 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - l1 []int - l2 []int - expected []int +type testType struct { + l1 []int + l2 []int + want []int } func TestMergeTwoLists(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - l1: []int{1, 2, 4}, - l2: []int{1, 3, 4}, - expected: []int{1, 1, 2, 3, 4, 4}, + l1: []int{1, 2, 4}, + l2: []int{1, 3, 4}, + want: []int{1, 1, 2, 3, 4, 4}, }, { - l1: nil, - l2: nil, - expected: nil, + l1: nil, + l2: nil, + want: nil, }, { - l1: nil, - l2: []int{1, 2, 3}, - expected: []int{1, 2, 3}, + l1: nil, + l2: []int{1, 2, 3}, + want: []int{1, 2, 3}, }, { - l1: []int{1, 2, 3}, - l2: nil, - expected: []int{1, 2, 3}, + l1: []int{1, 2, 3}, + l2: nil, + want: []int{1, 2, 3}, }, { - l1: []int{1, 2, 3, 8, 16}, - l2: []int{1, 2, 3, 10, 12, 24}, - expected: []int{1, 1, 2, 2, 3, 3, 8, 10, 12, 16, 24}, + l1: []int{1, 2, 3, 8, 16}, + l2: []int{1, 2, 3, 10, 12, 24}, + want: []int{1, 1, 2, 2, 3, 3, 8, 10, 12, 16, 24}, }, } - for _, tc := range tests { - l1 := kit.SliceInt2ListNode(tc.l1) - l2 := kit.SliceInt2ListNode(tc.l2) - output := kit.ListNode2SliceInt(mergeTwoLists(l1, l2)) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.l1, tc.l2, output, tc.expected) + for _, tt := range tests { + l1 := kit.SliceInt2ListNode(tt.l1) + l2 := kit.SliceInt2ListNode(tt.l2) + got := kit.ListNode2SliceInt(mergeTwoLists(l1, l2)) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.l1, tt.l2, got, tt.want) } } } diff --git a/problems/min-cost-climbing-stairs/min_cost_climbing_stairs_test.go b/problems/min-cost-climbing-stairs/min_cost_climbing_stairs_test.go index a6c2f5f96..37d4e96a5 100644 --- a/problems/min-cost-climbing-stairs/min_cost_climbing_stairs_test.go +++ b/problems/min-cost-climbing-stairs/min_cost_climbing_stairs_test.go @@ -2,26 +2,26 @@ package problem746 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestMinCostClimbingStairs(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{10, 15, 20}, - expected: 15, + in: []int{10, 15, 20}, + want: 15, }, { - input: []int{1, 100, 1, 1, 1, 100, 1, 1, 100, 1}, - expected: 6, + in: []int{1, 100, 1, 1, 1, 100, 1, 1, 100, 1}, + want: 6, }, } - for _, tc := range tests { - output := minCostClimbingStairs(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := minCostClimbingStairs(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/min-stack/min_stack_test.go b/problems/min-stack/min_stack_test.go index 7fa89135d..27d60ea1b 100644 --- a/problems/min-stack/min_stack_test.go +++ b/problems/min-stack/min_stack_test.go @@ -5,29 +5,29 @@ import ( "testing" ) -type caseType struct { - input []int - expected []int +type testType struct { + in []int + want []int } func TestMinStack(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{-2, 0, -3}, - expected: []int{-3, 0, -2}, + in: []int{-2, 0, -3}, + want: []int{-3, 0, -2}, }, } - for _, tc := range tests { - minStack, output := Constructor(), make([]int, 0) - for _, x := range tc.input { + for _, tt := range tests { + minStack, got := Constructor(), make([]int, 0) + for _, x := range tt.in { minStack.Push(x) } - output = append(output, minStack.GetMin()) + got = append(got, minStack.GetMin()) minStack.Pop() - output = append(output, minStack.Top()) - output = append(output, minStack.GetMin()) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + got = append(got, minStack.Top()) + got = append(got, minStack.GetMin()) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/missing-number/missing_number_test.go b/problems/missing-number/missing_number_test.go index 519e32bd3..267263af2 100644 --- a/problems/missing-number/missing_number_test.go +++ b/problems/missing-number/missing_number_test.go @@ -2,30 +2,30 @@ package problem268 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestMissingNumber(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{3, 0, 1}, - expected: 2, + in: []int{3, 0, 1}, + want: 2, }, { - input: []int{0, 1, 2, 4, 5, 6}, - expected: 3, + in: []int{0, 1, 2, 4, 5, 6}, + want: 3, }, { - input: []int{9, 6, 4, 2, 3, 5, 7, 0, 1}, - expected: 8, + in: []int{9, 6, 4, 2, 3, 5, 7, 0, 1}, + want: 8, }, } - for _, tc := range tests { - output := missingNumber(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := missingNumber(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/monotonic-array/monotonic_array_test.go b/problems/monotonic-array/monotonic_array_test.go index c9ec551de..05de2c01d 100644 --- a/problems/monotonic-array/monotonic_array_test.go +++ b/problems/monotonic-array/monotonic_array_test.go @@ -2,42 +2,42 @@ package problem896 import "testing" -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestIsMonotonic(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 2, 3}, - expected: true, + in: []int{1, 2, 2, 3}, + want: true, }, { - input: []int{6, 5, 4, 4}, - expected: true, + in: []int{6, 5, 4, 4}, + want: true, }, { - input: []int{1, 3, 2}, - expected: false, + in: []int{1, 3, 2}, + want: false, }, { - input: []int{1, 2, 4, 5}, - expected: true, + in: []int{1, 2, 4, 5}, + want: true, }, { - input: []int{1, 1, 1}, - expected: true, + in: []int{1, 1, 1}, + want: true, }, { - input: []int{1, 2, 3, 3, 3, 2, 1}, - expected: false, + in: []int{1, 2, 3, 3, 3, 2, 1}, + want: false, }, } - for _, tc := range tests { - output := isMonotonic(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isMonotonic(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/most-common-word/most_common_word_test.go b/problems/most-common-word/most_common_word_test.go index 8832d8bf7..25437752f 100644 --- a/problems/most-common-word/most_common_word_test.go +++ b/problems/most-common-word/most_common_word_test.go @@ -2,34 +2,34 @@ package problem819 import "testing" -type caseType struct { +type testType struct { paragraph string banned []string - expected string + want string } func TestMostCommonWord(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { paragraph: "Bob hit a ball, the hit BALL flew far after it was hit.", banned: []string{"hit"}, - expected: "ball", + want: "ball", }, { paragraph: "a, a, a, a, b,b,b,c, c", banned: []string{"a"}, - expected: "b", + want: "b", }, { paragraph: "Bob", banned: []string{}, - expected: "bob", + want: "bob", }, } - for _, tc := range tests { - output := mostCommonWord(tc.paragraph, tc.banned) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.paragraph, tc.banned, output, tc.expected) + for _, tt := range tests { + got := mostCommonWord(tt.paragraph, tt.banned) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.paragraph, tt.banned, got, tt.want) } } } diff --git a/problems/move-zeroes/move_zeroes_test.go b/problems/move-zeroes/move_zeroes_test.go index fd97332d9..56f5ea626 100644 --- a/problems/move-zeroes/move_zeroes_test.go +++ b/problems/move-zeroes/move_zeroes_test.go @@ -5,33 +5,33 @@ import ( "testing" ) -type caseType struct { - input []int - expected []int +type testType struct { + in []int + want []int } func TestMoveZeroes(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{0, 1, 0, 3, 12}, - expected: []int{1, 3, 12, 0, 0}, + in: []int{0, 1, 0, 3, 12}, + want: []int{1, 3, 12, 0, 0}, }, { - input: []int{0, 1, 0, 2, 3, 3, 0, 7, 8}, - expected: []int{1, 2, 3, 3, 7, 8, 0, 0, 0}, + in: []int{0, 1, 0, 2, 3, 3, 0, 7, 8}, + want: []int{1, 2, 3, 3, 7, 8, 0, 0, 0}, }, { - input: []int{1, 2, 3, 4, 5}, - expected: []int{1, 2, 3, 4, 5}, + in: []int{1, 2, 3, 4, 5}, + want: []int{1, 2, 3, 4, 5}, }, } - for _, tc := range tests { - output := make([]int, len(tc.input)) - copy(output, tc.input) - moveZeroes(output) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := make([]int, len(tt.in)) + copy(got, tt.in) + moveZeroes(got) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/n-repeated-element-in-size-2n-array/n_repeated_element_in_size_2n_array_test.go b/problems/n-repeated-element-in-size-2n-array/n_repeated_element_in_size_2n_array_test.go index fb07fe5f7..5c0aa5bed 100644 --- a/problems/n-repeated-element-in-size-2n-array/n_repeated_element_in_size_2n_array_test.go +++ b/problems/n-repeated-element-in-size-2n-array/n_repeated_element_in_size_2n_array_test.go @@ -2,35 +2,35 @@ package problem961 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestRepeatedNTimes(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 3, 3}, - expected: 3, + in: []int{1, 2, 3, 3}, + want: 3, }, { - input: []int{2, 1, 2, 5, 3, 2}, - expected: 2, + in: []int{2, 1, 2, 5, 3, 2}, + want: 2, }, { - input: []int{5, 1, 5, 2, 5, 3, 5, 4}, - expected: 5, + in: []int{5, 1, 5, 2, 5, 3, 5, 4}, + want: 5, }, { - input: []int{1, 2, 3}, - expected: 0, + in: []int{1, 2, 3}, + want: 0, }, } - for _, tc := range tests { - output := repeatedNTimes(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := repeatedNTimes(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/nim-game/nim_game_test.go b/problems/nim-game/nim_game_test.go index 5a649e2da..acd719a48 100644 --- a/problems/nim-game/nim_game_test.go +++ b/problems/nim-game/nim_game_test.go @@ -2,26 +2,26 @@ package problem292 import "testing" -type caseType struct { - input int - expected bool +type testType struct { + in int + want bool } func TestCanWinNim(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 4, - expected: false, + in: 4, + want: false, }, { - input: 3, - expected: true, + in: 3, + want: true, }, } - for _, tc := range tests { - output := canWinNim(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := canWinNim(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/non-decreasing-array/non_decreasing_array_test.go b/problems/non-decreasing-array/non_decreasing_array_test.go index 5cdd4f8c5..cb03c1529 100644 --- a/problems/non-decreasing-array/non_decreasing_array_test.go +++ b/problems/non-decreasing-array/non_decreasing_array_test.go @@ -2,38 +2,38 @@ package problem665 import "testing" -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestCheckPossibility(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{3, 2, 5}, - expected: true, + in: []int{3, 2, 5}, + want: true, }, { - input: []int{3, 2, 1}, - expected: false, + in: []int{3, 2, 1}, + want: false, }, { - input: []int{3, 4, 2, 3}, - expected: false, + in: []int{3, 4, 2, 3}, + want: false, }, { - input: []int{1, 2, 3, 7, 5, 6}, - expected: true, + in: []int{1, 2, 3, 7, 5, 6}, + want: true, }, { - input: []int{1, 2, 3, 7, 1, 9}, - expected: true, + in: []int{1, 2, 3, 7, 1, 9}, + want: true, }, } - for _, tc := range tests { - output := checkPossibility(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := checkPossibility(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/number-of-1-bits/number_of_1_bits_test.go b/problems/number-of-1-bits/number_of_1_bits_test.go index bb842e441..ead22f4c4 100644 --- a/problems/number-of-1-bits/number_of_1_bits_test.go +++ b/problems/number-of-1-bits/number_of_1_bits_test.go @@ -2,34 +2,34 @@ package problem191 import "testing" -type caseType struct { - input uint32 - expected int +type testType struct { + in uint32 + want int } func TestHammingWeight(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 3, - expected: 2, + in: 3, + want: 2, }, { - input: 7, - expected: 3, + in: 7, + want: 3, }, { - input: 8, - expected: 1, + in: 8, + want: 1, }, { - input: 0x5555, - expected: 8, + in: 0x5555, + want: 8, }, } - for _, tc := range tests { - output := hammingWeight(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := hammingWeight(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/number-of-digit-one/number_of_digit_one_test.go b/problems/number-of-digit-one/number_of_digit_one_test.go index d1cadac4c..7ee2365cb 100644 --- a/problems/number-of-digit-one/number_of_digit_one_test.go +++ b/problems/number-of-digit-one/number_of_digit_one_test.go @@ -2,66 +2,66 @@ package problem233 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestCountDigitOne(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 0, - expected: 0, + in: 0, + want: 0, }, { - input: 1, - expected: 1, + in: 1, + want: 1, }, { - input: 12, - expected: 5, + in: 12, + want: 5, }, { - input: 99, - expected: 20, + in: 99, + want: 20, }, { - input: 100, - expected: 21, + in: 100, + want: 21, }, { - input: 123, - expected: 57, + in: 123, + want: 57, }, { - input: 1234, - expected: 689, + in: 1234, + want: 689, }, { - input: 12345, - expected: 8121, + in: 12345, + want: 8121, }, { - input: 123456, - expected: 93553, + in: 123456, + want: 93553, }, { - input: 1234567, - expected: 1058985, + in: 1234567, + want: 1058985, }, { - input: 12345678, - expected: 11824417, + in: 12345678, + want: 11824417, }, { - input: 123456789, - expected: 130589849, + in: 123456789, + want: 130589849, }, } - for _, tc := range tests { - output := countDigitOne(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := countDigitOne(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/number-of-recent-calls/number_of_recent_calls_test.go b/problems/number-of-recent-calls/number_of_recent_calls_test.go index 553dcbabc..8cee8bc23 100644 --- a/problems/number-of-recent-calls/number_of_recent_calls_test.go +++ b/problems/number-of-recent-calls/number_of_recent_calls_test.go @@ -5,25 +5,25 @@ import ( "testing" ) -type caseType struct { - input []int - expected []int +type testType struct { + in []int + want []int } func TestConstructor(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 100, 3001, 3002}, - expected: []int{1, 2, 3, 3}, + in: []int{1, 100, 3001, 3002}, + want: []int{1, 2, 3, 3}, }, } - for _, tc := range tests { - obj, output := Constructor(), make([]int, 0) - for _, t := range tc.input { - output = append(output, obj.Ping(t)) + for _, tt := range tests { + obj, got := Constructor(), make([]int, 0) + for _, t := range tt.in { + got = append(got, obj.Ping(t)) } - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/number-of-segments-in-a-string/number_of_segments_in_a_string_test.go b/problems/number-of-segments-in-a-string/number_of_segments_in_a_string_test.go index a7f8e9083..eeb8bdd01 100644 --- a/problems/number-of-segments-in-a-string/number_of_segments_in_a_string_test.go +++ b/problems/number-of-segments-in-a-string/number_of_segments_in_a_string_test.go @@ -2,42 +2,42 @@ package problem434 import "testing" -type caseType struct { - input string - expected int +type testType struct { + in string + want int } func TestCountSegments(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "Hello, my name is John", - expected: 5, + in: "Hello, my name is John", + want: 5, }, { - input: "", - expected: 0, + in: "", + want: 0, }, { - input: " ", - expected: 0, + in: " ", + want: 0, }, { - input: " abc ", - expected: 1, + in: " abc ", + want: 1, }, { - input: " abc def ", - expected: 2, + in: " abc def ", + want: 2, }, { - input: "love live! mu'sic forever", - expected: 4, + in: "love live! mu'sic forever", + want: 4, }, } - for _, tc := range tests { - output := countSegments(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := countSegments(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/pairs-of-songs-with-total-durations-divisible-by-60/pairs_of_songs_with_total_durations_divisible_by_60_test.go b/problems/pairs-of-songs-with-total-durations-divisible-by-60/pairs_of_songs_with_total_durations_divisible_by_60_test.go index 0c5cb8a4e..15c675a6d 100644 --- a/problems/pairs-of-songs-with-total-durations-divisible-by-60/pairs_of_songs_with_total_durations_divisible_by_60_test.go +++ b/problems/pairs-of-songs-with-total-durations-divisible-by-60/pairs_of_songs_with_total_durations_divisible_by_60_test.go @@ -2,26 +2,26 @@ package problem1010 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestNumPairsDivisibleBy60(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{30, 20, 150, 100, 40}, - expected: 3, + in: []int{30, 20, 150, 100, 40}, + want: 3, }, { - input: []int{60, 60, 60}, - expected: 3, + in: []int{60, 60, 60}, + want: 3, }, } - for _, tc := range tests { - output := numPairsDivisibleBy60(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := numPairsDivisibleBy60(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/palindrome-linked-list/palindrome_linked_list_test.go b/problems/palindrome-linked-list/palindrome_linked_list_test.go index f279a0319..baac89617 100644 --- a/problems/palindrome-linked-list/palindrome_linked_list_test.go +++ b/problems/palindrome-linked-list/palindrome_linked_list_test.go @@ -6,30 +6,30 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestIsPalindrome(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2}, - expected: false, + in: []int{1, 2}, + want: false, }, { - input: []int{1, 2, 1}, - expected: true, + in: []int{1, 2, 1}, + want: true, }, { - input: []int{1, 2, 2, 1}, - expected: true, + in: []int{1, 2, 2, 1}, + want: true, }, } - for _, tc := range tests { - output := isPalindrome(kit.SliceInt2ListNode(tc.input)) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isPalindrome(kit.SliceInt2ListNode(tt.in)) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/palindrome-number/palindrome_number_test.go b/problems/palindrome-number/palindrome_number_test.go index 4ca77860c..67de9186b 100644 --- a/problems/palindrome-number/palindrome_number_test.go +++ b/problems/palindrome-number/palindrome_number_test.go @@ -18,10 +18,10 @@ func TestIsPalindrome(t *testing.T) { math.MaxInt32: false, } - for input, expected := range tests { - output := isPalindrome(input) - if output != expected { - t.Fatalf("input: %v, output: %v, expected: %v", input, output, expected) + for in, want := range tests { + got := isPalindrome(in) + if got != want { + t.Fatalf("in: %v, got: %v, want: %v", in, got, want) } } } diff --git a/problems/partition-array-into-three-parts-with-equal-sum/partition_array_into_three_parts_with_equal_sum_test.go b/problems/partition-array-into-three-parts-with-equal-sum/partition_array_into_three_parts_with_equal_sum_test.go index 57912dfbd..ff9546982 100644 --- a/problems/partition-array-into-three-parts-with-equal-sum/partition_array_into_three_parts_with_equal_sum_test.go +++ b/problems/partition-array-into-three-parts-with-equal-sum/partition_array_into_three_parts_with_equal_sum_test.go @@ -2,38 +2,38 @@ package problem1013 import "testing" -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestCanThreePartsEqualSum(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{0, 2, 1, -6, 6, -7, 9, 1, 2, 0, 1}, - expected: true, + in: []int{0, 2, 1, -6, 6, -7, 9, 1, 2, 0, 1}, + want: true, }, { - input: []int{0, 2, 1, -6, 6, 7, 9, -1, 2, 0, 1}, - expected: false, + in: []int{0, 2, 1, -6, 6, 7, 9, -1, 2, 0, 1}, + want: false, }, { - input: []int{3, 3, 6, 5, -2, 2, 5, 1, -9, 4}, - expected: true, + in: []int{3, 3, 6, 5, -2, 2, 5, 1, -9, 4}, + want: true, }, { - input: []int{-3, 3, 3, -3}, - expected: false, + in: []int{-3, 3, 3, -3}, + want: false, }, { - input: []int{1, 7, 2, 6, 3, 5, 8}, - expected: false, + in: []int{1, 7, 2, 6, 3, 5, 8}, + want: false, }, } - for _, tc := range tests { - output := canThreePartsEqualSum(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := canThreePartsEqualSum(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/pascals-triangle-ii/pascals_triangle_ii_test.go b/problems/pascals-triangle-ii/pascals_triangle_ii_test.go index 31a65a695..1e39cb1eb 100644 --- a/problems/pascals-triangle-ii/pascals_triangle_ii_test.go +++ b/problems/pascals-triangle-ii/pascals_triangle_ii_test.go @@ -5,30 +5,30 @@ import ( "testing" ) -type caseType struct { - input int - expected []int +type testType struct { + in int + want []int } func TestGetRow(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 2, - expected: []int{1, 2, 1}, + in: 2, + want: []int{1, 2, 1}, }, { - input: 3, - expected: []int{1, 3, 3, 1}, + in: 3, + want: []int{1, 3, 3, 1}, }, { - input: 5, - expected: []int{1, 5, 10, 10, 5, 1}, + in: 5, + want: []int{1, 5, 10, 10, 5, 1}, }, } - for _, tc := range tests { - output := getRow(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := getRow(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/pascals-triangle/pascals_triangle_test.go b/problems/pascals-triangle/pascals_triangle_test.go index 2e99f50fa..7dc90f988 100644 --- a/problems/pascals-triangle/pascals_triangle_test.go +++ b/problems/pascals-triangle/pascals_triangle_test.go @@ -5,16 +5,16 @@ import ( "testing" ) -type caseType struct { - input int - expected [][]int +type testType struct { + in int + want [][]int } func TestGenerate(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 5, - expected: [][]int{ + in: 5, + want: [][]int{ {1}, {1, 1}, {1, 2, 1}, @@ -23,10 +23,10 @@ func TestGenerate(t *testing.T) { }, }, } - for _, tc := range tests { - output := generate(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := generate(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/plus-one/plus_one_test.go b/problems/plus-one/plus_one_test.go index 93e4139e4..9f1786863 100644 --- a/problems/plus-one/plus_one_test.go +++ b/problems/plus-one/plus_one_test.go @@ -5,35 +5,35 @@ import ( "testing" ) -type caseType struct { - input []int - expected []int +type testType struct { + in []int + want []int } func TestPlusOne(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 3}, - expected: []int{1, 2, 4}, + in: []int{1, 2, 3}, + want: []int{1, 2, 4}, }, { - input: []int{4, 3, 2, 1}, - expected: []int{4, 3, 2, 2}, + in: []int{4, 3, 2, 1}, + want: []int{4, 3, 2, 2}, }, { - input: []int{1, 2, 9, 9}, - expected: []int{1, 3, 0, 0}, + in: []int{1, 2, 9, 9}, + want: []int{1, 3, 0, 0}, }, { - input: []int{9, 9}, - expected: []int{1, 0, 0}, + in: []int{9, 9}, + want: []int{1, 0, 0}, }, } - for _, tc := range tests { - output := plusOne(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := plusOne(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/positions-of-large-groups/positions_of_large_groups_test.go b/problems/positions-of-large-groups/positions_of_large_groups_test.go index 0cb8fd72c..428224777 100644 --- a/problems/positions-of-large-groups/positions_of_large_groups_test.go +++ b/problems/positions-of-large-groups/positions_of_large_groups_test.go @@ -5,42 +5,42 @@ import ( "testing" ) -type caseType struct { - input string - expected [][]int +type testType struct { + in string + want [][]int } func TestLargeGroupPositions(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "abbxxxxzzy", - expected: [][]int{ + in: "abbxxxxzzy", + want: [][]int{ {3, 6}, }, }, { - input: "abc", - expected: [][]int{}, + in: "abc", + want: [][]int{}, }, { - input: "abcdddeeeeaabbbcd", - expected: [][]int{ + in: "abcdddeeeeaabbbcd", + want: [][]int{ {3, 5}, {6, 9}, {12, 14}, }, }, { - input: "abcddd", - expected: [][]int{ + in: "abcddd", + want: [][]int{ {3, 5}, }, }, } - for _, tc := range tests { - output := largeGroupPositions(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := largeGroupPositions(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/power-of-four/power_of_four_test.go b/problems/power-of-four/power_of_four_test.go index 3601045ba..aaaa15ddf 100644 --- a/problems/power-of-four/power_of_four_test.go +++ b/problems/power-of-four/power_of_four_test.go @@ -2,42 +2,42 @@ package problem342 import "testing" -type caseType struct { - input int - expected bool +type testType struct { + in int + want bool } func TestIsPowerOfFour(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 16, - expected: true, + in: 16, + want: true, }, { - input: 5, - expected: false, + in: 5, + want: false, }, { - input: 6, - expected: false, + in: 6, + want: false, }, { - input: 12, - expected: false, + in: 12, + want: false, }, { - input: 0, - expected: false, + in: 0, + want: false, }, { - input: 1, - expected: true, + in: 1, + want: true, }, } - for _, tc := range tests { - output := isPowerOfFour(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isPowerOfFour(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/power-of-three/power_of_three_test.go b/problems/power-of-three/power_of_three_test.go index a1d2363a9..b889dfde8 100644 --- a/problems/power-of-three/power_of_three_test.go +++ b/problems/power-of-three/power_of_three_test.go @@ -2,38 +2,38 @@ package problem326 import "testing" -type caseType struct { - input int - expected bool +type testType struct { + in int + want bool } func TestIsPowerOfThree(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 27, - expected: true, + in: 27, + want: true, }, { - input: 0, - expected: false, + in: 0, + want: false, }, { - input: 1, - expected: true, + in: 1, + want: true, }, { - input: 9, - expected: true, + in: 9, + want: true, }, { - input: 45, - expected: false, + in: 45, + want: false, }, } - for _, tc := range tests { - output := isPowerOfThree(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isPowerOfThree(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/power-of-two/power_of_two_test.go b/problems/power-of-two/power_of_two_test.go index b664515f5..dce162355 100644 --- a/problems/power-of-two/power_of_two_test.go +++ b/problems/power-of-two/power_of_two_test.go @@ -2,38 +2,38 @@ package problem231 import "testing" -type caseType struct { - input int - expected bool +type testType struct { + in int + want bool } func TestIsPowerOfTwo(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 0, - expected: false, + in: 0, + want: false, }, { - input: 1, - expected: true, + in: 1, + want: true, }, { - input: 12, - expected: false, + in: 12, + want: false, }, { - input: 16, - expected: true, + in: 16, + want: true, }, { - input: 218, - expected: false, + in: 218, + want: false, }, } - for _, tc := range tests { - output := isPowerOfTwo(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isPowerOfTwo(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/powerful-integers/powerful_integers_test.go b/problems/powerful-integers/powerful_integers_test.go index ccd0ea49b..e1918818b 100644 --- a/problems/powerful-integers/powerful_integers_test.go +++ b/problems/powerful-integers/powerful_integers_test.go @@ -6,32 +6,32 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - x int - y int - bound int - expected []int +type testType struct { + x int + y int + bound int + want []int } func TestPowerfulIntegers(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - x: 2, - y: 3, - bound: 10, - expected: []int{2, 3, 4, 5, 7, 9, 10}, + x: 2, + y: 3, + bound: 10, + want: []int{2, 3, 4, 5, 7, 9, 10}, }, { - x: 3, - y: 5, - bound: 15, - expected: []int{2, 4, 6, 8, 10, 14}, + x: 3, + y: 5, + bound: 15, + want: []int{2, 4, 6, 8, 10, 14}, }, } - for _, tc := range tests { - output := powerfulIntegers(tc.x, tc.y, tc.bound) - if !kit.IsEqualSliceInt(output, tc.expected) { - t.Fatalf("input: %v %v %v, output: %v, expected: %v", tc.x, tc.y, tc.bound, output, tc.expected) + for _, tt := range tests { + got := powerfulIntegers(tt.x, tt.y, tt.bound) + if !kit.IsEqualSliceInt(got, tt.want) { + t.Fatalf("in: %v %v %v, got: %v, want: %v", tt.x, tt.y, tt.bound, got, tt.want) } } } diff --git a/problems/powx-n/powx_n_test.go b/problems/powx-n/powx_n_test.go index 8909c2576..52082d715 100644 --- a/problems/powx-n/powx_n_test.go +++ b/problems/powx-n/powx_n_test.go @@ -5,36 +5,36 @@ import ( "testing" ) -type caseType struct { - x float64 - n int - expected float64 +type testType struct { + x float64 + n int + want float64 } func TestMyPow(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - x: 2.00000, - n: 10, - expected: 1024.00000, + x: 2.00000, + n: 10, + want: 1024.00000, }, { - x: 2.10000, - n: 3, - expected: 9.26100, + x: 2.10000, + n: 3, + want: 9.26100, }, { - x: 2.00000, - n: -2, - expected: 0.25000, + x: 2.00000, + n: -2, + want: 0.25000, }, } - for _, tc := range tests { - output := myPow(tc.x, tc.n) - output = math.Trunc(output*1e5) / 1e5 - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.x, tc.n, output, tc.expected) + for _, tt := range tests { + got := myPow(tt.x, tt.n) + got = math.Trunc(got*1e5) / 1e5 + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.x, tt.n, got, tt.want) } } } diff --git a/problems/preimage-size-of-factorial-zeroes-function/preimage_size_of_factorial_zeroes_function_test.go b/problems/preimage-size-of-factorial-zeroes-function/preimage_size_of_factorial_zeroes_function_test.go index 05dfdb3a2..713f17821 100644 --- a/problems/preimage-size-of-factorial-zeroes-function/preimage_size_of_factorial_zeroes_function_test.go +++ b/problems/preimage-size-of-factorial-zeroes-function/preimage_size_of_factorial_zeroes_function_test.go @@ -2,34 +2,34 @@ package problem793 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestPreimageSizeFZF(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 0, - expected: 5, + in: 0, + want: 5, }, { - input: 5, - expected: 0, + in: 5, + want: 0, }, { - input: 17, - expected: 0, + in: 17, + want: 0, }, { - input: 11, - expected: 0, + in: 11, + want: 0, }, } - for _, tc := range tests { - output := preimageSizeFZF(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := preimageSizeFZF(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/range-sum-of-bst/range_sum_of_bst_test.go b/problems/range-sum-of-bst/range_sum_of_bst_test.go index 25ab12147..4636b6814 100644 --- a/problems/range-sum-of-bst/range_sum_of_bst_test.go +++ b/problems/range-sum-of-bst/range_sum_of_bst_test.go @@ -6,32 +6,32 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - l int - r int - expected int +type testType struct { + in []int + l int + r int + want int } func TestRangeSumBST(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{10, 5, 15, 3, 7, kit.NULL, 18}, - l: 7, - r: 15, - expected: 32, + in: []int{10, 5, 15, 3, 7, kit.NULL, 18}, + l: 7, + r: 15, + want: 32, }, { - input: []int{10, 5, 15, 3, 7, 13, 18, 1, kit.NULL, 6}, - l: 6, - r: 10, - expected: 23, + in: []int{10, 5, 15, 3, 7, 13, 18, 1, kit.NULL, 6}, + l: 6, + r: 10, + want: 23, }, } - for _, tc := range tests { - output := rangeSumBST(kit.SliceInt2TreeNode(tc.input), tc.l, tc.r) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := rangeSumBST(kit.SliceInt2TreeNode(tt.in), tt.l, tt.r) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/range-sum-query-immutable/range_sum_query_immutable_test.go b/problems/range-sum-query-immutable/range_sum_query_immutable_test.go index b6395bcb8..57c2a2e37 100644 --- a/problems/range-sum-query-immutable/range_sum_query_immutable_test.go +++ b/problems/range-sum-query-immutable/range_sum_query_immutable_test.go @@ -2,36 +2,36 @@ package problem303 import "testing" -type caseType struct { - i int - j int - expected int +type testType struct { + i int + j int + want int } func TestConstructor(t *testing.T) { nums := []int{-2, 0, 3, -5, 2, -1} obj := Constructor(nums) - tests := [...]caseType{ + tests := [...]testType{ { - i: 0, - j: 2, - expected: 1, + i: 0, + j: 2, + want: 1, }, { - i: 2, - j: 5, - expected: -1, + i: 2, + j: 5, + want: -1, }, { - i: 0, - j: 5, - expected: -3, + i: 0, + j: 5, + want: -3, }, } - for _, tc := range tests { - output := obj.SumRange(tc.i, tc.j) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.i, tc.j, output, tc.expected) + for _, tt := range tests { + got := obj.SumRange(tt.i, tt.j) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.i, tt.j, got, tt.want) } } } diff --git a/problems/ransom-note/ransom_note_test.go b/problems/ransom-note/ransom_note_test.go index 99635abf6..32ead09ec 100644 --- a/problems/ransom-note/ransom_note_test.go +++ b/problems/ransom-note/ransom_note_test.go @@ -2,34 +2,34 @@ package problem383 import "testing" -type caseType struct { +type testType struct { ransom string magazine string - expected bool + want bool } func TestCanConstruct(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { ransom: "a", magazine: "b", - expected: false, + want: false, }, { ransom: "aa", magazine: "ab", - expected: false, + want: false, }, { ransom: "aa", magazine: "aab", - expected: true, + want: true, }, } - for _, tc := range tests { - output := canConstruct(tc.ransom, tc.magazine) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.ransom, tc.magazine, output, tc.expected) + for _, tt := range tests { + got := canConstruct(tt.ransom, tt.magazine) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.ransom, tt.magazine, got, tt.want) } } } diff --git a/problems/regular-expression-matching/regular_expression_matching_test.go b/problems/regular-expression-matching/regular_expression_matching_test.go index 0c91d45f3..e8d3ca781 100644 --- a/problems/regular-expression-matching/regular_expression_matching_test.go +++ b/problems/regular-expression-matching/regular_expression_matching_test.go @@ -2,49 +2,49 @@ package problem10 import "testing" -type caseType struct { - s string - p string - expected bool +type testType struct { + s string + p string + want bool } func TestIsMatch(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - s: "aa", - p: "a", - expected: false, + s: "aa", + p: "a", + want: false, }, { - s: "aa", - p: "a*", - expected: true, + s: "aa", + p: "a*", + want: true, }, { - s: "ab", - p: ".*", - expected: true, + s: "ab", + p: ".*", + want: true, }, { - s: "aab", - p: "c*a*b", - expected: true, + s: "aab", + p: "c*a*b", + want: true, }, { - s: "mississippi", - p: "mis*is*p*.", - expected: false, + s: "mississippi", + p: "mis*is*p*.", + want: false, }, { - s: "", - p: ".", - expected: false, + s: "", + p: ".", + want: false, }, } - for _, tc := range tests { - output := isMatch(tc.s, tc.p) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.s, tc.p, output, tc.expected) + for _, tt := range tests { + got := isMatch(tt.s, tt.p) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.s, tt.p, got, tt.want) } } } diff --git a/problems/remove-all-adjacent-duplicates-in-string/remove_all_adjacent_duplicates_in_string_test.go b/problems/remove-all-adjacent-duplicates-in-string/remove_all_adjacent_duplicates_in_string_test.go index 3fc45065e..5ba27ce9d 100644 --- a/problems/remove-all-adjacent-duplicates-in-string/remove_all_adjacent_duplicates_in_string_test.go +++ b/problems/remove-all-adjacent-duplicates-in-string/remove_all_adjacent_duplicates_in_string_test.go @@ -2,26 +2,26 @@ package problem1047 import "testing" -type caseType struct { - input string - expected string +type testType struct { + in string + want string } func TestRemoveDuplicates(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "abbaca", - expected: "ca", + in: "abbaca", + want: "ca", }, { - input: "aaabaca", - expected: "abaca", + in: "aaabaca", + want: "abaca", }, } - for _, tc := range tests { - output := removeDuplicates(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := removeDuplicates(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/remove-duplicates-from-sorted-array/remove_duplicates_from_sorted_array_test.go b/problems/remove-duplicates-from-sorted-array/remove_duplicates_from_sorted_array_test.go index 30d2cfcd5..5680e875a 100644 --- a/problems/remove-duplicates-from-sorted-array/remove_duplicates_from_sorted_array_test.go +++ b/problems/remove-duplicates-from-sorted-array/remove_duplicates_from_sorted_array_test.go @@ -5,42 +5,42 @@ import ( "testing" ) -type caseType struct { - input []int - expected []int +type testType struct { + in []int + want []int } func TestRemoveDuplicates(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 1, 2}, - expected: []int{1, 2}, + in: []int{1, 1, 2}, + want: []int{1, 2}, }, { - input: []int{0, 0, 1, 1, 1, 2, 2, 3, 3, 4}, - expected: []int{0, 1, 2, 3, 4}, + in: []int{0, 0, 1, 1, 1, 2, 2, 3, 3, 4}, + want: []int{0, 1, 2, 3, 4}, }, { - input: []int{1, 2, 3, 4}, - expected: []int{1, 2, 3, 4}, + in: []int{1, 2, 3, 4}, + want: []int{1, 2, 3, 4}, }, { - input: []int{1, 2, 2, 3, 3, 3, 4, 4, 4, 4}, - expected: []int{1, 2, 3, 4}, + in: []int{1, 2, 2, 3, 3, 3, 4, 4, 4, 4}, + want: []int{1, 2, 3, 4}, }, { - input: []int{}, - expected: []int{}, + in: []int{}, + want: []int{}, }, } - for _, tc := range tests { - nums := make([]int, len(tc.input)) - copy(nums, tc.input) + for _, tt := range tests { + nums := make([]int, len(tt.in)) + copy(nums, tt.in) l := removeDuplicates(nums) - output := nums[:l] - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + got := nums[:l] + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/remove-duplicates-from-sorted-list/remove_duplicates_from_sorted_list_test.go b/problems/remove-duplicates-from-sorted-list/remove_duplicates_from_sorted_list_test.go index e01242985..0bedfe976 100644 --- a/problems/remove-duplicates-from-sorted-list/remove_duplicates_from_sorted_list_test.go +++ b/problems/remove-duplicates-from-sorted-list/remove_duplicates_from_sorted_list_test.go @@ -7,30 +7,30 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - expected []int +type testType struct { + in []int + want []int } func TestDeleteDuplicates(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 1, 2}, - expected: []int{1, 2}, + in: []int{1, 1, 2}, + want: []int{1, 2}, }, { - input: []int{1, 1, 2, 3, 3}, - expected: []int{1, 2, 3}, + in: []int{1, 1, 2, 3, 3}, + want: []int{1, 2, 3}, }, { - input: []int{0, 0, 1, 1, 2, 2}, - expected: []int{0, 1, 2}, + in: []int{0, 0, 1, 1, 2, 2}, + want: []int{0, 1, 2}, }, } - for _, tc := range tests { - output := deleteDuplicates(kit.SliceInt2ListNode(tc.input)) - if !reflect.DeepEqual(kit.ListNode2SliceInt(output), tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := deleteDuplicates(kit.SliceInt2ListNode(tt.in)) + if !reflect.DeepEqual(kit.ListNode2SliceInt(got), tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/remove-element/remove_element_test.go b/problems/remove-element/remove_element_test.go index 473935f41..b7658f30f 100644 --- a/problems/remove-element/remove_element_test.go +++ b/problems/remove-element/remove_element_test.go @@ -5,48 +5,48 @@ import ( "testing" ) -type caseType struct { - input []int - val int - expected []int +type testType struct { + in []int + val int + want []int } func TestRemoveElement(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{3, 2, 2, 3}, - val: 3, - expected: []int{2, 2}, + in: []int{3, 2, 2, 3}, + val: 3, + want: []int{2, 2}, }, { - input: []int{0, 1, 2, 2, 3, 0, 4, 2}, - val: 2, - expected: []int{0, 1, 3, 0, 4}, + in: []int{0, 1, 2, 2, 3, 0, 4, 2}, + val: 2, + want: []int{0, 1, 3, 0, 4}, }, { - input: []int{1, 2, 3, 4, 5}, - val: 6, - expected: []int{1, 2, 3, 4, 5}, + in: []int{1, 2, 3, 4, 5}, + val: 6, + want: []int{1, 2, 3, 4, 5}, }, { - input: []int{1, 2, 2, 3, 3, 3, 4, 4, 4, 4}, - val: 4, - expected: []int{1, 2, 2, 3, 3, 3}, + in: []int{1, 2, 2, 3, 3, 3, 4, 4, 4, 4}, + val: 4, + want: []int{1, 2, 2, 3, 3, 3}, }, { - input: []int{}, - val: 1, - expected: []int{}, + in: []int{}, + val: 1, + want: []int{}, }, } - for _, tc := range tests { - nums := make([]int, len(tc.input)) - copy(nums, tc.input) - l := removeElement(nums, tc.val) - output := nums[:l] - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + nums := make([]int, len(tt.in)) + copy(nums, tt.in) + l := removeElement(nums, tt.val) + got := nums[:l] + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/remove-outermost-parentheses/remove_outermost_parentheses_test.go b/problems/remove-outermost-parentheses/remove_outermost_parentheses_test.go index 445c77433..a2c1f36ca 100644 --- a/problems/remove-outermost-parentheses/remove_outermost_parentheses_test.go +++ b/problems/remove-outermost-parentheses/remove_outermost_parentheses_test.go @@ -2,30 +2,30 @@ package problem1021 import "testing" -type caseType struct { - input string - expected string +type testType struct { + in string + want string } func TestRemoveOuterParentheses(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "(()())(())", - expected: "()()()", + in: "(()())(())", + want: "()()()", }, { - input: "(()())(())(()(()))", - expected: "()()()()(())", + in: "(()())(())(()(()))", + want: "()()()()(())", }, { - input: "()()", - expected: "", + in: "()()", + want: "", }, } - for _, tc := range tests { - output := removeOuterParentheses(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := removeOuterParentheses(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/reorder-data-in-log-files/reorder_data_in_log_files_test.go b/problems/reorder-data-in-log-files/reorder_data_in_log_files_test.go index 322a5b332..8686e4724 100644 --- a/problems/reorder-data-in-log-files/reorder_data_in_log_files_test.go +++ b/problems/reorder-data-in-log-files/reorder_data_in_log_files_test.go @@ -5,32 +5,32 @@ import ( "testing" ) -type caseType struct { - input []string - expected []string +type testType struct { + in []string + want []string } func TestReorderLogFiles(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []string{"a1 9 2 3 1", "g1 act car", "zo4 4 7", "ab1 off key dog", "a8 act zoo"}, - expected: []string{"g1 act car", "a8 act zoo", "ab1 off key dog", "a1 9 2 3 1", "zo4 4 7"}, + in: []string{"a1 9 2 3 1", "g1 act car", "zo4 4 7", "ab1 off key dog", "a8 act zoo"}, + want: []string{"g1 act car", "a8 act zoo", "ab1 off key dog", "a1 9 2 3 1", "zo4 4 7"}, }, { - input: []string{"8 fj dzz k", "5r 446 6 3", "63 gu psub", "5 ba iedrz", "6s 87979 5", "3r 587 01", "jc 3480612", "bb wsrd kp", "b aq cojj", "r5 6316 71"}, - expected: []string{"b aq cojj", "5 ba iedrz", "8 fj dzz k", "63 gu psub", "bb wsrd kp", "5r 446 6 3", "6s 87979 5", "3r 587 01", "jc 3480612", "r5 6316 71"}, + in: []string{"8 fj dzz k", "5r 446 6 3", "63 gu psub", "5 ba iedrz", "6s 87979 5", "3r 587 01", "jc 3480612", "bb wsrd kp", "b aq cojj", "r5 6316 71"}, + want: []string{"b aq cojj", "5 ba iedrz", "8 fj dzz k", "63 gu psub", "bb wsrd kp", "5r 446 6 3", "6s 87979 5", "3r 587 01", "jc 3480612", "r5 6316 71"}, }, { - input: []string{"qi ir oo i", "cp vnzw i", "0 fkbikbts", "4 j trouka", "gn j q al", "5r w wgqc", "m8 x haje", "fg 28694 6", "i gf mwdoa", "ao 0850716"}, - expected: []string{"0 fkbikbts", "i gf mwdoa", "qi ir oo i", "gn j q al", "4 j trouka", "cp vnzw i", "5r w wgqc", "m8 x haje", "fg 28694 6", "ao 0850716"}, + in: []string{"qi ir oo i", "cp vnzw i", "0 fkbikbts", "4 j trouka", "gn j q al", "5r w wgqc", "m8 x haje", "fg 28694 6", "i gf mwdoa", "ao 0850716"}, + want: []string{"0 fkbikbts", "i gf mwdoa", "qi ir oo i", "gn j q al", "4 j trouka", "cp vnzw i", "5r w wgqc", "m8 x haje", "fg 28694 6", "ao 0850716"}, }, } - for _, tc := range tests { - output := make([]string, len(tc.input)) - copy(output, tc.input) - output = reorderLogFiles(output) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := make([]string, len(tt.in)) + copy(got, tt.in) + got = reorderLogFiles(got) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/repeated-string-match/repeated_string_match_test.go b/problems/repeated-string-match/repeated_string_match_test.go index 232dc1bf3..71f8f6f61 100644 --- a/problems/repeated-string-match/repeated_string_match_test.go +++ b/problems/repeated-string-match/repeated_string_match_test.go @@ -2,39 +2,39 @@ package problem686 import "testing" -type caseType struct { - a string - b string - expected int +type testType struct { + a string + b string + want int } func TestRepeatedStringMatch(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - a: "abcd", - b: "cdabcdab", - expected: 3, + a: "abcd", + b: "cdabcdab", + want: 3, }, { - a: "abcdefg", - b: "cde", - expected: 1, + a: "abcdefg", + b: "cde", + want: 1, }, { - a: "abc", - b: "abcabc", - expected: 2, + a: "abc", + b: "abcabc", + want: 2, }, { - a: "abc", - b: "abcd", - expected: -1, + a: "abc", + b: "abcd", + want: -1, }, } - for _, tc := range tests { - output := repeatedStringMatch(tc.a, tc.b) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.a, tc.b, output, tc.expected) + for _, tt := range tests { + got := repeatedStringMatch(tt.a, tt.b) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.a, tt.b, got, tt.want) } } } diff --git a/problems/repeated-substring-pattern/repeated_substring_pattern_test.go b/problems/repeated-substring-pattern/repeated_substring_pattern_test.go index 8c67350b4..9922234ac 100644 --- a/problems/repeated-substring-pattern/repeated_substring_pattern_test.go +++ b/problems/repeated-substring-pattern/repeated_substring_pattern_test.go @@ -2,53 +2,53 @@ package problem459 import "testing" -type caseType struct { - input string - expected bool +type testType struct { + in string + want bool } func TestRepeatedSubstringPattern(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "a", - expected: false, + in: "a", + want: false, }, { - input: "abab", - expected: true, + in: "abab", + want: true, }, { - input: "aba", - expected: false, + in: "aba", + want: false, }, { - input: "abaaba", - expected: true, + in: "abaaba", + want: true, }, { - input: "abcabcabcabc", - expected: true, + in: "abcabcabcabc", + want: true, }, { - input: "abbaabbaabba", - expected: true, + in: "abbaabbaabba", + want: true, }, { - input: "abcabcabcdabcabcabcdabcabcabcd", - expected: true, + in: "abcabcabcdabcabcabcdabcabcabcd", + want: true, }, { - input: "abaabaabac", - expected: false, + in: "abaabaabac", + want: false, }, { - input: "babbabbabbabbab", - expected: true, + in: "babbabbabbabbab", + want: true, }, } - for _, tc := range tests { - output := repeatedSubstringPattern(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := repeatedSubstringPattern(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/reshape-the-matrix/reshape_the_matrix_test.go b/problems/reshape-the-matrix/reshape_the_matrix_test.go index 54bc505df..837868aa6 100644 --- a/problems/reshape-the-matrix/reshape_the_matrix_test.go +++ b/problems/reshape-the-matrix/reshape_the_matrix_test.go @@ -5,15 +5,15 @@ import ( "testing" ) -type caseType struct { - nums [][]int - r int - c int - expected [][]int +type testType struct { + nums [][]int + r int + c int + want [][]int } func TestMatrixReshape(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { nums: [][]int{ {1, 2}, @@ -21,7 +21,7 @@ func TestMatrixReshape(t *testing.T) { }, r: 1, c: 4, - expected: [][]int{ + want: [][]int{ {1, 2, 3, 4}, }, }, @@ -32,16 +32,16 @@ func TestMatrixReshape(t *testing.T) { }, r: 2, c: 4, - expected: [][]int{ + want: [][]int{ {1, 2}, {3, 4}, }, }, } - for _, tc := range tests { - output := matrixReshape(tc.nums, tc.r, tc.c) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.nums, output, tc.expected) + for _, tt := range tests { + got := matrixReshape(tt.nums, tt.r, tt.c) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.nums, got, tt.want) } } diff --git a/problems/reverse-bits/reverse_bits_test.go b/problems/reverse-bits/reverse_bits_test.go index 007a907b9..827efc5c6 100644 --- a/problems/reverse-bits/reverse_bits_test.go +++ b/problems/reverse-bits/reverse_bits_test.go @@ -2,26 +2,26 @@ package problem190 import "testing" -type caseType struct { - input uint32 - expected uint32 +type testType struct { + in uint32 + want uint32 } func TestReverseBits(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 43261596, - expected: 964176192, + in: 43261596, + want: 964176192, }, { - input: 4294967293, - expected: 3221225471, + in: 4294967293, + want: 3221225471, }, } - for _, tc := range tests { - output := reverseBits(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := reverseBits(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/reverse-integer/reverse_integer_test.go b/problems/reverse-integer/reverse_integer_test.go index a6f0999fb..1d20103c0 100644 --- a/problems/reverse-integer/reverse_integer_test.go +++ b/problems/reverse-integer/reverse_integer_test.go @@ -14,10 +14,10 @@ func TestReverse(t *testing.T) { math.MinInt32: 0, } - for input, expected := range tests { - output := reverse(input) - if output != expected { - t.Fatalf("input: %v, output: %v, expected: %v", input, output, expected) + for in, want := range tests { + got := reverse(in) + if got != want { + t.Fatalf("in: %v, got: %v, want: %v", in, got, want) } } } diff --git a/problems/reverse-linked-list/reverse_linked_list_test.go b/problems/reverse-linked-list/reverse_linked_list_test.go index cc1974408..8bffc1a0f 100644 --- a/problems/reverse-linked-list/reverse_linked_list_test.go +++ b/problems/reverse-linked-list/reverse_linked_list_test.go @@ -7,22 +7,22 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - expected []int +type testType struct { + in []int + want []int } func TestReverseList(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 3, 4, 5}, - expected: []int{5, 4, 3, 2, 1}, + in: []int{1, 2, 3, 4, 5}, + want: []int{5, 4, 3, 2, 1}, }, } - for _, tc := range tests { - output := kit.ListNode2SliceInt(reverseList(kit.SliceInt2ListNode(tc.input))) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := kit.ListNode2SliceInt(reverseList(kit.SliceInt2ListNode(tt.in))) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/reverse-only-letters/reverse_only_letters_test.go b/problems/reverse-only-letters/reverse_only_letters_test.go index 42fdb3b52..467e56dc8 100644 --- a/problems/reverse-only-letters/reverse_only_letters_test.go +++ b/problems/reverse-only-letters/reverse_only_letters_test.go @@ -2,30 +2,30 @@ package problem917 import "testing" -type caseType struct { - input string - expected string +type testType struct { + in string + want string } func TestReverseOnlyLetters(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "ab-cd", - expected: "dc-ba", + in: "ab-cd", + want: "dc-ba", }, { - input: "a-bC-dEf-ghIj", - expected: "j-Ih-gfE-dCba", + in: "a-bC-dEf-ghIj", + want: "j-Ih-gfE-dCba", }, { - input: "Test1ng-Leet=code-Q!", - expected: "Qedo1ct-eeLg=ntse-T!", + in: "Test1ng-Leet=code-Q!", + want: "Qedo1ct-eeLg=ntse-T!", }, } - for _, tc := range tests { - output := reverseOnlyLetters(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := reverseOnlyLetters(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/reverse-string-ii/reverse_string_ii_test.go b/problems/reverse-string-ii/reverse_string_ii_test.go index 3d0155f16..5d58a0b8b 100644 --- a/problems/reverse-string-ii/reverse_string_ii_test.go +++ b/problems/reverse-string-ii/reverse_string_ii_test.go @@ -2,39 +2,39 @@ package problem541 import "testing" -type caseType struct { - s string - k int - expected string +type testType struct { + s string + k int + want string } func TestReverseStr(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - s: "abcdefg", - k: 2, - expected: "bacdfeg", + s: "abcdefg", + k: 2, + want: "bacdfeg", }, { - s: "abcdefg", - k: 4, - expected: "dcbaefg", + s: "abcdefg", + k: 4, + want: "dcbaefg", }, { - s: "abcd", - k: 4, - expected: "dcba", + s: "abcd", + k: 4, + want: "dcba", }, { - s: "abcdefg", - k: 8, - expected: "gfedcba", + s: "abcdefg", + k: 8, + want: "gfedcba", }, } - for _, tc := range tests { - output := reverseStr(tc.s, tc.k) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.s, tc.k, output, tc.expected) + for _, tt := range tests { + got := reverseStr(tt.s, tt.k) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.s, tt.k, got, tt.want) } } } diff --git a/problems/reverse-string/reverse_string_test.go b/problems/reverse-string/reverse_string_test.go index 2eb7ffcc1..67027e1e0 100644 --- a/problems/reverse-string/reverse_string_test.go +++ b/problems/reverse-string/reverse_string_test.go @@ -5,28 +5,28 @@ import ( "testing" ) -type caseType struct { - input []byte - expected []byte +type testType struct { + in []byte + want []byte } func TestReverseString(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []byte{'h', 'e', 'l', 'l', 'o'}, - expected: []byte{'o', 'l', 'l', 'e', 'h'}, + in: []byte{'h', 'e', 'l', 'l', 'o'}, + want: []byte{'o', 'l', 'l', 'e', 'h'}, }, { - input: []byte{'H', 'a', 'n', 'n', 'a', 'h'}, - expected: []byte{'h', 'a', 'n', 'n', 'a', 'H'}, + in: []byte{'H', 'a', 'n', 'n', 'a', 'h'}, + want: []byte{'h', 'a', 'n', 'n', 'a', 'H'}, }, } - for _, tc := range tests { - output := make([]byte, len(tc.input)) - copy(output, tc.input) - reverseString(output) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := make([]byte, len(tt.in)) + copy(got, tt.in) + reverseString(got) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/reverse-vowels-of-a-string/reverse_vowels_of_a_string_test.go b/problems/reverse-vowels-of-a-string/reverse_vowels_of_a_string_test.go index 9ecbffe44..398aa3df7 100644 --- a/problems/reverse-vowels-of-a-string/reverse_vowels_of_a_string_test.go +++ b/problems/reverse-vowels-of-a-string/reverse_vowels_of_a_string_test.go @@ -2,26 +2,26 @@ package problem345 import "testing" -type caseType struct { - input string - expected string +type testType struct { + in string + want string } func TestReverseVowels(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "hello", - expected: "holle", + in: "hello", + want: "holle", }, { - input: "leetcode", - expected: "leotcede", + in: "leetcode", + want: "leotcede", }, } - for _, tc := range tests { - output := reverseVowels(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := reverseVowels(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/reverse-words-in-a-string-iii/reverse_words_in_a_string_iii_test.go b/problems/reverse-words-in-a-string-iii/reverse_words_in_a_string_iii_test.go index ce3ab0a5b..374779bab 100644 --- a/problems/reverse-words-in-a-string-iii/reverse_words_in_a_string_iii_test.go +++ b/problems/reverse-words-in-a-string-iii/reverse_words_in_a_string_iii_test.go @@ -2,22 +2,22 @@ package problem557 import "testing" -type caseType struct { - input string - expected string +type testType struct { + in string + want string } func TestReverseWords(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "Let's take LeetCode contest", - expected: "s'teL ekat edoCteeL tsetnoc", + in: "Let's take LeetCode contest", + want: "s'teL ekat edoCteeL tsetnoc", }, } - for _, tc := range tests { - output := reverseWords(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := reverseWords(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/reverse-words-in-a-string/reverse_words_in_a_string_test.go b/problems/reverse-words-in-a-string/reverse_words_in_a_string_test.go index 84e5c1b5e..a4038c9d2 100644 --- a/problems/reverse-words-in-a-string/reverse_words_in_a_string_test.go +++ b/problems/reverse-words-in-a-string/reverse_words_in_a_string_test.go @@ -2,30 +2,30 @@ package problem151 import "testing" -type caseType struct { - input string - expected string +type testType struct { + in string + want string } func TestReverseWords(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "the sky is blue", - expected: "blue is sky the", + in: "the sky is blue", + want: "blue is sky the", }, { - input: " hello world! ", - expected: "world! hello", + in: " hello world! ", + want: "world! hello", }, { - input: "a good example", - expected: "example good a", + in: "a good example", + want: "example good a", }, } - for _, tc := range tests { - output := reverseWords(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := reverseWords(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/robot-bounded-in-circle/robot_bounded_in_circle_test.go b/problems/robot-bounded-in-circle/robot_bounded_in_circle_test.go index 6e89bd132..94cf7a854 100644 --- a/problems/robot-bounded-in-circle/robot_bounded_in_circle_test.go +++ b/problems/robot-bounded-in-circle/robot_bounded_in_circle_test.go @@ -2,46 +2,46 @@ package problem1041 import "testing" -type caseType struct { - input string - expected bool +type testType struct { + in string + want bool } func TestIsRobotBounded(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "GGLLGG", - expected: true, + in: "GGLLGG", + want: true, }, { - input: "GG", - expected: false, + in: "GG", + want: false, }, { - input: "GL", - expected: true, + in: "GL", + want: true, }, { - input: "GGLLGGGGRRGG", - expected: true, + in: "GGLLGGGGRRGG", + want: true, }, { - input: "GGRRGG", - expected: true, + in: "GGRRGG", + want: true, }, { - input: "GLRLLGLL", - expected: true, + in: "GLRLLGLL", + want: true, }, { - input: "GLGRGLGLGLGL", - expected: false, + in: "GLGRGLGLGLGL", + want: false, }, } - for _, tc := range tests { - output := isRobotBounded(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isRobotBounded(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/robot-return-to-origin/robot_return_to_origin_test.go b/problems/robot-return-to-origin/robot_return_to_origin_test.go index 9f857b5db..46a9d5ced 100644 --- a/problems/robot-return-to-origin/robot_return_to_origin_test.go +++ b/problems/robot-return-to-origin/robot_return_to_origin_test.go @@ -2,34 +2,34 @@ package problem657 import "testing" -type caseType struct { - input string - expected bool +type testType struct { + in string + want bool } func TestJudgeCircle(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "UD", - expected: true, + in: "UD", + want: true, }, { - input: "RL", - expected: true, + in: "RL", + want: true, }, { - input: "LL", - expected: false, + in: "LL", + want: false, }, { - input: "UU", - expected: false, + in: "UU", + want: false, }, } - for _, tc := range tests { - output := judgeCircle(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := judgeCircle(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/roman-to-integer/roman_to_integer_test.go b/problems/roman-to-integer/roman_to_integer_test.go index 16e2cca99..5ccfa1daf 100644 --- a/problems/roman-to-integer/roman_to_integer_test.go +++ b/problems/roman-to-integer/roman_to_integer_test.go @@ -11,10 +11,10 @@ func TestRomanToInt(t *testing.T) { "MCMXCIV": 1994, } - for input, expected := range tests { - output := romanToInt(input) - if output != expected { - t.Fatalf("input: %v, output: %v, expected: %v", input, output, expected) + for in, want := range tests { + got := romanToInt(in) + if got != want { + t.Fatalf("in: %v, got: %v, want: %v", in, got, want) } } } diff --git a/problems/rotate-array/rotate_array_test.go b/problems/rotate-array/rotate_array_test.go index d60f4e221..98283b6bc 100644 --- a/problems/rotate-array/rotate_array_test.go +++ b/problems/rotate-array/rotate_array_test.go @@ -6,36 +6,36 @@ import ( ) type castType struct { - nums []int - k int - expected []int + nums []int + k int + want []int } func TestRotate(t *testing.T) { tests := [...]castType{ { - nums: []int{1, 2, 3, 4, 5, 6, 7}, - k: 3, - expected: []int{5, 6, 7, 1, 2, 3, 4}, + nums: []int{1, 2, 3, 4, 5, 6, 7}, + k: 3, + want: []int{5, 6, 7, 1, 2, 3, 4}, }, { - nums: []int{-1, -100, 3, 99}, - k: 2, - expected: []int{3, 99, -1, -100}, + nums: []int{-1, -100, 3, 99}, + k: 2, + want: []int{3, 99, -1, -100}, }, { - nums: []int{-1}, - k: 2, - expected: []int{-1}, + nums: []int{-1}, + k: 2, + want: []int{-1}, }, } - for _, tc := range tests { - output := make([]int, len(tc.nums)) - copy(output, tc.nums) - rotate(output, tc.k) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.nums, tc.k, output, tc.expected) + for _, tt := range tests { + got := make([]int, len(tt.nums)) + copy(got, tt.nums) + rotate(got, tt.k) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.nums, tt.k, got, tt.want) } } } diff --git a/problems/rotate-image/rotate_image_test.go b/problems/rotate-image/rotate_image_test.go index a8b9d85ec..e79d4c3b6 100644 --- a/problems/rotate-image/rotate_image_test.go +++ b/problems/rotate-image/rotate_image_test.go @@ -5,33 +5,33 @@ import ( "testing" ) -type caseType struct { - input [][]int - expected [][]int +type testType struct { + in [][]int + want [][]int } func TestRotate(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]int{ + in: [][]int{ {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, }, - expected: [][]int{ + want: [][]int{ {7, 4, 1}, {8, 5, 2}, {9, 6, 3}, }, }, { - input: [][]int{ + in: [][]int{ {5, 1, 9, 11}, {2, 4, 8, 10}, {13, 3, 6, 7}, {15, 14, 12, 16}, }, - expected: [][]int{ + want: [][]int{ {15, 13, 2, 5}, {14, 3, 4, 1}, {12, 6, 8, 9}, @@ -40,16 +40,16 @@ func TestRotate(t *testing.T) { }, } - for _, tc := range tests { - l := len(tc.input) - output := make([][]int, l) + for _, tt := range tests { + l := len(tt.in) + got := make([][]int, l) for i := 0; i < l; i++ { - output[i] = make([]int, l) - copy(output[i], tc.input[i]) + got[i] = make([]int, l) + copy(got[i], tt.in[i]) } - rotate(output) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + rotate(got) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/rotate-string/rotate_string_test.go b/problems/rotate-string/rotate_string_test.go index 188cc21b5..ded3a7430 100644 --- a/problems/rotate-string/rotate_string_test.go +++ b/problems/rotate-string/rotate_string_test.go @@ -2,34 +2,34 @@ package problem796 import "testing" -type caseType struct { - A string - B string - expected bool +type testType struct { + A string + B string + want bool } func TestRotateString(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - A: "abcde", - B: "cdeab", - expected: true, + A: "abcde", + B: "cdeab", + want: true, }, { - A: "abcde", - B: "abced", - expected: false, + A: "abcde", + B: "abced", + want: false, }, { - A: "abcde", - B: "abcdef", - expected: false, + A: "abcde", + B: "abcdef", + want: false, }, } - for _, tc := range tests { - output := rotateString(tc.A, tc.B) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.A, tc.B, output, tc.expected) + for _, tt := range tests { + got := rotateString(tt.A, tt.B) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.A, tt.B, got, tt.want) } } } diff --git a/problems/rotated-digits/rotated_digits_test.go b/problems/rotated-digits/rotated_digits_test.go index 4375f9b3a..e338a914d 100644 --- a/problems/rotated-digits/rotated_digits_test.go +++ b/problems/rotated-digits/rotated_digits_test.go @@ -2,34 +2,34 @@ package problem788 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestRotatedDigits(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 10, - expected: 4, + in: 10, + want: 4, }, { - input: 23, - expected: 11, + in: 23, + want: 11, }, { - input: 100, - expected: 40, + in: 100, + want: 40, }, { - input: 200, - expected: 81, + in: 200, + want: 81, }, } - for _, tc := range tests { - output := rotatedDigits(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := rotatedDigits(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/rotting-oranges/rotting_oranges_test.go b/problems/rotting-oranges/rotting_oranges_test.go index 9d7cfe55c..9ba440447 100644 --- a/problems/rotting-oranges/rotting_oranges_test.go +++ b/problems/rotting-oranges/rotting_oranges_test.go @@ -2,46 +2,46 @@ package problem994 import "testing" -type caseType struct { - input [][]int - expected int +type testType struct { + in [][]int + want int } func TestOrangesRotting(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]int{ + in: [][]int{ {2, 1, 1}, {1, 1, 0}, {0, 1, 1}, }, - expected: 4, + want: 4, }, { - input: [][]int{ + in: [][]int{ {2, 1, 1}, {0, 1, 1}, {1, 0, 1}, }, - expected: -1, + want: -1, }, { - input: [][]int{ + in: [][]int{ {0, 2}, }, - expected: 0, + want: 0, }, { - input: [][]int{ + in: [][]int{ {1, 2}, }, - expected: 1, + want: 1, }, } - for _, tc := range tests { - output := orangesRotting(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := orangesRotting(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/same-tree/same_tree_test.go b/problems/same-tree/same_tree_test.go index 9a6766ae0..264348cd2 100644 --- a/problems/same-tree/same_tree_test.go +++ b/problems/same-tree/same_tree_test.go @@ -6,34 +6,34 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - p []int - q []int - expected bool +type testType struct { + p []int + q []int + want bool } func TestIsSameTree(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - p: []int{1, 2, 3}, - q: []int{1, 2, 3}, - expected: true, + p: []int{1, 2, 3}, + q: []int{1, 2, 3}, + want: true, }, { - p: []int{1, 2}, - q: []int{1, kit.NULL, 2}, - expected: false, + p: []int{1, 2}, + q: []int{1, kit.NULL, 2}, + want: false, }, { - p: []int{1, 2, 1}, - q: []int{1, 1, 2}, - expected: false, + p: []int{1, 2, 1}, + q: []int{1, 1, 2}, + want: false, }, } - for _, tc := range tests { - output := isSameTree(kit.SliceInt2TreeNode(tc.p), kit.SliceInt2TreeNode(tc.q)) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.p, tc.q, output, tc.expected) + for _, tt := range tests { + got := isSameTree(kit.SliceInt2TreeNode(tt.p), kit.SliceInt2TreeNode(tt.q)) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.p, tt.q, got, tt.want) } } } diff --git a/problems/search-insert-position/search_insert_position_test.go b/problems/search-insert-position/search_insert_position_test.go index c09c15b41..2f8387a91 100644 --- a/problems/search-insert-position/search_insert_position_test.go +++ b/problems/search-insert-position/search_insert_position_test.go @@ -2,45 +2,45 @@ package problem35 import "testing" -type caseType struct { - nums []int - target int - expected int +type testType struct { + nums []int + target int + want int } func TestSearchInsert(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - nums: []int{2, 7, 11, 15}, - target: 5, - expected: 1, + nums: []int{2, 7, 11, 15}, + target: 5, + want: 1, }, { - nums: []int{1, 3, 5, 6}, - target: 2, - expected: 1, + nums: []int{1, 3, 5, 6}, + target: 2, + want: 1, }, { - nums: []int{1, 3, 5, 6}, - target: 7, - expected: 4, + nums: []int{1, 3, 5, 6}, + target: 7, + want: 4, }, { - nums: []int{1, 3, 5, 6}, - target: 7, - expected: 4, + nums: []int{1, 3, 5, 6}, + target: 7, + want: 4, }, { - nums: []int{1, 3, 5, 6}, - target: 0, - expected: 0, + nums: []int{1, 3, 5, 6}, + target: 0, + want: 0, }, } - for _, tc := range tests { - output := searchInsert(tc.nums, tc.target) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.nums, output, tc.expected) + for _, tt := range tests { + got := searchInsert(tt.nums, tt.target) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.nums, got, tt.want) } } } diff --git a/problems/self-dividing-numbers/self_dividing_numbers_test.go b/problems/self-dividing-numbers/self_dividing_numbers_test.go index 8c61d157e..afefd547b 100644 --- a/problems/self-dividing-numbers/self_dividing_numbers_test.go +++ b/problems/self-dividing-numbers/self_dividing_numbers_test.go @@ -5,24 +5,24 @@ import ( "testing" ) -type caseType struct { - left int - right int - expected []int +type testType struct { + left int + right int + want []int } func TestSelfDividingNumbers(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - left: 1, - right: 22, - expected: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22}, + left: 1, + right: 22, + want: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22}, }, } - for _, tc := range tests { - output := selfDividingNumbers(tc.left, tc.right) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.left, tc.right, output, tc.expected) + for _, tt := range tests { + got := selfDividingNumbers(tt.left, tt.right) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.left, tt.right, got, tt.want) } } } diff --git a/problems/shortest-unsorted-continuous-subarray/shortest_unsorted_continuous_subarray_test.go b/problems/shortest-unsorted-continuous-subarray/shortest_unsorted_continuous_subarray_test.go index 987280ed4..3a3a4f987 100644 --- a/problems/shortest-unsorted-continuous-subarray/shortest_unsorted_continuous_subarray_test.go +++ b/problems/shortest-unsorted-continuous-subarray/shortest_unsorted_continuous_subarray_test.go @@ -2,30 +2,30 @@ package problem581 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestFindUnsortedSubarray(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{2, 6, 4, 8, 10, 9, 15}, - expected: 5, + in: []int{2, 6, 4, 8, 10, 9, 15}, + want: 5, }, { - input: []int{1, 2, 3, 4}, - expected: 0, + in: []int{1, 2, 3, 4}, + want: 0, }, { - input: []int{1, 2, 4, 5, 3}, - expected: 3, + in: []int{1, 2, 4, 5, 3}, + want: 3, }, } - for _, tc := range tests { - output := findUnsortedSubarray(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := findUnsortedSubarray(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/simplify-path/simplify_path_test.go b/problems/simplify-path/simplify_path_test.go index 1480a0c5a..3e3585734 100644 --- a/problems/simplify-path/simplify_path_test.go +++ b/problems/simplify-path/simplify_path_test.go @@ -2,42 +2,42 @@ package problem71 import "testing" -type caseType struct { - input string - expected string +type testType struct { + in string + want string } func TestSimplifyPath(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "/home/", - expected: "/home", + in: "/home/", + want: "/home", }, { - input: "/../", - expected: "/", + in: "/../", + want: "/", }, { - input: "/home//foo/", - expected: "/home/foo", + in: "/home//foo/", + want: "/home/foo", }, { - input: "/a/./b/../../c/", - expected: "/c", + in: "/a/./b/../../c/", + want: "/c", }, { - input: "/a/../../b/../c//.//", - expected: "/c", + in: "/a/../../b/../c//.//", + want: "/c", }, { - input: "/a//b////c/d//././/..", - expected: "/a/b/c", + in: "/a//b////c/d//././/..", + want: "/a/b/c", }, } - for _, tc := range tests { - output := simplifyPath(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := simplifyPath(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/single-number-ii/single_number_ii_test.go b/problems/single-number-ii/single_number_ii_test.go index 9f426485f..887fd0deb 100644 --- a/problems/single-number-ii/single_number_ii_test.go +++ b/problems/single-number-ii/single_number_ii_test.go @@ -2,26 +2,26 @@ package problem137 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestSingleNumber(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{2, 2, 3, 2}, - expected: 3, + in: []int{2, 2, 3, 2}, + want: 3, }, { - input: []int{0, 1, 0, 1, 0, 1, 99}, - expected: 99, + in: []int{0, 1, 0, 1, 0, 1, 99}, + want: 99, }, } - for _, tc := range tests { - output := singleNumber(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := singleNumber(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/single-number/single_number_test.go b/problems/single-number/single_number_test.go index ca0bfbc19..559e0d9b7 100644 --- a/problems/single-number/single_number_test.go +++ b/problems/single-number/single_number_test.go @@ -2,31 +2,31 @@ package problem136 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestSingleNumber(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{2, 2, 1}, - expected: 1, + in: []int{2, 2, 1}, + want: 1, }, { - input: []int{4, 1, 2, 1, 2}, - expected: 4, + in: []int{4, 1, 2, 1, 2}, + want: 4, }, { - input: []int{1, 2, 1, 2, 3}, - expected: 3, + in: []int{1, 2, 1, 2, 3}, + want: 3, }, } - for _, tc := range tests { - output := singleNumber(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := singleNumber(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/smallest-range-i/smallest_range_i_test.go b/problems/smallest-range-i/smallest_range_i_test.go index 3d4e60a59..69fb1faf8 100644 --- a/problems/smallest-range-i/smallest_range_i_test.go +++ b/problems/smallest-range-i/smallest_range_i_test.go @@ -2,44 +2,44 @@ package problem908 import "testing" -type caseType struct { - input []int - k int - expected int +type testType struct { + in []int + k int + want int } func TestSmallestRangeI(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1}, - k: 0, - expected: 0, + in: []int{1}, + k: 0, + want: 0, }, { - input: []int{0, 10}, - k: 2, - expected: 6, + in: []int{0, 10}, + k: 2, + want: 6, }, { - input: []int{1, 3, 6}, - k: 3, - expected: 0, + in: []int{1, 3, 6}, + k: 3, + want: 0, }, { - input: []int{1, 3, 5, 7, 9}, - k: 1, - expected: 6, + in: []int{1, 3, 5, 7, 9}, + k: 1, + want: 6, }, { - input: []int{18, 16, 12, 7, 9, 3, 5}, - k: 6, - expected: 3, + in: []int{18, 16, 12, 7, 9, 3, 5}, + k: 6, + want: 3, }, } - for _, tc := range tests { - output := smallestRangeI(tc.input, tc.k) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := smallestRangeI(tt.in, tt.k) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/sort-array-by-parity-ii/sort_array_by_parity_ii_test.go b/problems/sort-array-by-parity-ii/sort_array_by_parity_ii_test.go index 89b66b58f..847b97493 100644 --- a/problems/sort-array-by-parity-ii/sort_array_by_parity_ii_test.go +++ b/problems/sort-array-by-parity-ii/sort_array_by_parity_ii_test.go @@ -5,26 +5,26 @@ import ( "testing" ) -type caseType struct { - input []int - expected []int +type testType struct { + in []int + want []int } func TestSortArrayByParityII(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{4, 2, 5, 7}, - expected: []int{4, 5, 2, 7}, + in: []int{4, 2, 5, 7}, + want: []int{4, 5, 2, 7}, }, { - input: []int{2, 3, 1, 1, 4, 0, 0, 4, 3, 3}, - expected: []int{2, 3, 0, 1, 4, 1, 0, 3, 4, 3}, + in: []int{2, 3, 1, 1, 4, 0, 0, 4, 3, 3}, + want: []int{2, 3, 0, 1, 4, 1, 0, 3, 4, 3}, }, } - for _, tc := range tests { - output := sortArrayByParityII(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := sortArrayByParityII(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/sort-array-by-parity/sort_array_by_parity_test.go b/problems/sort-array-by-parity/sort_array_by_parity_test.go index fcc0f4893..cd78c5ed0 100644 --- a/problems/sort-array-by-parity/sort_array_by_parity_test.go +++ b/problems/sort-array-by-parity/sort_array_by_parity_test.go @@ -5,22 +5,22 @@ import ( "testing" ) -type caseType struct { - input []int - expected []int +type testType struct { + in []int + want []int } func TestSortArrayByParity(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{3, 1, 2, 4}, - expected: []int{2, 4, 3, 1}, + in: []int{3, 1, 2, 4}, + want: []int{2, 4, 3, 1}, }, } - for _, tc := range tests { - output := sortArrayByParity(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := sortArrayByParity(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/split-a-string-in-balanced-strings/split_a_string_in_balanced_strings_test.go b/problems/split-a-string-in-balanced-strings/split_a_string_in_balanced_strings_test.go index a4c73ff8d..7094dc22e 100644 --- a/problems/split-a-string-in-balanced-strings/split_a_string_in_balanced_strings_test.go +++ b/problems/split-a-string-in-balanced-strings/split_a_string_in_balanced_strings_test.go @@ -2,30 +2,30 @@ package problem1221 import "testing" -type caseType struct { - input string - expected int +type testType struct { + in string + want int } func TestBalancedStringSplit(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "RLRRLLRLRL", - expected: 4, + in: "RLRRLLRLRL", + want: 4, }, { - input: "RLLLLRRRLR", - expected: 3, + in: "RLLLLRRRLR", + want: 3, }, { - input: "LLLLRRRR", - expected: 1, + in: "LLLLRRRR", + want: 1, }, } - for _, tc := range tests { - output := balancedStringSplit(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := balancedStringSplit(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/sqrtx/sqrtx_test.go b/problems/sqrtx/sqrtx_test.go index 511836416..1df7ab5a6 100644 --- a/problems/sqrtx/sqrtx_test.go +++ b/problems/sqrtx/sqrtx_test.go @@ -2,34 +2,34 @@ package problem69 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestMySqrt(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 4, - expected: 2, + in: 4, + want: 2, }, { - input: 8, - expected: 2, + in: 8, + want: 2, }, { - input: 0, - expected: 0, + in: 0, + want: 0, }, { - input: 1, - expected: 1, + in: 1, + want: 1, }, } - for _, tc := range tests { - output := mySqrt(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := mySqrt(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/squares-of-a-sorted-array/squares_of_a_sorted_array_test.go b/problems/squares-of-a-sorted-array/squares_of_a_sorted_array_test.go index 701093419..bdfe20889 100644 --- a/problems/squares-of-a-sorted-array/squares_of_a_sorted_array_test.go +++ b/problems/squares-of-a-sorted-array/squares_of_a_sorted_array_test.go @@ -5,26 +5,26 @@ import ( "testing" ) -type caseType struct { - input []int - expected []int +type testType struct { + in []int + want []int } func TestSortedSquares(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{-4, -1, 0, 3, 10}, - expected: []int{0, 1, 9, 16, 100}, + in: []int{-4, -1, 0, 3, 10}, + want: []int{0, 1, 9, 16, 100}, }, { - input: []int{-7, -3, 2, 3, 11}, - expected: []int{4, 9, 9, 49, 121}, + in: []int{-7, -3, 2, 3, 11}, + want: []int{4, 9, 9, 49, 121}, }, } - for _, tc := range tests { - output := sortedSquares(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := sortedSquares(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/stone-game/stone_game_test.go b/problems/stone-game/stone_game_test.go index b2875279a..834473a1c 100644 --- a/problems/stone-game/stone_game_test.go +++ b/problems/stone-game/stone_game_test.go @@ -2,26 +2,26 @@ package problem877 import "testing" -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestStoneGame(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{5, 3, 4, 5}, - expected: true, + in: []int{5, 3, 4, 5}, + want: true, }, { - input: []int{2, 5, 7, 3}, - expected: true, + in: []int{2, 5, 7, 3}, + want: true, }, } - for _, tc := range tests { - output := stoneGame(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := stoneGame(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/string-compression/string_compression_test.go b/problems/string-compression/string_compression_test.go index 9eb03fc8c..c813ef387 100644 --- a/problems/string-compression/string_compression_test.go +++ b/problems/string-compression/string_compression_test.go @@ -5,34 +5,34 @@ import ( "testing" ) -type caseType struct { - input []byte - expected []byte +type testType struct { + in []byte + want []byte } func TestCompress(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []byte{'a', 'a', 'b', 'b', 'c', 'c', 'c'}, - expected: []byte{'a', '2', 'b', '2', 'c', '3'}, + in: []byte{'a', 'a', 'b', 'b', 'c', 'c', 'c'}, + want: []byte{'a', '2', 'b', '2', 'c', '3'}, }, { - input: []byte{'a'}, - expected: []byte{'a'}, + in: []byte{'a'}, + want: []byte{'a'}, }, { - input: []byte{'a', 'a'}, - expected: []byte{'a', '2'}, + in: []byte{'a', 'a'}, + want: []byte{'a', '2'}, }, { - input: []byte{'a', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'}, - expected: []byte{'a', 'b', '1', '2'}, + in: []byte{'a', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'}, + want: []byte{'a', 'b', '1', '2'}, }, } - for _, tc := range tests { - l := compress(tc.input) - if !reflect.DeepEqual(tc.input[:l], tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, l, tc.expected) + for _, tt := range tests { + l := compress(tt.in) + if !reflect.DeepEqual(tt.in[:l], tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, l, tt.want) } } } diff --git a/problems/string-to-integer-atoi/string_to_integer_atoi_test.go b/problems/string-to-integer-atoi/string_to_integer_atoi_test.go index b5a25cf45..3e37dbd11 100644 --- a/problems/string-to-integer-atoi/string_to_integer_atoi_test.go +++ b/problems/string-to-integer-atoi/string_to_integer_atoi_test.go @@ -21,10 +21,10 @@ func TestMyAtoi(t *testing.T) { "9876543210": math.MaxInt32, } - for input, expected := range tests { - output := myAtoi(input) - if output != expected { - t.Fatalf("input: %v, output: %v, expected: %v", input, output, expected) + for in, want := range tests { + got := myAtoi(in) + if got != want { + t.Fatalf("in: %v, got: %v, want: %v", in, got, want) } } } diff --git a/problems/string-without-aaa-or-bbb/string_without_aaa_or_bbb_test.go b/problems/string-without-aaa-or-bbb/string_without_aaa_or_bbb_test.go index 72cb93d15..ad4625d85 100644 --- a/problems/string-without-aaa-or-bbb/string_without_aaa_or_bbb_test.go +++ b/problems/string-without-aaa-or-bbb/string_without_aaa_or_bbb_test.go @@ -2,39 +2,39 @@ package problem984 import "testing" -type caseType struct { - a int - b int - expected string +type testType struct { + a int + b int + want string } func TestStrWithout3a3b(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - a: 6, - b: 2, - expected: "aabaabaa", + a: 6, + b: 2, + want: "aabaabaa", }, { - a: 2, - b: 6, - expected: "bbabbabb", + a: 2, + b: 6, + want: "bbabbabb", }, { - a: 1, - b: 2, - expected: "bba", + a: 1, + b: 2, + want: "bba", }, { - a: 4, - b: 1, - expected: "aabaa", + a: 4, + b: 1, + want: "aabaa", }, } - for _, tc := range tests { - output := strWithout3a3b(tc.a, tc.b) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.a, tc.b, output, tc.expected) + for _, tt := range tests { + got := strWithout3a3b(tt.a, tt.b) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.a, tt.b, got, tt.want) } } } diff --git a/problems/student-attendance-record-i/student_attendance_record_i_test.go b/problems/student-attendance-record-i/student_attendance_record_i_test.go index 855310d60..76b4f54f4 100644 --- a/problems/student-attendance-record-i/student_attendance_record_i_test.go +++ b/problems/student-attendance-record-i/student_attendance_record_i_test.go @@ -2,26 +2,26 @@ package problem551 import "testing" -type caseType struct { - input string - expected bool +type testType struct { + in string + want bool } func TestCheckRecord(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "PPALLP", - expected: true, + in: "PPALLP", + want: true, }, { - input: "PPALLL", - expected: false, + in: "PPALLL", + want: false, }, } - for _, tc := range tests { - output := checkRecord(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := checkRecord(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/sum-of-even-numbers-after-queries/sum_of_even_numbers_after_queries_test.go b/problems/sum-of-even-numbers-after-queries/sum_of_even_numbers_after_queries_test.go index 95a752741..a6c1791ad 100644 --- a/problems/sum-of-even-numbers-after-queries/sum_of_even_numbers_after_queries_test.go +++ b/problems/sum-of-even-numbers-after-queries/sum_of_even_numbers_after_queries_test.go @@ -5,24 +5,24 @@ import ( "testing" ) -type caseType struct { - input []int - queries [][]int - expected []int +type testType struct { + in []int + queries [][]int + want []int } func TestSumEvenAfterQueries(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 3, 4}, - queries: [][]int{{1, 0}, {-3, 1}, {-4, 0}, {2, 3}}, - expected: []int{8, 6, 2, 4}, + in: []int{1, 2, 3, 4}, + queries: [][]int{{1, 0}, {-3, 1}, {-4, 0}, {2, 3}}, + want: []int{8, 6, 2, 4}, }, } - for _, tc := range tests { - output := sumEvenAfterQueries(tc.input, tc.queries) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := sumEvenAfterQueries(tt.in, tt.queries) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/sum-of-root-to-leaf-binary-numbers/sum_of_root_to_leaf_binary_numbers_test.go b/problems/sum-of-root-to-leaf-binary-numbers/sum_of_root_to_leaf_binary_numbers_test.go index f95ab89f0..f1e9535c5 100644 --- a/problems/sum-of-root-to-leaf-binary-numbers/sum_of_root_to_leaf_binary_numbers_test.go +++ b/problems/sum-of-root-to-leaf-binary-numbers/sum_of_root_to_leaf_binary_numbers_test.go @@ -6,30 +6,30 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestSumRootToLeaf(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 0, 1, 0, 1, 0, 1}, - expected: 22, + in: []int{1, 0, 1, 0, 1, 0, 1}, + want: 22, }, { - input: []int{1, 1}, - expected: 3, + in: []int{1, 1}, + want: 3, }, { - input: []int{1, kit.NULL, 0}, - expected: 2, + in: []int{1, kit.NULL, 0}, + want: 2, }, } - for _, tc := range tests { - output := sumRootToLeaf(kit.SliceInt2TreeNode(tc.input)) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := sumRootToLeaf(kit.SliceInt2TreeNode(tt.in)) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/sum-of-two-integers/sum_of_two_integers_test.go b/problems/sum-of-two-integers/sum_of_two_integers_test.go index 673ba2fc7..970bc7c1d 100644 --- a/problems/sum-of-two-integers/sum_of_two_integers_test.go +++ b/problems/sum-of-two-integers/sum_of_two_integers_test.go @@ -2,29 +2,29 @@ package problem371 import "testing" -type caseType struct { - a int - b int - expected int +type testType struct { + a int + b int + want int } func TestGetSum(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - a: 1, - b: 2, - expected: 3, + a: 1, + b: 2, + want: 3, }, { - a: -2, - b: 3, - expected: 1, + a: -2, + b: 3, + want: 1, }, } - for _, tc := range tests { - output := getSum(tc.a, tc.b) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.a, tc.b, output, tc.expected) + for _, tt := range tests { + got := getSum(tt.a, tt.b) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.a, tt.b, got, tt.want) } } } diff --git a/problems/symmetric-tree/symmetric_tree_test.go b/problems/symmetric-tree/symmetric_tree_test.go index 70c1f78f2..ea0d1a635 100644 --- a/problems/symmetric-tree/symmetric_tree_test.go +++ b/problems/symmetric-tree/symmetric_tree_test.go @@ -6,26 +6,26 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestIsSymmetric(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 2, 3, 4, 4, 3}, - expected: true, + in: []int{1, 2, 2, 3, 4, 4, 3}, + want: true, }, { - input: []int{1, 2, 2, kit.NULL, 3, kit.NULL, 3}, - expected: false, + in: []int{1, 2, 2, kit.NULL, 3, kit.NULL, 3}, + want: false, }, } - for _, tc := range tests { - output := isSymmetric(kit.SliceInt2TreeNode(tc.input)) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isSymmetric(kit.SliceInt2TreeNode(tt.in)) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/third-maximum-number/third_maximum_number_test.go b/problems/third-maximum-number/third_maximum_number_test.go index 34d0807ea..86338922d 100644 --- a/problems/third-maximum-number/third_maximum_number_test.go +++ b/problems/third-maximum-number/third_maximum_number_test.go @@ -2,42 +2,42 @@ package problem414 import "testing" -type caseType struct { - input []int - expected int +type testType struct { + in []int + want int } func TestThirdMax(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 2, 5, 3, 5}, - expected: 2, + in: []int{1, 2, 2, 5, 3, 5}, + want: 2, }, { - input: []int{1, 2, 2}, - expected: 2, + in: []int{1, 2, 2}, + want: 2, }, { - input: []int{1, 1, 2}, - expected: 2, + in: []int{1, 1, 2}, + want: 2, }, { - input: []int{3, 2, 1}, - expected: 1, + in: []int{3, 2, 1}, + want: 1, }, { - input: []int{1, 2}, - expected: 2, + in: []int{1, 2}, + want: 2, }, { - input: []int{2, 2, 3, 1}, - expected: 1, + in: []int{2, 2, 3, 1}, + want: 1, }, } - for _, tc := range tests { - output := thirdMax(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := thirdMax(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/to-lower-case/to_lower_case_test.go b/problems/to-lower-case/to_lower_case_test.go index 79f85b560..c8973390e 100644 --- a/problems/to-lower-case/to_lower_case_test.go +++ b/problems/to-lower-case/to_lower_case_test.go @@ -10,10 +10,10 @@ func TestToLowerCase(t *testing.T) { "OpenSet": "openset", } - for input, expected := range tests { - output := toLowerCase(input) - if output != expected { - t.Fatalf("input: %v, output: %v, expected: %v", input, output, expected) + for in, want := range tests { + got := toLowerCase(in) + if got != want { + t.Fatalf("in: %v, got: %v, want: %v", in, got, want) } } } diff --git a/problems/toeplitz-matrix/toeplitz_matrix_test.go b/problems/toeplitz-matrix/toeplitz_matrix_test.go index 8753a23ed..df54e8b12 100644 --- a/problems/toeplitz-matrix/toeplitz_matrix_test.go +++ b/problems/toeplitz-matrix/toeplitz_matrix_test.go @@ -2,33 +2,33 @@ package problem766 import "testing" -type caseType struct { - input [][]int - expected bool +type testType struct { + in [][]int + want bool } func TestIsToeplitzMatrix(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]int{ + in: [][]int{ {1, 2, 3, 4}, {5, 1, 2, 3}, {9, 5, 1, 2}, }, - expected: true, + want: true, }, { - input: [][]int{ + in: [][]int{ {1, 2}, {2, 2}, }, - expected: false, + want: false, }, } - for _, tc := range tests { - output := isToeplitzMatrix(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isToeplitzMatrix(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/transpose-matrix/transpose_matrix_test.go b/problems/transpose-matrix/transpose_matrix_test.go index 68a0678cb..cd12659e8 100644 --- a/problems/transpose-matrix/transpose_matrix_test.go +++ b/problems/transpose-matrix/transpose_matrix_test.go @@ -5,41 +5,41 @@ import ( "testing" ) -type caseType struct { - input [][]int - expected [][]int +type testType struct { + in [][]int + want [][]int } func TestTranspose(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]int{ + in: [][]int{ {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, }, - expected: [][]int{ + want: [][]int{ {1, 4, 7}, {2, 5, 8}, {3, 6, 9}, }, }, { - input: [][]int{ + in: [][]int{ {1, 2, 3}, {4, 5, 6}, }, - expected: [][]int{ + want: [][]int{ {1, 4}, {2, 5}, {3, 6}, }, }, } - for _, tc := range tests { - output := transpose(tc.input) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := transpose(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/two-city-scheduling/two_city_scheduling_test.go b/problems/two-city-scheduling/two_city_scheduling_test.go index 11ba9abb9..00ec9619a 100644 --- a/problems/two-city-scheduling/two_city_scheduling_test.go +++ b/problems/two-city-scheduling/two_city_scheduling_test.go @@ -2,24 +2,24 @@ package problem1029 import "testing" -type caseType struct { - input [][]int - expected int +type testType struct { + in [][]int + want int } func TestTwoCitySchedCost(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]int{ + in: [][]int{ {10, 20}, {30, 200}, {400, 50}, {30, 20}, }, - expected: 110, + want: 110, }, { - input: [][]int{ + in: [][]int{ {259, 770}, {448, 54}, {926, 667}, @@ -27,10 +27,10 @@ func TestTwoCitySchedCost(t *testing.T) { {840, 118}, {577, 469}, }, - expected: 1859, + want: 1859, }, { - input: [][]int{ + in: [][]int{ {918, 704}, {77, 778}, {239, 457}, @@ -46,13 +46,13 @@ func TestTwoCitySchedCost(t *testing.T) { {384, 585}, {165, 54}, }, - expected: 4532, + want: 4532, }, } - for _, tc := range tests { - output := twoCitySchedCost(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := twoCitySchedCost(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/two-sum-ii-input-array-is-sorted/two_sum_ii_input_array_is_sorted_test.go b/problems/two-sum-ii-input-array-is-sorted/two_sum_ii_input_array_is_sorted_test.go index 533e7b829..432b299db 100644 --- a/problems/two-sum-ii-input-array-is-sorted/two_sum_ii_input_array_is_sorted_test.go +++ b/problems/two-sum-ii-input-array-is-sorted/two_sum_ii_input_array_is_sorted_test.go @@ -5,40 +5,40 @@ import ( "testing" ) -type caseType struct { - nums []int - target int - expected []int +type testType struct { + nums []int + target int + want []int } func TestTwoSum(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - nums: []int{2, 7, 11, 15}, - target: 9, - expected: []int{1, 2}, + nums: []int{2, 7, 11, 15}, + target: 9, + want: []int{1, 2}, }, { - nums: []int{2, 7, 11, 15}, - target: 10, - expected: nil, + nums: []int{2, 7, 11, 15}, + target: 10, + want: nil, }, { - nums: []int{1, 3, 5, 7, 9, 12}, - target: 16, - expected: []int{4, 5}, + nums: []int{1, 3, 5, 7, 9, 12}, + target: 16, + want: []int{4, 5}, }, { - nums: []int{1, 2, 3, 4}, - target: 6, - expected: []int{2, 4}, + nums: []int{1, 2, 3, 4}, + target: 6, + want: []int{2, 4}, }, } - for _, tc := range tests { - output := twoSum(tc.nums, tc.target) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.nums, output, tc.expected) + for _, tt := range tests { + got := twoSum(tt.nums, tt.target) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.nums, got, tt.want) } } } diff --git a/problems/two-sum/two_sum_test.go b/problems/two-sum/two_sum_test.go index 2b714b3be..1236c35d9 100644 --- a/problems/two-sum/two_sum_test.go +++ b/problems/two-sum/two_sum_test.go @@ -5,34 +5,34 @@ import ( "testing" ) -type caseType struct { - nums []int - target int - expected []int +type testType struct { + nums []int + target int + want []int } func TestTwoSum(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - nums: []int{2, 7, 11, 15}, - target: 9, - expected: []int{0, 1}, + nums: []int{2, 7, 11, 15}, + target: 9, + want: []int{0, 1}, }, { - nums: []int{2, 7, 11, 15}, - target: 10, - expected: nil, + nums: []int{2, 7, 11, 15}, + target: 10, + want: nil, }, { - nums: []int{1, 2, 3, 4}, - target: 5, - expected: []int{1, 2}, + nums: []int{1, 2, 3, 4}, + target: 5, + want: []int{1, 2}, }, } - for _, tc := range tests { - output := twoSum(tc.nums, tc.target) - if !reflect.DeepEqual(output, tc.expected) { - t.Fatalf("input: %v, output: %v, expected: %v", tc.nums, output, tc.expected) + for _, tt := range tests { + got := twoSum(tt.nums, tt.target) + if !reflect.DeepEqual(got, tt.want) { + t.Fatalf("in: %v, got: %v, want: %v", tt.nums, got, tt.want) } } } diff --git a/problems/ugly-number-ii/ugly_number_ii_test.go b/problems/ugly-number-ii/ugly_number_ii_test.go index 70fe7a6da..45cf5fd00 100644 --- a/problems/ugly-number-ii/ugly_number_ii_test.go +++ b/problems/ugly-number-ii/ugly_number_ii_test.go @@ -2,38 +2,38 @@ package problem264 import "testing" -type caseType struct { - input int - expected int +type testType struct { + in int + want int } func TestNthUglyNumber(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 10, - expected: 12, + in: 10, + want: 12, }, { - input: 9, - expected: 10, + in: 9, + want: 10, }, { - input: 60, - expected: 384, + in: 60, + want: 384, }, { - input: 90, - expected: 1152, + in: 90, + want: 1152, }, { - input: 1, - expected: 1, + in: 1, + want: 1, }, } - for _, tc := range tests { - output := nthUglyNumber(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := nthUglyNumber(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/ugly-number/ugly_number_test.go b/problems/ugly-number/ugly_number_test.go index 914b3e058..0d74ba9dc 100644 --- a/problems/ugly-number/ugly_number_test.go +++ b/problems/ugly-number/ugly_number_test.go @@ -2,42 +2,42 @@ package problem263 import "testing" -type caseType struct { - input int - expected bool +type testType struct { + in int + want bool } func TestIsUgly(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: 1, - expected: true, + in: 1, + want: true, }, { - input: 6, - expected: true, + in: 6, + want: true, }, { - input: 8, - expected: true, + in: 8, + want: true, }, { - input: 14, - expected: false, + in: 14, + want: false, }, { - input: 0, - expected: false, + in: 0, + want: false, }, { - input: -30, - expected: false, + in: -30, + want: false, }, } - for _, tc := range tests { - output := isUgly(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isUgly(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/unique-email-addresses/unique_email_addresses_test.go b/problems/unique-email-addresses/unique_email_addresses_test.go index 842db5fba..4b25e1d09 100644 --- a/problems/unique-email-addresses/unique_email_addresses_test.go +++ b/problems/unique-email-addresses/unique_email_addresses_test.go @@ -2,27 +2,27 @@ package problem929 import "testing" -type caseType struct { - input []string - expected int +type testType struct { + in []string + want int } func TestNumUniqueEmails(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []string{"test.email+alex@leetcode.com", "test.e.mail+bob.cathy@leetcode.com", "testemail+david@lee.tcode.com"}, - expected: 2, + in: []string{"test.email+alex@leetcode.com", "test.e.mail+bob.cathy@leetcode.com", "testemail+david@lee.ttode.com"}, + want: 2, }, { - input: []string{"sandy+wang@openset.wang", "openset.wang@openset.com", "openset+wang@openset.com"}, - expected: 3, + in: []string{"sandy+wang@openset.wang", "openset.wang@openset.com", "openset+wang@openset.com"}, + want: 3, }, } - for _, tc := range tests { - output := numUniqueEmails(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := numUniqueEmails(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/unique-morse-code-words/unique_morse_code_words_test.go b/problems/unique-morse-code-words/unique_morse_code_words_test.go index 6886c4f3d..4abf94755 100644 --- a/problems/unique-morse-code-words/unique_morse_code_words_test.go +++ b/problems/unique-morse-code-words/unique_morse_code_words_test.go @@ -2,26 +2,26 @@ package problem804 import "testing" -type caseType struct { - input []string - expected int +type testType struct { + in []string + want int } func TestUniqueMorseRepresentations(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []string{"gin", "zen", "gig", "msg"}, - expected: 2, + in: []string{"gin", "zen", "gig", "msg"}, + want: 2, }, { - input: []string{"hello", "word"}, - expected: 2, + in: []string{"hello", "word"}, + want: 2, }, } - for _, tc := range tests { - output := uniqueMorseRepresentations(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := uniqueMorseRepresentations(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/univalued-binary-tree/univalued_binary_tree_test.go b/problems/univalued-binary-tree/univalued_binary_tree_test.go index 822e212fd..e2948682c 100644 --- a/problems/univalued-binary-tree/univalued_binary_tree_test.go +++ b/problems/univalued-binary-tree/univalued_binary_tree_test.go @@ -6,30 +6,30 @@ import ( "github.com/openset/leetcode/internal/kit" ) -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestIsUnivalTree(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 1, 1, 1, 1, kit.NULL, 1}, - expected: true, + in: []int{1, 1, 1, 1, 1, kit.NULL, 1}, + want: true, }, { - input: []int{2, 2, 2, 5, 2}, - expected: false, + in: []int{2, 2, 2, 5, 2}, + want: false, }, { - input: []int{3, 3, 3, 3, 5}, - expected: false, + in: []int{3, 3, 3, 3, 5}, + want: false, }, } - for _, tc := range tests { - output := isUnivalTree(kit.SliceInt2TreeNode(tc.input)) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isUnivalTree(kit.SliceInt2TreeNode(tt.in)) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/utf-8-validation/utf_8_validation_test.go b/problems/utf-8-validation/utf_8_validation_test.go index fe0a5cf3b..4588c16d3 100644 --- a/problems/utf-8-validation/utf_8_validation_test.go +++ b/problems/utf-8-validation/utf_8_validation_test.go @@ -2,38 +2,38 @@ package problem393 import "testing" -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestValidUtf8(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{197}, - expected: false, + in: []int{197}, + want: false, }, { - input: []int{197, 130, 1}, - expected: true, + in: []int{197, 130, 1}, + want: true, }, { - input: []int{235, 140, 4}, - expected: false, + in: []int{235, 140, 4}, + want: false, }, { - input: []int{248}, - expected: false, + in: []int{248}, + want: false, }, { - input: []int{194, 155, 231, 184, 185, 246, 176, 131, 161, 222, 174, 227, 162, 134, 241, 154, 168, 185, 218, 178, 229, 187, 139, 246, 178, 187, 139, 204, 146, 225, 148, 179, 245, 139, 172, 134, 193, 156, 233, 131, 154, 240, 166, 188, 190, 216, 150, 230, 145, 144, 240, 167, 140, 163, 221, 190, 238, 168, 139, 241, 154, 159, 164, 199, 170, 224, 173, 140, 244, 182, 143, 134, 206, 181, 227, 172, 141, 241, 146, 159, 170, 202, 134, 230, 142, 163, 244, 172, 140, 191}, - expected: true, + in: []int{194, 155, 231, 184, 185, 246, 176, 131, 161, 222, 174, 227, 162, 134, 241, 154, 168, 185, 218, 178, 229, 187, 139, 246, 178, 187, 139, 204, 146, 225, 148, 179, 245, 139, 172, 134, 193, 156, 233, 131, 154, 240, 166, 188, 190, 216, 150, 230, 145, 144, 240, 167, 140, 163, 221, 190, 238, 168, 139, 241, 154, 159, 164, 199, 170, 224, 173, 140, 244, 182, 143, 134, 206, 181, 227, 172, 141, 241, 146, 159, 170, 202, 134, 230, 142, 163, 244, 172, 140, 191}, + want: true, }, } - for _, tc := range tests { - output := validUtf8(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := validUtf8(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/valid-anagram/valid_anagram_test.go b/problems/valid-anagram/valid_anagram_test.go index a4db07f20..10899056d 100644 --- a/problems/valid-anagram/valid_anagram_test.go +++ b/problems/valid-anagram/valid_anagram_test.go @@ -2,45 +2,45 @@ package problem242 import "testing" -type caseType struct { - s string - t string - expected bool +type testType struct { + s string + t string + want bool } func TestIsAnagram(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - s: "anagram", - t: "nagaram", - expected: true, + s: "anagram", + t: "nagaram", + want: true, }, { - s: "hannah", - t: "hanna", - expected: false, + s: "hannah", + t: "hanna", + want: false, }, { - s: "this is string", - t: "this is string long", - expected: false, + s: "this is string", + t: "this is string long", + want: false, }, { - s: "this is string", - t: "this as string", - expected: false, + s: "this is string", + t: "this as string", + want: false, }, { - s: "你好,世界", - t: "世界,你好", - expected: true, + s: "你好,世界", + t: "世界,你好", + want: true, }, } - for _, tc := range tests { - output := isAnagram(tc.s, tc.t) - if output != tc.expected { - t.Fatalf("input: %v %v, output: %v, expected: %v", tc.s, tc.t, output, tc.expected) + for _, tt := range tests { + got := isAnagram(tt.s, tt.t) + if got != tt.want { + t.Fatalf("in: %v %v, got: %v, want: %v", tt.s, tt.t, got, tt.want) } } } diff --git a/problems/valid-boomerang/valid_boomerang_test.go b/problems/valid-boomerang/valid_boomerang_test.go index 6b457ed9b..b9cc50f73 100644 --- a/problems/valid-boomerang/valid_boomerang_test.go +++ b/problems/valid-boomerang/valid_boomerang_test.go @@ -2,34 +2,34 @@ package problem1037 import "testing" -type caseType struct { - input [][]int - expected bool +type testType struct { + in [][]int + want bool } func TestIsBoomerang(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]int{ + in: [][]int{ {1, 1}, {2, 3}, {3, 2}, }, - expected: true, + want: true, }, { - input: [][]int{ + in: [][]int{ {1, 1}, {2, 2}, {3, 3}, }, - expected: false, + want: false, }, } - for _, tc := range tests { - output := isBoomerang(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isBoomerang(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/valid-mountain-array/valid_mountain_array_test.go b/problems/valid-mountain-array/valid_mountain_array_test.go index ad10593fd..e0d0f2ab6 100644 --- a/problems/valid-mountain-array/valid_mountain_array_test.go +++ b/problems/valid-mountain-array/valid_mountain_array_test.go @@ -2,42 +2,42 @@ package problem941 import "testing" -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestValidMountainArray(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{2, 1}, - expected: false, + in: []int{2, 1}, + want: false, }, { - input: []int{3, 5, 5}, - expected: false, + in: []int{3, 5, 5}, + want: false, }, { - input: []int{0, 3, 2, 1}, - expected: true, + in: []int{0, 3, 2, 1}, + want: true, }, { - input: []int{1, 2, 3, 2}, - expected: true, + in: []int{1, 2, 3, 2}, + want: true, }, { - input: []int{9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - expected: false, + in: []int{9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + want: false, }, { - input: []int{1, 2, 3, 4, 5}, - expected: false, + in: []int{1, 2, 3, 4, 5}, + want: false, }, } - for _, tc := range tests { - output := validMountainArray(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := validMountainArray(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/valid-number/valid_number_test.go b/problems/valid-number/valid_number_test.go index dfd10e691..ed8d47f62 100644 --- a/problems/valid-number/valid_number_test.go +++ b/problems/valid-number/valid_number_test.go @@ -2,78 +2,78 @@ package problem65 import "testing" -type caseType struct { - input string - expected bool +type testType struct { + in string + want bool } func TestIsNumber(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "0", - expected: true, + in: "0", + want: true, }, { - input: " 0.1", - expected: true, + in: " 0.1", + want: true, }, { - input: "abc", - expected: false, + in: "abc", + want: false, }, { - input: "1 a", - expected: false, + in: "1 a", + want: false, }, { - input: "2e10", - expected: true, + in: "2e10", + want: true, }, { - input: " -90e3 ", - expected: true, + in: " -90e3 ", + want: true, }, { - input: " 1e", - expected: false, + in: " 1e", + want: false, }, { - input: "e3", - expected: false, + in: "e3", + want: false, }, { - input: " 6e-1", - expected: true, + in: " 6e-1", + want: true, }, { - input: " 99e2.5 ", - expected: false, + in: " 99e2.5 ", + want: false, }, { - input: "53.5e93", - expected: true, + in: "53.5e93", + want: true, }, { - input: " --6 ", - expected: false, + in: " --6 ", + want: false, }, { - input: "-+3", - expected: false, + in: "-+3", + want: false, }, { - input: "95a54e53", - expected: false, + in: "95a54e53", + want: false, }, { - input: "078332e437", - expected: true, + in: "078332e437", + want: true, }, } - for _, tc := range tests { - output := isNumber(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isNumber(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/valid-palindrome-ii/valid_palindrome_ii_test.go b/problems/valid-palindrome-ii/valid_palindrome_ii_test.go index ce60b675b..0191af625 100644 --- a/problems/valid-palindrome-ii/valid_palindrome_ii_test.go +++ b/problems/valid-palindrome-ii/valid_palindrome_ii_test.go @@ -2,38 +2,38 @@ package problem680 import "testing" -type caseType struct { - input string - expected bool +type testType struct { + in string + want bool } func TestValidPalindrome(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "aba", - expected: true, + in: "aba", + want: true, }, { - input: "abca", - expected: true, + in: "abca", + want: true, }, { - input: "hello", - expected: false, + in: "hello", + want: false, }, { - input: "abcdcbda", - expected: true, + in: "abcdcbda", + want: true, }, { - input: "abcbabbbca", - expected: false, + in: "abcbabbbca", + want: false, }, } - for _, tc := range tests { - output := validPalindrome(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := validPalindrome(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/valid-palindrome/valid_palindrome_test.go b/problems/valid-palindrome/valid_palindrome_test.go index 1d7cacda3..ce2d6f7f9 100644 --- a/problems/valid-palindrome/valid_palindrome_test.go +++ b/problems/valid-palindrome/valid_palindrome_test.go @@ -2,43 +2,43 @@ package problem125 import "testing" -type caseType struct { - input string - expected bool +type testType struct { + in string + want bool } func TestIsPalindrome(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "A man, a plan, a canal: Panama", - expected: true, + in: "A man, a plan, a canal: Panama", + want: true, }, { - input: "", - expected: true, + in: "", + want: true, }, { - input: ".", - expected: true, + in: ".", + want: true, }, { - input: "12321", - expected: true, + in: "12321", + want: true, }, { - input: "race a car", - expected: false, + in: "race a car", + want: false, }, { - input: "hello, world", - expected: false, + in: "hello, world", + want: false, }, } - for _, tc := range tests { - output := isPalindrome(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isPalindrome(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/valid-parentheses/valid_parentheses_test.go b/problems/valid-parentheses/valid_parentheses_test.go index d9d39e91b..655d91820 100644 --- a/problems/valid-parentheses/valid_parentheses_test.go +++ b/problems/valid-parentheses/valid_parentheses_test.go @@ -14,10 +14,10 @@ func TestIsValid(t *testing.T) { "([})]": false, } - for input, expected := range tests { - output := isValid(input) - if output != expected { - t.Fatalf("input: %v, output: %v, expected: %v", input, output, expected) + for in, want := range tests { + got := isValid(in) + if got != want { + t.Fatalf("in: %v, got: %v, want: %v", in, got, want) } } } diff --git a/problems/valid-sudoku/valid_sudoku_test.go b/problems/valid-sudoku/valid_sudoku_test.go index 5d169977c..9c7b72fec 100644 --- a/problems/valid-sudoku/valid_sudoku_test.go +++ b/problems/valid-sudoku/valid_sudoku_test.go @@ -2,15 +2,15 @@ package problem36 import "testing" -type caseType struct { - input [][]byte - expected bool +type testType struct { + in [][]byte + want bool } func TestIsValidSudoku(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: [][]byte{ + in: [][]byte{ {'5', '3', '.', '.', '7', '.', '.', '.', '.'}, {'6', '.', '.', '1', '9', '5', '.', '.', '.'}, {'.', '9', '8', '.', '.', '.', '.', '6', '.'}, @@ -21,10 +21,10 @@ func TestIsValidSudoku(t *testing.T) { {'.', '.', '.', '4', '1', '9', '.', '.', '5'}, {'.', '.', '.', '.', '8', '.', '.', '7', '9'}, }, - expected: true, + want: true, }, { - input: [][]byte{ + in: [][]byte{ {'5', '3', '6', '.', '7', '.', '.', '.', '.'}, {'6', '.', '.', '1', '9', '5', '.', '.', '.'}, {'.', '9', '8', '.', '.', '.', '.', '6', '.'}, @@ -35,10 +35,10 @@ func TestIsValidSudoku(t *testing.T) { {'.', '.', '.', '4', '1', '9', '.', '.', '5'}, {'.', '.', '.', '.', '8', '.', '.', '7', '9'}, }, - expected: false, + want: false, }, { - input: [][]byte{ + in: [][]byte{ {'8', '3', '.', '.', '7', '.', '.', '.', '.'}, {'6', '.', '.', '1', '9', '5', '.', '.', '.'}, {'.', '9', '8', '.', '.', '.', '.', '6', '.'}, @@ -49,10 +49,10 @@ func TestIsValidSudoku(t *testing.T) { {'.', '.', '.', '4', '1', '9', '.', '.', '5'}, {'.', '.', '.', '.', '8', '.', '.', '7', '9'}, }, - expected: false, + want: false, }, { - input: [][]byte{ + in: [][]byte{ {'8', '3', '.', '.', '3', '.', '.', '.', '.'}, {'6', '.', '.', '1', '9', '5', '.', '.', '.'}, {'.', '9', '2', '.', '.', '.', '.', '6', '.'}, @@ -63,10 +63,10 @@ func TestIsValidSudoku(t *testing.T) { {'.', '.', '.', '4', '1', '9', '.', '.', '5'}, {'.', '.', '.', '.', '8', '.', '.', '7', '9'}, }, - expected: false, + want: false, }, { - input: [][]byte{ + in: [][]byte{ {'8', '3', '.', '.', '3', '.', '.', '.', '.'}, {'6', '.', '.', '1', '9', '5', '.', '.', '.'}, {'.', '8', '2', '.', '.', '.', '.', '6', '.'}, @@ -77,14 +77,14 @@ func TestIsValidSudoku(t *testing.T) { {'.', '.', '.', '4', '1', '9', '.', '.', '5'}, {'.', '.', '.', '.', '8', '.', '.', '7', '9'}, }, - expected: false, + want: false, }, } - for _, tc := range tests { - output := isValidSudoku(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := isValidSudoku(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/validate-ip-address/validate_ip_address_test.go b/problems/validate-ip-address/validate_ip_address_test.go index 3669e8a6c..3dec640a4 100644 --- a/problems/validate-ip-address/validate_ip_address_test.go +++ b/problems/validate-ip-address/validate_ip_address_test.go @@ -2,46 +2,46 @@ package problem468 import "testing" -type caseType struct { - input string - expected string +type testType struct { + in string + want string } func TestValidIPAddress(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "172.16.254.1", - expected: "IPv4", + in: "172.16.254.1", + want: "IPv4", }, { - input: "172.16.254.01", - expected: "Neither", + in: "172.16.254.01", + want: "Neither", }, { - input: "256.256.256.256", - expected: "Neither", + in: "256.256.256.256", + want: "Neither", }, { - input: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", - expected: "IPv6", + in: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", + want: "IPv6", }, { - input: "2001:db8:85a3:0:0:8A2E:0370:7334", - expected: "IPv6", + in: "2001:db8:85a3:0:0:8A2E:0370:7334", + want: "IPv6", }, { - input: "2001:0db8:85a3::8A2E:0370:7334", - expected: "Neither", + in: "2001:0db8:85a3::8A2E:0370:7334", + want: "Neither", }, { - input: "02001:0db8:85a3:0000:0000:8a2e:0370:7334", - expected: "Neither", + in: "02001:0db8:85a3:0000:0000:8a2e:0370:7334", + want: "Neither", }, } - for _, tc := range tests { - output := validIPAddress(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := validIPAddress(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/verifying-an-alien-dictionary/verifying_an_alien_dictionary_test.go b/problems/verifying-an-alien-dictionary/verifying_an_alien_dictionary_test.go index eaf236b5c..60f69fba5 100644 --- a/problems/verifying-an-alien-dictionary/verifying_an_alien_dictionary_test.go +++ b/problems/verifying-an-alien-dictionary/verifying_an_alien_dictionary_test.go @@ -2,34 +2,34 @@ package problem953 import "testing" -type caseType struct { - words []string - order string - expected bool +type testType struct { + words []string + order string + want bool } func TestIsAlienSorted(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - words: []string{"hello", "leetcode"}, - order: "hlabcdefgijkmnopqrstuvwxyz", - expected: true, + words: []string{"hello", "leetcode"}, + order: "hlabcdefgijkmnopqrstuvwxyz", + want: true, }, { - words: []string{"word", "world", "row"}, - order: "worldabcefghijkmnpqstuvxyz", - expected: false, + words: []string{"word", "world", "row"}, + order: "worldabcefghijkmnpqstuvxyz", + want: false, }, { - words: []string{"apple", "app"}, - order: "abcdefghijklmnopqrstuvwxyz", - expected: false, + words: []string{"apple", "app"}, + order: "abcdefghijklmnopqrstuvwxyz", + want: false, }, } - for _, tc := range tests { - output := isAlienSorted(tc.words, tc.order) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.words, output, tc.expected) + for _, tt := range tests { + got := isAlienSorted(tt.words, tt.order) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.words, got, tt.want) } } } diff --git a/problems/word-break/word_break_test.go b/problems/word-break/word_break_test.go index 53f8016df..a314c3d00 100644 --- a/problems/word-break/word_break_test.go +++ b/problems/word-break/word_break_test.go @@ -2,34 +2,34 @@ package problem139 import "testing" -type caseType struct { - input string +type testType struct { + in string wordDict []string - expected bool + want bool } func TestWordBreak(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "leetcode", + in: "leetcode", wordDict: []string{"leet", "code"}, - expected: true, + want: true, }, { - input: "applepenapple", + in: "applepenapple", wordDict: []string{"apple", "pen"}, - expected: true, + want: true, }, { - input: "catsandog", + in: "catsandog", wordDict: []string{"cats", "dog", "sand", "and", "cat"}, - expected: false, + want: false, }, } - for _, tc := range tests { - output := wordBreak(tc.input, tc.wordDict) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := wordBreak(tt.in, tt.wordDict) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/word-pattern/word_pattern_test.go b/problems/word-pattern/word_pattern_test.go index 12a84e248..4df4e38b2 100644 --- a/problems/word-pattern/word_pattern_test.go +++ b/problems/word-pattern/word_pattern_test.go @@ -2,54 +2,54 @@ package problem290 import "testing" -type caseType struct { - pattern string - str string - expected bool +type testType struct { + pattern string + str string + want bool } func TestWordPattern(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - pattern: "abba", - str: "dog cat cat dog", - expected: true, + pattern: "abba", + str: "dog cat cat dog", + want: true, }, { - pattern: "abba", - str: "dog cat cat fish", - expected: false, + pattern: "abba", + str: "dog cat cat fish", + want: false, }, { - pattern: "aaaa", - str: "dog cat cat dog", - expected: false, + pattern: "aaaa", + str: "dog cat cat dog", + want: false, }, { - pattern: "abba", - str: "dog dog dog dog", - expected: false, + pattern: "abba", + str: "dog dog dog dog", + want: false, }, { - pattern: "abba", - str: "dog cat cat dog fish", - expected: false, + pattern: "abba", + str: "dog cat cat dog fish", + want: false, }, { - pattern: "abba", - str: "b a a b", - expected: true, + pattern: "abba", + str: "b a a b", + want: true, }, { - pattern: "abba", - str: "b c c b", - expected: true, + pattern: "abba", + str: "b c c b", + want: true, }, } - for _, tc := range tests { - output := wordPattern(tc.pattern, tc.str) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.pattern, output, tc.expected) + for _, tt := range tests { + got := wordPattern(tt.pattern, tt.str) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.pattern, got, tt.want) } } } diff --git a/problems/x-of-a-kind-in-a-deck-of-cards/x_of_a_kind_in_a_deck_of_cards_test.go b/problems/x-of-a-kind-in-a-deck-of-cards/x_of_a_kind_in_a_deck_of_cards_test.go index b2afecfe3..ef2ea13d4 100644 --- a/problems/x-of-a-kind-in-a-deck-of-cards/x_of_a_kind_in_a_deck_of_cards_test.go +++ b/problems/x-of-a-kind-in-a-deck-of-cards/x_of_a_kind_in_a_deck_of_cards_test.go @@ -2,38 +2,38 @@ package problem914 import "testing" -type caseType struct { - input []int - expected bool +type testType struct { + in []int + want bool } func TestHasGroupsSizeX(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: []int{1, 2, 3, 4, 4, 3, 2, 1}, - expected: true, + in: []int{1, 2, 3, 4, 4, 3, 2, 1}, + want: true, }, { - input: []int{1, 1, 1, 2, 2, 2, 3, 3}, - expected: false, + in: []int{1, 1, 1, 2, 2, 2, 3, 3}, + want: false, }, { - input: []int{1}, - expected: false, + in: []int{1}, + want: false, }, { - input: []int{1, 1}, - expected: true, + in: []int{1, 1}, + want: true, }, { - input: []int{1, 1, 2, 2, 2, 2}, - expected: true, + in: []int{1, 1, 2, 2, 2, 2}, + want: true, }, } - for _, tc := range tests { - output := hasGroupsSizeX(tc.input) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := hasGroupsSizeX(tt.in) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } } diff --git a/problems/zigzag-conversion/zigzag_conversion_test.go b/problems/zigzag-conversion/zigzag_conversion_test.go index c01116a01..b23fa2c22 100644 --- a/problems/zigzag-conversion/zigzag_conversion_test.go +++ b/problems/zigzag-conversion/zigzag_conversion_test.go @@ -2,34 +2,34 @@ package problem6 import "testing" -type caseType struct { - input string - numRows int - expected string +type testType struct { + in string + numRows int + want string } func TestConvert(t *testing.T) { - tests := [...]caseType{ + tests := [...]testType{ { - input: "PAYPALISHIRING", - numRows: 3, - expected: "PAHNAPLSIIGYIR", + in: "PAYPALISHIRING", + numRows: 3, + want: "PAHNAPLSIIGYIR", }, { - input: "PAYPALISHIRING", - numRows: 4, - expected: "PINALSIGYAHRPI", + in: "PAYPALISHIRING", + numRows: 4, + want: "PINALSIGYAHRPI", }, { - input: "AB", - numRows: 1, - expected: "AB", + in: "AB", + numRows: 1, + want: "AB", }, } - for _, tc := range tests { - output := convert(tc.input, tc.numRows) - if output != tc.expected { - t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected) + for _, tt := range tests { + got := convert(tt.in, tt.numRows) + if got != tt.want { + t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want) } } }