-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use module and test functions for testing
- Loading branch information
1 parent
da82f2d
commit 993b1b4
Showing
24 changed files
with
221 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]") | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\"") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
Oops, something went wrong.