Skip to content

Commit

Permalink
tests: added some test to sorting algorithm (#222)
Browse files Browse the repository at this point in the history
## Pull Request type

Following the recent issue on bubble sort, I added some test to sorting
algorithms

Please check the type of change your PR introduces:

- [ ] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no API changes)
- [ ] Build-related changes
- [ ] Documentation content changes
- [X] Other (please describe): unit tests

## What is the current behavior?

Issue Number: N/A

## What is the new behavior?

- Test covers more scenarios

## Does this introduce a breaking change?

- [ ] Yes
- [X] No

## Other information
  • Loading branch information
azurwastaken authored Nov 30, 2023
1 parent 5887296 commit 8426dbb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/sorting/src/tests/bubble_sort_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,33 @@ fn bubblesort_test_pre_sorted() {

#[test]
#[available_gas(2000000)]
fn bubblesort_test_2_same_values() {
fn bubblesort_test_pre_sorted_decreasing() {
let mut data = array![4_u32, 3_u32, 2_u32, 1_u32];
let mut correct = array![1_u32, 2_u32, 3_u32, 4_u32];

let sorted = bubble_sort::bubble_sort_elements(data);

assert(is_equal(sorted.span(), correct.span()), 'invalid result');
}

#[test]
#[available_gas(2000000)]
fn bubblesort_test_pre_sorted_2_same_values() {
let mut data = array![1_u32, 2_u32, 2_u32, 4_u32];
let mut correct = array![1_u32, 2_u32, 2_u32, 4_u32];

let sorted = bubble_sort::bubble_sort_elements(data);

assert(is_equal(sorted.span(), correct.span()), 'invalid result');
}

#[test]
#[available_gas(2000000)]
fn bubblesort_test_2_same_values() {
let mut data = array![1_u32, 2_u32, 4_u32, 2_u32];
let mut correct = array![1_u32, 2_u32, 2_u32, 4_u32];

let sorted = bubble_sort::bubble_sort_elements(data);

assert(is_equal(sorted.span(), correct.span()), 'invalid result');
}
33 changes: 33 additions & 0 deletions src/sorting/src/tests/merge_sort_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ fn mergesort_test() {
assert(is_equal(sorted, correct), 'invalid result');
}

#[test]
#[available_gas(2000000)]
fn mergesort_test_2_pre_sorted_decreasing() {
let mut data = array![4_u32, 3_u32, 2_u32, 1_u32];
let mut correct = array![1_u32, 2_u32, 3_u32, 4_u32];

let sorted = merge(data);

assert(is_equal(sorted.span(), correct.span()), 'invalid result');
}

#[test]
#[available_gas(2000000)]
fn mergesort_test_empty() {
Expand Down Expand Up @@ -44,3 +55,25 @@ fn mergesort_test_pre_sorted() {

assert(is_equal(sorted.span(), correct.span()), 'invalid result');
}

#[test]
#[available_gas(2000000)]
fn mergesort_test_2_same_values() {
let mut data = array![1_u32, 2_u32, 3_u32, 2_u32, 4_u32];
let mut correct = array![1_u32, 2_u32, 2_u32, 3_u32, 4_u32];

let sorted = merge(data);

assert(is_equal(sorted.span(), correct.span()), 'invalid result');
}

#[test]
#[available_gas(2000000)]
fn mergesort_test_2_same_values_pre_sorted() {
let mut data = array![1_u32, 2_u32, 2_u32, 3_u32, 4_u32];
let mut correct = array![1_u32, 2_u32, 2_u32, 3_u32, 4_u32];

let sorted = merge(data);

assert(is_equal(sorted.span(), correct.span()), 'invalid result');
}

0 comments on commit 8426dbb

Please sign in to comment.