From 5004d75780eb9c804cfe8d4bf91748a8de2a9bb0 Mon Sep 17 00:00:00 2001 From: fartem Date: Thu, 8 May 2025 09:15:24 +0300 Subject: [PATCH] 2025-05-08 v. 1.0.9: refactored tests --- pubspec.yaml | 2 +- test/easy/100_same_tree_test.dart | 6 +++--- test/easy/101_symmetric_tree_test.dart | 4 ++-- .../104_maximum_depth_of_binary_tree_test.dart | 4 ++-- ...rt_sorted_array_to_binary_search_tree_test.dart | 4 ++-- test/easy/110_balanced_binary_tree_test.dart | 4 ++-- .../111_minimum_depth_of_binary_tree_test.dart | 4 ++-- test/easy/112_path_sum_test.dart | 6 +++--- test/easy/118_pascals_triangle_test.dart | 4 ++-- test/easy/13_roman_to_integer_test.dart | 6 +++--- test/easy/14_longest_common_prefix_test.dart | 4 ++-- test/easy/1_two_sum_test.dart | 6 +++--- test/easy/20_valid_parentheses_test.dart | 6 +++--- test/easy/21_merge_two_sorted_lists_test.dart | 6 +++--- test/easy/263_ugly_number_test.dart | 6 +++--- test/easy/27_remove_element_test.dart | 4 ++-- ...nt_the_number_of_special_characters_i_test.dart | 8 +++----- test/easy/3280_convert_date_to_binary_test.dart | 4 ++-- test/easy/3340_check_balanced_string_test.dart | 4 ++-- test/easy/3516_find_closest_person.dart_test.dart | 6 +++--- .../3536_maximum_product_of_two_digits_test.dart | 6 +++--- test/easy/35_search_insert_position_test.dart | 6 +++--- test/easy/500_keyboard_row_test.dart | 6 ++---- test/easy/58_length_of_last_word_test.dart | 6 +++--- test/easy/66_plus_one_test.dart | 6 +++--- test/easy/67_add_binary_test.dart | 14 ++++++++++---- test/easy/69_sqrt_x_test.dart | 4 ++-- test/easy/70_climbing_stairs_test.dart | 4 ++-- ...83_remove_duplicates_from_sorted_list_test.dart | 4 ++-- test/easy/88_merge_sorted_array_test.dart | 11 +++++++---- .../94_binary_tree_inorder_traversal_test.dart | 6 +++--- test/easy/9_palindrome_number_test.dart | 6 +++--- 32 files changed, 91 insertions(+), 86 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index c32ba70..6baffca 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: leetcode_dart description: Some solved problems from https://leetcode.com on Dart -version: 1.0.8 +version: 1.0.9 homepage: https://github.com/fartem/leetcode-dart environment: diff --git a/test/easy/100_same_tree_test.dart b/test/easy/100_same_tree_test.dart index 70ed5bf..7bd76b0 100644 --- a/test/easy/100_same_tree_test.dart +++ b/test/easy/100_same_tree_test.dart @@ -9,7 +9,7 @@ void main() { final solution = Solution(); test( - 'true', + 'Test case 1', () => expect( true, solution.isSameTree( @@ -27,7 +27,7 @@ void main() { ), ); test( - 'false', + 'Test case 2', () => expect( false, solution.isSameTree( @@ -44,7 +44,7 @@ void main() { ), ); test( - 'false', + 'Test case 3', () => expect( false, solution.isSameTree( diff --git a/test/easy/101_symmetric_tree_test.dart b/test/easy/101_symmetric_tree_test.dart index 0d7d86d..e2e56bf 100644 --- a/test/easy/101_symmetric_tree_test.dart +++ b/test/easy/101_symmetric_tree_test.dart @@ -9,7 +9,7 @@ void main() { final solution = Solution(); test( - 'true', + 'Test case 1', () => expect( true, solution.isSymmetric( @@ -30,7 +30,7 @@ void main() { ), ); test( - 'false', + 'Test case 2', () => expect( false, solution.isSymmetric( diff --git a/test/easy/104_maximum_depth_of_binary_tree_test.dart b/test/easy/104_maximum_depth_of_binary_tree_test.dart index 53b4c22..1cb668a 100644 --- a/test/easy/104_maximum_depth_of_binary_tree_test.dart +++ b/test/easy/104_maximum_depth_of_binary_tree_test.dart @@ -9,7 +9,7 @@ void main() { final solution = Solution(); test( - '3', + 'Test case 1', () => expect( 3, solution.maxDepth( @@ -26,7 +26,7 @@ void main() { ), ); test( - '2', + 'Test case 2', () => expect( 2, solution.maxDepth( diff --git a/test/easy/108_convert_sorted_array_to_binary_search_tree_test.dart b/test/easy/108_convert_sorted_array_to_binary_search_tree_test.dart index 1d35627..2d9f217 100644 --- a/test/easy/108_convert_sorted_array_to_binary_search_tree_test.dart +++ b/test/easy/108_convert_sorted_array_to_binary_search_tree_test.dart @@ -11,7 +11,7 @@ void main() { final solution = Solution(); test( - '[0, -10, 5, null, -3, null, 9]', + 'Test case 1', () => expect( true, BinaryTreeHelper.areEqual( @@ -35,7 +35,7 @@ void main() { ), ); test( - '3, null, 1', + 'Test case 2', () => expect( true, BinaryTreeHelper.areEqual( diff --git a/test/easy/110_balanced_binary_tree_test.dart b/test/easy/110_balanced_binary_tree_test.dart index 7df0964..7bad444 100644 --- a/test/easy/110_balanced_binary_tree_test.dart +++ b/test/easy/110_balanced_binary_tree_test.dart @@ -9,7 +9,7 @@ void main() { final solution = Solution(); test( - 'true', + 'Test case 1', () => expect( true, solution.isBalanced( @@ -26,7 +26,7 @@ void main() { ), ); test( - 'false', + 'Test case 2', () => expect( false, solution.isBalanced( diff --git a/test/easy/111_minimum_depth_of_binary_tree_test.dart b/test/easy/111_minimum_depth_of_binary_tree_test.dart index e2c23c6..0b70c51 100644 --- a/test/easy/111_minimum_depth_of_binary_tree_test.dart +++ b/test/easy/111_minimum_depth_of_binary_tree_test.dart @@ -9,7 +9,7 @@ void main() { final solution = Solution(); test( - '2', + 'Test case 1', () => expect( 2, solution.minDepth( @@ -26,7 +26,7 @@ void main() { ), ); test( - '5', + 'Test case 2', () => expect( 5, solution.minDepth( diff --git a/test/easy/112_path_sum_test.dart b/test/easy/112_path_sum_test.dart index 08d8f86..2562541 100644 --- a/test/easy/112_path_sum_test.dart +++ b/test/easy/112_path_sum_test.dart @@ -9,7 +9,7 @@ void main() { final solution = Solution(); test( - 'true', + 'Test case 1', () => expect( true, solution.hasPathSum( @@ -41,7 +41,7 @@ void main() { ), ); test( - 'false', + 'Test case 2', () => expect( false, solution.hasPathSum( @@ -55,7 +55,7 @@ void main() { ), ); test( - 'false', + 'Test case 3', () => expect( false, solution.hasPathSum( diff --git a/test/easy/118_pascals_triangle_test.dart b/test/easy/118_pascals_triangle_test.dart index 7f6246f..fd3e053 100644 --- a/test/easy/118_pascals_triangle_test.dart +++ b/test/easy/118_pascals_triangle_test.dart @@ -8,7 +8,7 @@ void main() { final solution = Solution(); test( - '[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]', + 'Test case 1', () => expect( [ [1], @@ -21,7 +21,7 @@ void main() { ), ); test( - '[1]', + 'Test case 2', () => expect( [ [1], diff --git a/test/easy/13_roman_to_integer_test.dart b/test/easy/13_roman_to_integer_test.dart index a3fb7cf..8bac182 100644 --- a/test/easy/13_roman_to_integer_test.dart +++ b/test/easy/13_roman_to_integer_test.dart @@ -8,21 +8,21 @@ void main() { final solution = Solution(); test( - '3', + 'Test case 1', () => expect( 3, solution.romanToInt('III'), ), ); test( - '58', + 'Test case 2', () => expect( 58, solution.romanToInt('LVIII'), ), ); test( - '1994', + 'Test case 3', () => expect( 1994, solution.romanToInt('MCMXCIV'), diff --git a/test/easy/14_longest_common_prefix_test.dart b/test/easy/14_longest_common_prefix_test.dart index 8058b66..9f01366 100644 --- a/test/easy/14_longest_common_prefix_test.dart +++ b/test/easy/14_longest_common_prefix_test.dart @@ -8,7 +8,7 @@ void main() { final solution = Solution(); test( - 'fl', + 'Test case 1', () => expect( 'fl', solution.longestCommonPrefix( @@ -17,7 +17,7 @@ void main() { ), ); test( - '', + 'Test case 2', () => expect( '', solution.longestCommonPrefix( diff --git a/test/easy/1_two_sum_test.dart b/test/easy/1_two_sum_test.dart index c600bce..3214b8a 100644 --- a/test/easy/1_two_sum_test.dart +++ b/test/easy/1_two_sum_test.dart @@ -8,7 +8,7 @@ void main() { final solution = Solution(); test( - '0, 1', + 'Test case 1', () => expect( [0, 1], solution.twoSum( @@ -18,7 +18,7 @@ void main() { ), ); test( - '1, 2', + 'Test case 2', () => expect( [1, 2], solution.twoSum( @@ -28,7 +28,7 @@ void main() { ), ); test( - '0, 1', + 'Test case 3', () => expect( [0, 1], solution.twoSum( diff --git a/test/easy/20_valid_parentheses_test.dart b/test/easy/20_valid_parentheses_test.dart index 31738e1..45c23ac 100644 --- a/test/easy/20_valid_parentheses_test.dart +++ b/test/easy/20_valid_parentheses_test.dart @@ -8,21 +8,21 @@ void main() { final solution = Solution(); test( - 'true', + 'Test case 1', () => expect( true, solution.isValid('()'), ), ); test( - 'true', + 'Test case 2', () => expect( true, solution.isValid('()[]{}'), ), ); test( - 'false', + 'Test case 3', () => expect( false, solution.isValid('(]'), diff --git a/test/easy/21_merge_two_sorted_lists_test.dart b/test/easy/21_merge_two_sorted_lists_test.dart index 1599bcf..2d1abc7 100644 --- a/test/easy/21_merge_two_sorted_lists_test.dart +++ b/test/easy/21_merge_two_sorted_lists_test.dart @@ -11,7 +11,7 @@ void main() { final solution = Solution(); test( - '[1, 1, 2, 3, 4, 4]', + 'Test case 1', () => expect( true, LinkedListHelper.areEqual( @@ -30,7 +30,7 @@ void main() { ), ); test( - '[]', + 'Test case 2', () => expect( true, LinkedListHelper.areEqual( @@ -43,7 +43,7 @@ void main() { ), ); test( - '[0]', + 'Test case 3', () => expect( true, LinkedListHelper.areEqual( diff --git a/test/easy/263_ugly_number_test.dart b/test/easy/263_ugly_number_test.dart index 59ed44c..8f2d5c2 100644 --- a/test/easy/263_ugly_number_test.dart +++ b/test/easy/263_ugly_number_test.dart @@ -8,21 +8,21 @@ void main() { final solution = Solution(); test( - '6', + 'Test case 1', () => expect( true, solution.isUgly(6), ), ); test( - '1', + 'Test case 2', () => expect( true, solution.isUgly(6), ), ); test( - '14', + 'Test case 3', () => expect( true, solution.isUgly(6), diff --git a/test/easy/27_remove_element_test.dart b/test/easy/27_remove_element_test.dart index b2c3530..b500da5 100644 --- a/test/easy/27_remove_element_test.dart +++ b/test/easy/27_remove_element_test.dart @@ -8,7 +8,7 @@ void main() { final solution = Solution(); test( - '2', + 'Test case 1', () => expect( 2, solution.removeElement( @@ -18,7 +18,7 @@ void main() { ), ); test( - '5', + 'Test case 2', () => expect( 5, solution.removeElement( diff --git a/test/easy/3120_count_the_number_of_special_characters_i_test.dart b/test/easy/3120_count_the_number_of_special_characters_i_test.dart index 1c20688..8ac8454 100644 --- a/test/easy/3120_count_the_number_of_special_characters_i_test.dart +++ b/test/easy/3120_count_the_number_of_special_characters_i_test.dart @@ -8,7 +8,7 @@ void main() { final solution = Solution(); test( - '3', + 'Test case 1', () => expect( 3, solution.numberOfSpecialChars( @@ -16,9 +16,8 @@ void main() { ), ), ); - test( - '0', + 'Test case 2', () => expect( 0, solution.numberOfSpecialChars( @@ -26,9 +25,8 @@ void main() { ), ), ); - test( - '1', + 'Test case 3', () => expect( 1, solution.numberOfSpecialChars( diff --git a/test/easy/3280_convert_date_to_binary_test.dart b/test/easy/3280_convert_date_to_binary_test.dart index e309b9b..0a76252 100644 --- a/test/easy/3280_convert_date_to_binary_test.dart +++ b/test/easy/3280_convert_date_to_binary_test.dart @@ -8,7 +8,7 @@ void main() { final solution = Solution(); test( - '100000100000-10-11101', + 'Test case 1', () => expect( '100000100000-10-11101', solution.convertDateToBinary( @@ -17,7 +17,7 @@ void main() { ), ); test( - '11101101100-1-1', + 'Test case 2', () => expect( '11101101100-1-1', solution.convertDateToBinary( diff --git a/test/easy/3340_check_balanced_string_test.dart b/test/easy/3340_check_balanced_string_test.dart index 2229fed..a0c6ad6 100644 --- a/test/easy/3340_check_balanced_string_test.dart +++ b/test/easy/3340_check_balanced_string_test.dart @@ -8,7 +8,7 @@ void main() { final solution = Solution(); test( - 'false', + 'Test case 1', () => expect( false, solution.isBalanced( @@ -17,7 +17,7 @@ void main() { ), ); test( - 'true', + 'Test case 2', () => expect( true, solution.isBalanced( diff --git a/test/easy/3516_find_closest_person.dart_test.dart b/test/easy/3516_find_closest_person.dart_test.dart index dd9469f..834cb57 100644 --- a/test/easy/3516_find_closest_person.dart_test.dart +++ b/test/easy/3516_find_closest_person.dart_test.dart @@ -8,21 +8,21 @@ void main() { final solution = Solution(); test( - '1', + 'Test case 1', () => expect( 1, solution.findClosest(2, 7, 4), ), ); test( - '2', + 'Test case 2', () => expect( 2, solution.findClosest(2, 5, 6), ), ); test( - '0', + 'Test case 3', () => expect( 0, solution.findClosest(1, 5, 3), diff --git a/test/easy/3536_maximum_product_of_two_digits_test.dart b/test/easy/3536_maximum_product_of_two_digits_test.dart index 9115916..aedcd10 100644 --- a/test/easy/3536_maximum_product_of_two_digits_test.dart +++ b/test/easy/3536_maximum_product_of_two_digits_test.dart @@ -8,21 +8,21 @@ void main() { final solution = Solution(); test( - '3', + 'Test case 1', () => expect( 3, solution.maxProduct(31), ), ); test( - '4', + 'Test case 2', () => expect( 4, solution.maxProduct(22), ), ); test( - '8', + 'Test case 3', () => expect( 8, solution.maxProduct(124), diff --git a/test/easy/35_search_insert_position_test.dart b/test/easy/35_search_insert_position_test.dart index abb7a74..8e0b785 100644 --- a/test/easy/35_search_insert_position_test.dart +++ b/test/easy/35_search_insert_position_test.dart @@ -8,7 +8,7 @@ void main() { final solution = Solution(); test( - '2', + 'Test case 1', () => expect( 2, solution.searchInsert( @@ -18,7 +18,7 @@ void main() { ), ); test( - '1', + 'Test case 2', () => expect( 1, solution.searchInsert( @@ -28,7 +28,7 @@ void main() { ), ); test( - '4', + 'Test case 3', () => expect( 4, solution.searchInsert( diff --git a/test/easy/500_keyboard_row_test.dart b/test/easy/500_keyboard_row_test.dart index a2e4fa3..40048a9 100644 --- a/test/easy/500_keyboard_row_test.dart +++ b/test/easy/500_keyboard_row_test.dart @@ -8,7 +8,7 @@ void main() { final solution = Solution(); test( - 'test case 1', + 'Test case 1', () => expect( [ 'Alaska', @@ -24,9 +24,8 @@ void main() { ), ), ); - test( - 'test case 2', + 'Test case 2', () => expect( [], solution.findWords( @@ -36,7 +35,6 @@ void main() { ), ), ); - test( 'test case 3', () => expect( diff --git a/test/easy/58_length_of_last_word_test.dart b/test/easy/58_length_of_last_word_test.dart index 7c7d146..f7f77ce 100644 --- a/test/easy/58_length_of_last_word_test.dart +++ b/test/easy/58_length_of_last_word_test.dart @@ -8,7 +8,7 @@ void main() { final solution = Solution(); test( - '5', + 'Test case 1', () => expect( 5, solution.lengthOfLastWord( @@ -17,7 +17,7 @@ void main() { ), ); test( - '4', + 'Test case 2', () => expect( 4, solution.lengthOfLastWord( @@ -26,7 +26,7 @@ void main() { ), ); test( - '6', + 'Test case 3', () => expect( 6, solution.lengthOfLastWord( diff --git a/test/easy/66_plus_one_test.dart b/test/easy/66_plus_one_test.dart index c78f1a3..24003ab 100644 --- a/test/easy/66_plus_one_test.dart +++ b/test/easy/66_plus_one_test.dart @@ -8,7 +8,7 @@ void main() { final solution = Solution(); test( - '[1, 2, 4]', + 'Test case 1', () => expect( [1, 2, 4], solution.plusOne( @@ -17,7 +17,7 @@ void main() { ), ); test( - '[4, 3, 2, 2]', + 'Test case 2', () => expect( [4, 3, 2, 2], solution.plusOne( @@ -26,7 +26,7 @@ void main() { ), ); test( - '[1, 0]', + 'Test case 3', () => expect( [1, 0], solution.plusOne( diff --git a/test/easy/67_add_binary_test.dart b/test/easy/67_add_binary_test.dart index c769f0e..5e2c88e 100644 --- a/test/easy/67_add_binary_test.dart +++ b/test/easy/67_add_binary_test.dart @@ -8,17 +8,23 @@ void main() { final solution = Solution(); test( - '100', + 'Test case 1', () => expect( '100', - solution.addBinary('11', '1'), + solution.addBinary( + '11', + '1', + ), ), ); test( - '10101', + 'Test case 2', () => expect( '10101', - solution.addBinary('1010', '1011'), + solution.addBinary( + '1010', + '1011', + ), ), ); }, diff --git a/test/easy/69_sqrt_x_test.dart b/test/easy/69_sqrt_x_test.dart index dba2706..c6077fa 100644 --- a/test/easy/69_sqrt_x_test.dart +++ b/test/easy/69_sqrt_x_test.dart @@ -8,14 +8,14 @@ void main() { final solution = Solution(); test( - '2', + 'Test case 1', () => expect( 2, solution.mySqrt(4), ), ); test( - '2', + 'Test case 2', () => expect( 2, solution.mySqrt(8), diff --git a/test/easy/70_climbing_stairs_test.dart b/test/easy/70_climbing_stairs_test.dart index b3a843e..d04bcd7 100644 --- a/test/easy/70_climbing_stairs_test.dart +++ b/test/easy/70_climbing_stairs_test.dart @@ -8,14 +8,14 @@ void main() { final solution = Solution(); test( - '2', + 'Test case 1', () => expect( 2, solution.climbStairs(2), ), ); test( - '3', + 'Test case 2', () => expect( 3, solution.climbStairs(3), diff --git a/test/easy/83_remove_duplicates_from_sorted_list_test.dart b/test/easy/83_remove_duplicates_from_sorted_list_test.dart index 1b95dba..687e7ac 100644 --- a/test/easy/83_remove_duplicates_from_sorted_list_test.dart +++ b/test/easy/83_remove_duplicates_from_sorted_list_test.dart @@ -10,7 +10,7 @@ void main() { final solution = Solution(); test( - '[1, 2]', + 'Test case 1', () => expect( true, LinkedListHelper.areEqual( @@ -26,7 +26,7 @@ void main() { ), ); test( - '[1, 2, 3]', + 'Test case 2', () => expect( true, LinkedListHelper.areEqual( diff --git a/test/easy/88_merge_sorted_array_test.dart b/test/easy/88_merge_sorted_array_test.dart index 741aedc..f503b51 100644 --- a/test/easy/88_merge_sorted_array_test.dart +++ b/test/easy/88_merge_sorted_array_test.dart @@ -8,7 +8,7 @@ void main() { final solution = Solution(); test( - '[1, 2, 2, 3, 5, 6]', + 'Test case 1', () { final nums1 = [1, 2, 3, 0, 0, 0]; solution.merge( @@ -25,7 +25,7 @@ void main() { }, ); test( - '[1]', + 'Test case 2', () { final nums1 = [1]; solution.merge( @@ -35,11 +35,14 @@ void main() { 0, ); - expect([1], nums1); + expect( + [1], + nums1, + ); }, ); test( - '[1]', + 'Test case 3', () { final nums1 = [0]; solution.merge( diff --git a/test/easy/94_binary_tree_inorder_traversal_test.dart b/test/easy/94_binary_tree_inorder_traversal_test.dart index f7eea61..8494ff3 100644 --- a/test/easy/94_binary_tree_inorder_traversal_test.dart +++ b/test/easy/94_binary_tree_inorder_traversal_test.dart @@ -9,7 +9,7 @@ void main() { final solution = Solution(); test( - '[1, 3, 2]', + 'Test case 1', () => expect( [1, 3, 2], solution.inorderTraversal( @@ -25,14 +25,14 @@ void main() { ), ); test( - '[]', + 'Test case 2', () => expect( [], solution.inorderTraversal(null), ), ); test( - '[1]', + 'Test case 3', () => expect( [1], solution.inorderTraversal( diff --git a/test/easy/9_palindrome_number_test.dart b/test/easy/9_palindrome_number_test.dart index aa244a4..e69ed0f 100644 --- a/test/easy/9_palindrome_number_test.dart +++ b/test/easy/9_palindrome_number_test.dart @@ -8,21 +8,21 @@ void main() { final solution = Solution(); test( - 'true', + 'Test case 1', () => expect( true, solution.isPalindrome(121), ), ); test( - 'false', + 'Test case 2', () => expect( false, solution.isPalindrome(-121), ), ); test( - 'false', + 'Test case 3', () => expect( false, solution.isPalindrome(10),