From 017ef8bac45e108159c682c08f5e23ab8124b175 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Mon, 11 Dec 2023 12:11:47 +0000 Subject: [PATCH] Add lua-format config and auto-format all exercises --- .lua-format | 33 +++++++++++++++++++++++++++++++++ .template.lua | 3 +-- anagrams.lua | 17 ++++++++--------- greatest_common_divisor.lua | 9 ++++----- hamming_distance.lua | 7 +++---- leap_years.lua | 11 +++++------ prime_numbers.lua | 13 ++++++------- queen_threats.lua | 17 ++++++++--------- resistor_colours.lua | 23 +++++++++++------------ 9 files changed, 79 insertions(+), 54 deletions(-) create mode 100644 .lua-format diff --git a/.lua-format b/.lua-format new file mode 100644 index 0000000..9946991 --- /dev/null +++ b/.lua-format @@ -0,0 +1,33 @@ +column_limit: 80 +indent_width: 1 +use_tab: true +tab_width: 4 +continuation_indent_width: 1 +spaces_before_call: 1 +keep_simple_control_block_one_line: true +keep_simple_function_one_line: false +align_args: true +break_after_functioncall_lp: false +break_before_functioncall_rp: false +spaces_inside_functioncall_parens: false +spaces_inside_functiondef_parens: false +align_parameter: true +chop_down_parameter: false +break_after_functiondef_lp: false +break_before_functiondef_rp: false +align_table_field: true +break_after_table_lb: true +break_before_table_rb: true +chop_down_table: false +chop_down_kv_table: true +table_sep: "," +extra_sep_at_table_end: false +column_table_limit: 0 +column_table_limit_kv: 0 +spaces_inside_table_braces: false +break_after_operator: true +double_quote_to_single_quote: false +single_quote_to_double_quote: false +spaces_around_equals_in_field: true +line_breaks_after_function_body: 1 +line_separator: input diff --git a/.template.lua b/.template.lua index 2fdc362..8d18d86 100644 --- a/.template.lua +++ b/.template.lua @@ -1,7 +1,6 @@ -- Solution -------------------------------------------------------------------- - function f() - -- Your implementation here + -- Your implementation here end -- Tests ----------------------------------------------------------------------- diff --git a/anagrams.lua b/anagrams.lua index ed2fb0a..cbf083b 100644 --- a/anagrams.lua +++ b/anagrams.lua @@ -1,7 +1,6 @@ -- Solution -------------------------------------------------------------------- - function is_anagram(str1, str2) - -- Your implementation here + -- Your implementation here end -- Tests ----------------------------------------------------------------------- @@ -9,31 +8,31 @@ end local luaunit = require("luaunit.luaunit") function test_listen_is_anagram_of_silent() - luaunit.assertTrue(is_anagram("listen", "silent")) + luaunit.assertTrue(is_anagram("listen", "silent")) end function test_astronomers_is_anagram_of_moon_starers() - luaunit.assertTrue(is_anagram("astronomers", "moon starers")) + luaunit.assertTrue(is_anagram("astronomers", "moon starers")) end function test_dormitory_is_anagram_of_dirty_room() - luaunit.assertTrue(is_anagram("dormitory", "dirty room")) + luaunit.assertTrue(is_anagram("dormitory", "dirty room")) end function test_foo_is_not_anagram_of_bar() - luaunit.assertFalse(is_anagram("foo", "bar")) + luaunit.assertFalse(is_anagram("foo", "bar")) end function test_foo_is_not_anagram_of_of() - luaunit.assertFalse(is_anagram("foo", "of")) + luaunit.assertFalse(is_anagram("foo", "of")) end function test_bar_is_not_anagram_of_barn() - luaunit.assertFalse(is_anagram("bar", "barn")) + luaunit.assertFalse(is_anagram("bar", "barn")) end function test_barn_is_not_anagram_of_bar() - luaunit.assertFalse(is_anagram("barn", "bar")) + luaunit.assertFalse(is_anagram("barn", "bar")) end os.exit(luaunit.LuaUnit.run()) diff --git a/greatest_common_divisor.lua b/greatest_common_divisor.lua index 84eed01..d6559c2 100644 --- a/greatest_common_divisor.lua +++ b/greatest_common_divisor.lua @@ -1,7 +1,6 @@ -- Solution -------------------------------------------------------------------- - function greatest_common_divisor(x, y) - -- Your implementation here + -- Your implementation here end -- Tests ----------------------------------------------------------------------- @@ -9,15 +8,15 @@ end local luaunit = require("luaunit.luaunit") function test_greatest_common_divisor_of_1386_and_3213_is_63() - luaunit.assertEquals(greatest_common_divisor(1386, 3213), 63) + luaunit.assertEquals(greatest_common_divisor(1386, 3213), 63) end function test_greatest_common_divisor_of_1470_and_3234_is_294() - luaunit.assertEquals(greatest_common_divisor(1470, 3234), 294) + luaunit.assertEquals(greatest_common_divisor(1470, 3234), 294) end function test_greatest_common_divisor_of_931_and_399_is_133() - luaunit.assertEquals(greatest_common_divisor(931, 399), 133) + luaunit.assertEquals(greatest_common_divisor(931, 399), 133) end os.exit(luaunit.LuaUnit.run()) diff --git a/hamming_distance.lua b/hamming_distance.lua index 2c74a29..8a71bd2 100644 --- a/hamming_distance.lua +++ b/hamming_distance.lua @@ -1,7 +1,6 @@ -- Solution -------------------------------------------------------------------- - function hamming_distance(str1, str2) - -- Your implementation here + -- Your implementation here end -- Tests ----------------------------------------------------------------------- @@ -9,11 +8,11 @@ end local luaunit = require("luaunit.luauint") function test_distance_between_foo_and_bar_is_3() - luaunit.assertEquals(hamming_distance("foo", "bar"), 3) + luaunit.assertEquals(hamming_distance("foo", "bar"), 3) end function test_distance_between_bar_and_baz_is_1() - luaunit.assertEquals(hamming_distance("bar", "baz"), 1) + luaunit.assertEquals(hamming_distance("bar", "baz"), 1) end os.exit(luaunit.LuaUnit.run()) diff --git a/leap_years.lua b/leap_years.lua index 482acc6..d633280 100644 --- a/leap_years.lua +++ b/leap_years.lua @@ -1,7 +1,6 @@ -- Solution -------------------------------------------------------------------- - function is_leap_year(year) - -- Your implementation here + -- Your implementation here end -- Tests ----------------------------------------------------------------------- @@ -9,19 +8,19 @@ end local luaunit = require("luaunit.luaunit") function test_2004_is_leap_year() - luaunit.assertTrue(is_leap_year(2004)) + luaunit.assertTrue(is_leap_year(2004)) end function test_1993_is_not_leap_year() - luaunit.assertFalse(is_leap_year(1993)) + luaunit.assertFalse(is_leap_year(1993)) end function test_1900_is_not_leap_year() - luaunit.assertFalse(is_leap_year(1900)) + luaunit.assertFalse(is_leap_year(1900)) end function test_2000_is_leap_year() - luaunit.assertTrue(is_leap_year(2000)) + luaunit.assertTrue(is_leap_year(2000)) end os.exit(luaunit.LuaUnit.run()) diff --git a/prime_numbers.lua b/prime_numbers.lua index fd1daca..05451a9 100644 --- a/prime_numbers.lua +++ b/prime_numbers.lua @@ -1,7 +1,6 @@ -- Solution -------------------------------------------------------------------- - function is_prime(x) - -- Your implementation here + -- Your implementation here end -- Tests ----------------------------------------------------------------------- @@ -9,23 +8,23 @@ end local luaunit = require("luaunit.luauint") function test_1_is_not_prime() - luaunit.assertFalse(is_prime(1)) + luaunit.assertFalse(is_prime(1)) end function test_2_is_prime() - luaunit.assertTrue(is_prime(2)) + luaunit.assertTrue(is_prime(2)) end function test_15_is_not_prime() - luaunit.assertFalse(is_prime(15)) + luaunit.assertFalse(is_prime(15)) end function test_441_is_not_prime() - luaunit.assertFalse(is_prime(441)) + luaunit.assertFalse(is_prime(441)) end function test_563_is_prime() - luaunit.assertTrue(is_prime(563)) + luaunit.assertTrue(is_prime(563)) end os.exit(luaunit.LuaUnit.run()) diff --git a/queen_threats.lua b/queen_threats.lua index 00a3ff2..bbecbd6 100644 --- a/queen_threats.lua +++ b/queen_threats.lua @@ -1,7 +1,6 @@ -- Solution -------------------------------------------------------------------- - function is_queen_threat(queen_position, pawn_position) - -- Your implementation here + -- Your implementation here end -- Tests ----------------------------------------------------------------------- @@ -9,31 +8,31 @@ end local luaunit = require("luaunit.luaunit") function test_B4_theatens_G4() - luaunit.assertTrue(is_queen_threat("B4", "G4")) + luaunit.assertTrue(is_queen_threat("B4", "G4")) end function test_D7_theatens_D1() - luaunit.assertTrue(is_queen_threat("D7", "D1")) + luaunit.assertTrue(is_queen_threat("D7", "D1")) end function test_C5_theatens_F8() - luaunit.assertTrue(is_queen_threat("C5", "F8")) + luaunit.assertTrue(is_queen_threat("C5", "F8")) end function test_B3_theatens_D1() - luaunit.assertTrue(is_queen_threat("B3", "D1")) + luaunit.assertTrue(is_queen_threat("B3", "D1")) end function test_B4_does_not_threaten_F3() - luaunit.assertFalse(is_queen_threat("B4", "F3")) + luaunit.assertFalse(is_queen_threat("B4", "F3")) end function test_E2_does_not_threaten_G1() - luaunit.assertFalse(is_queen_threat("E2", "G1")) + luaunit.assertFalse(is_queen_threat("E2", "G1")) end function test_A8_does_not_threaten_G3() - luaunit.assertFalse(is_queen_threat("A8", "G3")) + luaunit.assertFalse(is_queen_threat("A8", "G3")) end os.exit(luaunit.LuaUnit.run()) diff --git a/resistor_colours.lua b/resistor_colours.lua index b74c95d..5a71012 100644 --- a/resistor_colours.lua +++ b/resistor_colours.lua @@ -1,5 +1,4 @@ -- Solution -------------------------------------------------------------------- - -- Give the colours whatever values are convenient black = undefined brown = undefined @@ -15,7 +14,7 @@ gold = undefined silver = undefined function decode_resistance(colours) - -- Your implementation here + -- Your implementation here end -- Tests ----------------------------------------------------------------------- @@ -23,28 +22,28 @@ end local luaunit = require("luaunit.luaunit") function test_violet_orange_black_is_73_ohms() - local resistance = decode_resistance({violet, orange, black}) - luaunit.assertEquals(resistance, 73) + local resistance = decode_resistance({violet, orange, black}) + luaunit.assertEquals(resistance, 73) end function test_brown_green_black_is_15_ohms() - local resistance = decode_resistance({brown, green, black}) - luaunit.assertEquals(resistance, 15) + local resistance = decode_resistance({brown, green, black}) + luaunit.assertEquals(resistance, 15) end function test_green_blue_orange_is_56_kiloohms() - local resistance = decode_resistance({green, blue, orange}) - luaunit.assertEquals(resistance, 56000) + local resistance = decode_resistance({green, blue, orange}) + luaunit.assertEquals(resistance, 56000) end function test_white_yellow_yellow_is_940_kiloohms() - local resistance = decode_resistance({white, yellow, yellow}) - luaunit.assertEquals(resistance, 940000) + local resistance = decode_resistance({white, yellow, yellow}) + luaunit.assertEquals(resistance, 940000) end function test_orange_red_silver_is_320_milliohms() - local resistance = decode_resistance({orange, red, silver}) - luaunit.assertEquals(resistance, 0.32) + local resistance = decode_resistance({orange, red, silver}) + luaunit.assertEquals(resistance, 0.32) end os.exit(luaunit.LuaUnit.run())