Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • icon-libraries/libfortran-support
1 result
Show changes
Commits on Source (2)
......@@ -30,6 +30,7 @@ _Describe important implementation details of the bugfix._
- [ ] Test coverage does not decrease
- [ ] Reviewed by a maintainer
- [ ] Incorporate review suggestions
- [ ] Prior to merging, please remove any boilerplate from the MR description, retaining only the _What is the bug_ and _How do you fix it_ section to maintain
- [ ] Remember to edit the commit message and select the proper changelog category (feature/bugfix/other)
**You are not supposed to merge this request by yourself, the maintainers of fortan-support take care of this action!**
......@@ -25,6 +25,7 @@ _Describe important implementation details of the feature._
- [ ] Test coverage does not decrease
- [ ] Reviewed by a maintainer
- [ ] Incorporate review suggestions
- [ ] Prior to merging, please remove any boilerplate from the MR description, retaining only the _Please describe your feature in a couple of words_ and _describe important implementation details of the feature_ section to maintain
- [ ] Remember to edit the commit message and select the proper changelog category (feature/bugfix/other)
**You are not supposed to merge this request by yourself, the maintainers of fortan-support take care of this action!**
......@@ -15,55 +15,181 @@ MODULE TEST_mo_util_sort
CONTAINS
SUBROUTINE TEST_quicksort_real
USE mo_util_sort
USE mo_util_sort, ONLY: quicksort
REAL(wp) :: to_sort(6) = (/144.4, 58.6, 4.3, 7.8, 10.0, 11.0/)
CALL TAG_TEST("TEST_quicksort_real_1")
CALL TAG_TEST("TEST_quicksort_real_before")
CALL ASSERT_EQUAL(is_sorted_real(to_sort), .FALSE.)
CALL quicksort(to_sort)
CALL TAG_TEST("TEST_quicksort_real_after")
CALL ASSERT_EQUAL(is_sorted_real(to_sort), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_quicksort_real2
USE mo_util_sort, ONLY: quicksort
REAL(wp) :: to_sort(6) = (/144.4, 11.0, 4.3, 58.6, 10.0, 7.8/)
CALL TAG_TEST("TEST_quicksort_real2_before")
CALL ASSERT_EQUAL(is_sorted_real(to_sort), .FALSE.)
CALL quicksort(to_sort)
CALL TAG_TEST("TEST_quicksort_real_2")
CALL TAG_TEST("TEST_quicksort_real2_after")
CALL ASSERT_EQUAL(is_sorted_real(to_sort), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_quicksort_real_random
USE mo_util_sort, ONLY: quicksort
REAL(wp) :: to_sort(6)
! Generate random numbers geq 0.0 and < 256.0
CALL RANDOM_NUMBER(to_sort)
to_sort = to_sort*256
CALL quicksort(to_sort)
CALL TAG_TEST("TEST_quicksort_real_random")
CALL ASSERT_EQUAL(is_sorted_real(to_sort), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_quicksort_permutation_real
USE mo_util_sort, ONLY: quicksort
REAL(wp) :: to_sort(6) = (/144.4, 58.6, 4.3, 7.8, 10.0, 11.0/)
INTEGER :: idx_permutation(6) = (/1, 2, 3, 4, 5, 6/)
CALL TAG_TEST("TEST_quicksort_permutation_real_before")
CALL ASSERT_EQUAL(is_sorted_real(to_sort), .FALSE.)
CALL quicksort(to_sort, idx_permutation)
CALL TAG_TEST("TEST_quicksort_permutation_real_after")
CALL ASSERT_EQUAL(is_sorted_real(to_sort), .TRUE.)
CALL TAG_TEST("TEST_quicksort_permutation_real_permutation")
CALL ASSERT_EQUAL(has_same_values_int(idx_permutation, (/3, 4, 5, 6, 2, 1/)), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_quicksort_int
USE mo_util_sort
USE mo_util_sort, ONLY: quicksort
INTEGER :: to_sort(6) = (/144, 58, 4, 7, 10, 11/)
CALL TAG_TEST("TEST_quicksort_int_1")
CALL TAG_TEST("TEST_quicksort_int_before")
CALL ASSERT_EQUAL(is_sorted_int(to_sort), .FALSE.)
CALL quicksort(to_sort)
CALL TAG_TEST("TEST_quicksort_int_after")
CALL ASSERT_EQUAL(is_sorted_int(to_sort), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_quicksort_int2
USE mo_util_sort, ONLY: quicksort
INTEGER :: to_sort(6) = (/58, 4, 144, 10, 7, 11/)
CALL TAG_TEST("TEST_quicksort_int2_before")
CALL ASSERT_EQUAL(is_sorted_int(to_sort), .FALSE.)
CALL quicksort(to_sort)
CALL TAG_TEST("TEST_quicksort_int_2")
CALL TAG_TEST("TEST_quicksort_int2_after")
CALL ASSERT_EQUAL(is_sorted_int(to_sort), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_quicksort_int_random
USE mo_util_sort, ONLY: quicksort
INTEGER :: to_sort(6)
REAL(wp) :: random_wp(6)
! Generate random numbers between 0 and 255
CALL RANDOM_NUMBER(random_wp)
to_sort = FLOOR(random_wp*256)
CALL quicksort(to_sort)
CALL TAG_TEST("TEST_quicksort_int_random")
CALL ASSERT_EQUAL(is_sorted_int(to_sort), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_quicksort_permutation_int
USE mo_util_sort
USE mo_util_sort, ONLY: quicksort
INTEGER :: to_sort(6) = (/144, 58, 4, 7, 10, 11/)
INTEGER :: idx_permutation(6) = (/1, 2, 3, 4, 5, 6/)
CALL TAG_TEST("TEST_quicksort_permutation_int_1")
CALL TAG_TEST("TEST_quicksort_permutation_int_before")
CALL ASSERT_EQUAL(is_sorted_int(to_sort), .FALSE.)
CALL quicksort(to_sort, idx_permutation)
CALL TAG_TEST("TEST_quicksort_permutation_int_2")
CALL TAG_TEST("TEST_quicksort_permutation_int_after")
CALL ASSERT_EQUAL(is_sorted_int(to_sort), .TRUE.)
CALL TAG_TEST("TEST_quicksort_permutation_int_3")
CALL TAG_TEST("TEST_quicksort_permutation_int_permutation")
CALL ASSERT_EQUAL(has_same_values_int(idx_permutation, (/3, 4, 5, 6, 2, 1/)), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_quicksort_string
USE mo_util_sort
USE mo_util_sort, ONLY: quicksort
CHARACTER :: to_sort(6) = (/'A', 'C', 'Y', 'E', 'S', 'H'/)
CALL TAG_TEST("TEST_quicksort_string_1")
CALL TAG_TEST("TEST_quicksort_string_before")
CALL ASSERT_EQUAL(is_sorted_string(to_sort), .FALSE.)
CALL quicksort(to_sort)
CALL TAG_TEST("TEST_quicksort_string_after")
CALL ASSERT_EQUAL(is_sorted_string(to_sort), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_quicksort_string2
USE mo_util_sort, ONLY: quicksort
CHARACTER :: to_sort(6) = (/'Y', 'H', 'A', 'S', 'E', 'C'/)
CALL TAG_TEST("TEST_quicksort_string2_before")
CALL ASSERT_EQUAL(is_sorted_string(to_sort), .FALSE.)
CALL quicksort(to_sort)
CALL TAG_TEST("TEST_quicksort_string2_after")
CALL ASSERT_EQUAL(is_sorted_string(to_sort), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_quicksort_string3
USE mo_util_sort, ONLY: quicksort
CHARACTER :: to_sort(6) = (/'P', 'M', 'W', 'G', 'K', 'D'/)
CALL TAG_TEST("TEST_quicksort_string3_before")
CALL ASSERT_EQUAL(is_sorted_string(to_sort), .FALSE.)
CALL quicksort(to_sort)
CALL TAG_TEST("TEST_quicksort_string3_after")
CALL ASSERT_EQUAL(is_sorted_string(to_sort), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_quicksort_string4
USE mo_util_sort, ONLY: quicksort
CHARACTER :: to_sort(6) = (/'B', 'L', 'Q', 'S', 'Z', 'T'/)
CALL TAG_TEST("TEST_quicksort_string4_before")
CALL ASSERT_EQUAL(is_sorted_string(to_sort), .FALSE.)
CALL quicksort(to_sort)
CALL TAG_TEST("TEST_quicksort_string_2")
CALL TAG_TEST("TEST_quicksort_string4_after")
CALL ASSERT_EQUAL(is_sorted_string(to_sort), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_insertion_sort_int
USE mo_util_sort
USE mo_util_sort, ONLY: insertion_sort
INTEGER :: to_sort(6) = (/144, 58, 4, 7, 10, 11/)
CALL TAG_TEST("TEST_insertion_sort_int_1")
CALL TAG_TEST("TEST_insertion_sort_int_before")
CALL ASSERT_EQUAL(is_sorted_int(to_sort), .FALSE.)
CALL quicksort(to_sort)
CALL TAG_TEST("TEST_insertion_sort_int_2")
CALL insertion_sort(to_sort)
CALL TAG_TEST("TEST_insertion_sort_int_after")
CALL ASSERT_EQUAL(is_sorted_int(to_sort), .TRUE.)
END SUBROUTINE
SUBROUTINE TEST_insertion_sort_int_random
USE mo_util_sort, ONLY: insertion_sort
INTEGER :: to_sort(6)
REAL(wp) :: random_wp(6)
! Generate random numbers between 0 and 255
CALL RANDOM_NUMBER(random_wp)
to_sort = FLOOR(random_wp*256)
CALL insertion_sort(to_sort)
CALL TAG_TEST("TEST_insertion_sort_int_random")
CALL ASSERT_EQUAL(is_sorted_int(to_sort), .TRUE.)
END SUBROUTINE
......