Skip to content

Commit

Permalink
use module and test functions for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Nov 2, 2023
1 parent da82f2d commit 993b1b4
Show file tree
Hide file tree
Showing 24 changed files with 221 additions and 176 deletions.
26 changes: 20 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Empty file added jule.mod
Empty file.
10 changes: 10 additions & 0 deletions math/abs_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
8 changes: 8 additions & 0 deletions math/fact_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
8 changes: 8 additions & 0 deletions math/max_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
8 changes: 8 additions & 0 deletions math/median_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
8 changes: 8 additions & 0 deletions math/min_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
8 changes: 8 additions & 0 deletions math/sum_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
12 changes: 12 additions & 0 deletions search/binary_search_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
11 changes: 11 additions & 0 deletions search/linear_search_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
11 changes: 11 additions & 0 deletions sort/bubble_sort_test.jule
Original file line number Diff line number Diff line change
@@ -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]")
}
11 changes: 11 additions & 0 deletions sort/exchange_sort_test.jule
Original file line number Diff line number Diff line change
@@ -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]")
}
11 changes: 11 additions & 0 deletions sort/insertion_sort_test.jule
Original file line number Diff line number Diff line change
@@ -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]")
}
11 changes: 11 additions & 0 deletions sort/quick_sort_test.jule
Original file line number Diff line number Diff line change
@@ -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]")
}
11 changes: 11 additions & 0 deletions sort/selection_sort_test.jule
Original file line number Diff line number Diff line change
@@ -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]")
}
11 changes: 11 additions & 0 deletions sort/shell_sort_test.jule
Original file line number Diff line number Diff line change
@@ -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]")
}
12 changes: 12 additions & 0 deletions sort/simple_sort_test.jule
Original file line number Diff line number Diff line change
@@ -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]")
}

8 changes: 8 additions & 0 deletions string/capitalize_test.jule
Original file line number Diff line number Diff line change
@@ -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\"")
}
9 changes: 9 additions & 0 deletions string/is_alpha_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
9 changes: 9 additions & 0 deletions string/is_digit_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
8 changes: 8 additions & 0 deletions string/lower_case_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
8 changes: 8 additions & 0 deletions string/reverse_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
8 changes: 8 additions & 0 deletions string/upper_case_test.jule
Original file line number Diff line number Diff line change
@@ -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")
}
Loading

0 comments on commit 993b1b4

Please sign in to comment.