From 993b1b44e6a5a8732e7f2968979cced4aaa98caf Mon Sep 17 00:00:00 2001 From: mertcandav Date: Thu, 2 Nov 2023 17:27:33 +0300 Subject: [PATCH] use module and test functions for testing --- .github/workflows/tests.yml | 26 +++-- jule.mod | 0 math/abs_test.jule | 10 ++ math/fact_test.jule | 8 ++ math/max_test.jule | 8 ++ math/median_test.jule | 8 ++ math/min_test.jule | 8 ++ math/sum_test.jule | 8 ++ search/binary_search_test.jule | 12 +++ search/linear_search_test.jule | 11 +++ sort/bubble_sort_test.jule | 11 +++ sort/exchange_sort_test.jule | 11 +++ sort/insertion_sort_test.jule | 11 +++ sort/quick_sort_test.jule | 11 +++ sort/selection_sort_test.jule | 11 +++ sort/shell_sort_test.jule | 11 +++ sort/simple_sort_test.jule | 12 +++ string/capitalize_test.jule | 8 ++ string/is_alpha_test.jule | 9 ++ string/is_digit_test.jule | 9 ++ string/lower_case_test.jule | 8 ++ string/reverse_test.jule | 8 ++ string/upper_case_test.jule | 8 ++ test.jule | 170 --------------------------------- 24 files changed, 221 insertions(+), 176 deletions(-) create mode 100644 jule.mod create mode 100644 math/abs_test.jule create mode 100644 math/fact_test.jule create mode 100644 math/max_test.jule create mode 100644 math/median_test.jule create mode 100644 math/min_test.jule create mode 100644 math/sum_test.jule create mode 100644 search/binary_search_test.jule create mode 100644 search/linear_search_test.jule create mode 100644 sort/bubble_sort_test.jule create mode 100644 sort/exchange_sort_test.jule create mode 100644 sort/insertion_sort_test.jule create mode 100644 sort/quick_sort_test.jule create mode 100644 sort/selection_sort_test.jule create mode 100644 sort/shell_sort_test.jule create mode 100644 sort/simple_sort_test.jule create mode 100644 string/capitalize_test.jule create mode 100644 string/is_alpha_test.jule create mode 100644 string/is_digit_test.jule create mode 100644 string/lower_case_test.jule create mode 100644 string/reverse_test.jule create mode 100644 string/upper_case_test.jule delete mode 100644 test.jule diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e10d1e7..6f9be00 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,18 +14,32 @@ jobs: version: dev directory: . add-to-path: true - extra-command: version + extra-command: version - - name: Compile Tests + - name: Test - math run: | - julec test -o test . + julec test -o test math git update-index --add --chmod=-x test chmod +x test + ./test - - name: Run Tests + - name: Test - search run: | + julec test -o test search + git update-index --add --chmod=-x test + chmod +x test ./test - - name: Cleanup + - name: Test - sort run: | - rm -f test + julec test -o test sort + git update-index --add --chmod=-x test + chmod +x test + ./test + + - name: Test - string + run: | + julec test -o test string + git update-index --add --chmod=-x test + chmod +x test + ./test diff --git a/jule.mod b/jule.mod new file mode 100644 index 0000000..e69de29 diff --git a/math/abs_test.jule b/math/abs_test.jule new file mode 100644 index 0000000..1eac0a8 --- /dev/null +++ b/math/abs_test.jule @@ -0,0 +1,10 @@ +#build test + +use std::testing::{T} + +#test +fn test_abs(t: &T) { + t.assert(abs(-12.2) == 12.2, "-12.2 should equal to 12.2") + t.assert(abs(-12) == 12, "-12 should equal to 12") + t.assert(abs(-0.35) == 0.35, "-0.35 should equal to 0.35") +} diff --git a/math/fact_test.jule b/math/fact_test.jule new file mode 100644 index 0000000..794062c --- /dev/null +++ b/math/fact_test.jule @@ -0,0 +1,8 @@ +#build test + +use std::testing::{T} + +#test +fn test_fact(t: &T) { + t.assert(fact(10) == 3628800, "10 fact should equal to 3628800") +} diff --git a/math/max_test.jule b/math/max_test.jule new file mode 100644 index 0000000..7e9f051 --- /dev/null +++ b/math/max_test.jule @@ -0,0 +1,8 @@ +#build test + +use std::testing::{T} + +#test +fn test_max(t: &T) { + t.assert(max(0, -9024, 1, 894, -34) == 894, "max value should be 894") +} \ No newline at end of file diff --git a/math/median_test.jule b/math/median_test.jule new file mode 100644 index 0000000..3738adf --- /dev/null +++ b/math/median_test.jule @@ -0,0 +1,8 @@ +#build test + +use std::testing::{T} + +#test +fn test_median(t: &T) { + t.assert(median([2, 5, 2, 6, -4, -15, 1, -3]) == 1.5, "median should be 1.5") +} diff --git a/math/min_test.jule b/math/min_test.jule new file mode 100644 index 0000000..4b5a309 --- /dev/null +++ b/math/min_test.jule @@ -0,0 +1,8 @@ +#build test + +use std::testing::{T} + +#test +fn test_min(t: &T) { + t.assert(min(0, -9024, 1, 894, -34) == -9024, "min value should be -9024") +} diff --git a/math/sum_test.jule b/math/sum_test.jule new file mode 100644 index 0000000..cbda6e7 --- /dev/null +++ b/math/sum_test.jule @@ -0,0 +1,8 @@ +#build test + +use std::testing::{T} + +#test +fn test_sum(t: &T) { + t.assert(sum([-9, 0, 1, 99, 54, 12]) == 157, "sum should return 157") +} diff --git a/search/binary_search_test.jule b/search/binary_search_test.jule new file mode 100644 index 0000000..c4c34f2 --- /dev/null +++ b/search/binary_search_test.jule @@ -0,0 +1,12 @@ +#build test + +use std::testing::{T} + +#test +fn test_binary_search(t: &T) { + let s = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] + + t.assert(binary_search(s, 90) == -1, "90 should return -1") + t.assert(binary_search(s, -85) == 1, "85 should return 1") + t.assert(binary_search(s, 89) == 7, "89 should return 7") +} diff --git a/search/linear_search_test.jule b/search/linear_search_test.jule new file mode 100644 index 0000000..75cda64 --- /dev/null +++ b/search/linear_search_test.jule @@ -0,0 +1,11 @@ +#build test + +use std::testing::{T} + +#test +fn test_linear_search(t: &T) { + let s = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] + + t.assert(linear_search(s, 90) == -1, "90 should return -1") + t.assert(linear_search(s, -85) == 6, "-85 should return 6") +} diff --git a/sort/bubble_sort_test.jule b/sort/bubble_sort_test.jule new file mode 100644 index 0000000..73fbef2 --- /dev/null +++ b/sort/bubble_sort_test.jule @@ -0,0 +1,11 @@ +#build test + +use std::testing::{T} + +#test +fn test_bubble_sort(t: &T) { + let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] + let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] + + t.assert(bubble_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") +} diff --git a/sort/exchange_sort_test.jule b/sort/exchange_sort_test.jule new file mode 100644 index 0000000..d2900d0 --- /dev/null +++ b/sort/exchange_sort_test.jule @@ -0,0 +1,11 @@ +#build test + +use std::testing::{T} + +#test +fn test_exchange_sort(t: &T) { + let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] + let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] + + t.assert(exchange_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") +} diff --git a/sort/insertion_sort_test.jule b/sort/insertion_sort_test.jule new file mode 100644 index 0000000..a9691b7 --- /dev/null +++ b/sort/insertion_sort_test.jule @@ -0,0 +1,11 @@ +#build test + +use std::testing::{T} + +#test +fn test_insertion_sort(t: &T) { + let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] + let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] + + t.assert(insertion_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") +} diff --git a/sort/quick_sort_test.jule b/sort/quick_sort_test.jule new file mode 100644 index 0000000..a09b5a9 --- /dev/null +++ b/sort/quick_sort_test.jule @@ -0,0 +1,11 @@ +#build test + +use std::testing::{T} + +#test +fn test_quick_sort(t: &T) { + let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] + let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] + + t.assert(quick_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") +} diff --git a/sort/selection_sort_test.jule b/sort/selection_sort_test.jule new file mode 100644 index 0000000..d81ba29 --- /dev/null +++ b/sort/selection_sort_test.jule @@ -0,0 +1,11 @@ +#build test + +use std::testing::{T} + +#test +fn test_selection_sort(t: &T) { + let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] + let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] + + t.assert(selection_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") +} diff --git a/sort/shell_sort_test.jule b/sort/shell_sort_test.jule new file mode 100644 index 0000000..76af76e --- /dev/null +++ b/sort/shell_sort_test.jule @@ -0,0 +1,11 @@ +#build test + +use std::testing::{T} + +#test +fn test_shell_sort(t: &T) { + let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] + let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] + + t.assert(shell_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") +} diff --git a/sort/simple_sort_test.jule b/sort/simple_sort_test.jule new file mode 100644 index 0000000..83abeab --- /dev/null +++ b/sort/simple_sort_test.jule @@ -0,0 +1,12 @@ +#build test + +use std::testing::{T} + +#test +fn test_simple_sort(t: &T) { + let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] + let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] + + t.assert(simple_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") +} + diff --git a/string/capitalize_test.jule b/string/capitalize_test.jule new file mode 100644 index 0000000..da49354 --- /dev/null +++ b/string/capitalize_test.jule @@ -0,0 +1,8 @@ +#build test + +use std::testing::{T} + +#test +fn test_capitalize(t: &T) { + t.assert(capitalize("foo BAR") == "Foo bar", "capizalized \"foo BAR\" should be \"Foo bar\"") +} diff --git a/string/is_alpha_test.jule b/string/is_alpha_test.jule new file mode 100644 index 0000000..eb23463 --- /dev/null +++ b/string/is_alpha_test.jule @@ -0,0 +1,9 @@ +#build test + +use std::testing::{T} + +#test +fn test_is_alpha(t: &T) { + t.assert(is_alpha("foo") == true, "foo should return true") + t.assert(is_alpha("12345") == false, "12345 should return false") +} diff --git a/string/is_digit_test.jule b/string/is_digit_test.jule new file mode 100644 index 0000000..e9a4cd6 --- /dev/null +++ b/string/is_digit_test.jule @@ -0,0 +1,9 @@ +#build test + +use std::testing::{T} + +#test +fn test_is_digit(t: &T) { + t.assert(is_digit("12345") == true, "12345 should return true") + t.assert(is_digit("foo") == false, "foo should return false") +} diff --git a/string/lower_case_test.jule b/string/lower_case_test.jule new file mode 100644 index 0000000..ba7591e --- /dev/null +++ b/string/lower_case_test.jule @@ -0,0 +1,8 @@ +#build test + +use std::testing::{T} + +#test +fn test_lower_case(t: &T) { + t.assert(lower_case("FOo") == "foo", "FOo should return foo") +} diff --git a/string/reverse_test.jule b/string/reverse_test.jule new file mode 100644 index 0000000..56d517e --- /dev/null +++ b/string/reverse_test.jule @@ -0,0 +1,8 @@ +#build test + +use std::testing::{T} + +#test +fn test_reverse(t: &T) { + t.assert(reverse("FooBar") == "raBooF", "FooBar should return raBooF") +} diff --git a/string/upper_case_test.jule b/string/upper_case_test.jule new file mode 100644 index 0000000..ed357cd --- /dev/null +++ b/string/upper_case_test.jule @@ -0,0 +1,8 @@ +#build test + +use std::testing::{T} + +#test +fn test_upper_case(t: &T) { + t.assert(upper_case("foO") == "FOO", "foO should return FOO") +} diff --git a/test.jule b/test.jule deleted file mode 100644 index fbbc64a..0000000 --- a/test.jule +++ /dev/null @@ -1,170 +0,0 @@ -#build test - -use std::testing::{T} - -use math -use search -use sort -use string - -// -// MATH -// - -#test -fn test_math_abs(t: &T) { - t.assert(math::abs(-12.2) == 12.2, "-12.2 should equal to 12.2") - t.assert(math::abs(-12) == 12, "-12 should equal to 12") - t.assert(math::abs(-0.35) == 0.35, "-0.35 should equal to 0.35") -} - -#test -fn test_math_fact(t: &T) { - t.assert(math::fact(10) == 3628800, "10 fact should equal to 3628800") -} - -#test -fn test_math_max(t: &T) { - t.assert(math::max(0, -9024, 1, 894, -34) == 894, "max value should be 894") -} - -#test -fn test_math_median(t: &T) { - t.assert(math::median([2, 5, 2, 6, -4, -15, 1, -3]) == 1.5, "median should be 1.5") -} - -#test -fn test_math_min(t: &T) { - t.assert(math::min(0, -9024, 1, 894, -34) == -9024, "min value should be -9024") -} - -#test -fn test_math_sum(t: &T) { - t.assert(math::sum([-9, 0, 1, 99, 54, 12]) == 157, "sum should return 157") -} - - - - -// -// SEARCH -// - -#test -fn test_search_binary(t: &T) { - let s = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] - - t.assert(search::binary_search(s, 90) == -1, "90 should return -1") - t.assert(search::binary_search(s, -85) == 1, "85 should return 1") - t.assert(search::binary_search(s, 89) == 7, "89 should return 7") -} - -#test -fn test_search_linear(t: &T) { - let s = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] - - t.assert(search::linear_search(s, 90) == -1, "90 should return -1") - t.assert(search::linear_search(s, -85) == 6, "-85 should return 6") -} - - - - -// -// SORT -// - -#test -fn test_sort_bubble(t: &T) { - let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] - let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] - - t.assert(sort::bubble_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") -} - -#test -fn test_sort_exchange(t: &T) { - let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] - let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] - - t.assert(sort::exchange_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") -} - -#test -fn test_sort_insertion(t: &T) { - let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] - let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] - - t.assert(sort::insertion_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") -} - -#test -fn test_sort_quick(t: &T) { - let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] - let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] - - t.assert(sort::quick_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") -} - -#test -fn test_sort_selection(t: &T) { - let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] - let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] - - t.assert(sort::selection_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") -} - -#test -fn test_sort_shell(t: &T) { - let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] - let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] - - t.assert(sort::shell_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") -} - -#test -fn test_sort_simple(t: &T) { - let mut unsorted = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89] - let sorted = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935] - - t.assert(sort::simple_sort(unsorted) == sorted, "sorted slice should be [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]") -} - - - - -// -// STRING -// - -#test -fn test_string_capitalize(t: &T) { - t.assert(string::capitalize("foo BAR") == "Foo bar", "capizalized \"foo BAR\" should be \"Foo bar\"") -} - -#test -fn test_string_is_alpha(t: &T) { - t.assert(string::is_alpha("foo") == true, "foo should return true") - t.assert(string::is_alpha("12345") == false, "12345 should return false") -} - -#test -fn test_string_is_digit(t: &T) { - t.assert(string::is_digit("12345") == true, "12345 should return true") - t.assert(string::is_digit("foo") == false, "foo should return false") -} - -#test -fn test_string_lower_case(t: &T) { - t.assert(string::lower_case("FOo") == "foo", "FOo should return foo") -} - -#test -fn test_string_reverse(t: &T) { - t.assert(string::reverse("FooBar") == "raBooF", "FooBar should return raBooF") -} - -#test -fn test_string_upper_case(t: &T) { - t.assert(string::upper_case("foO") == "FOO", "foO should return FOO") -}