<commit_before>module packdat_test

  use fruit

  implicit none
  
contains

! ******************************************************************
! ******************************************************************

  subroutine setSeed(s)

    implicit none

    integer, intent(in) :: s

    integer :: i, nseed
    
    integer, allocatable :: seed(:)

    call random_seed(SIZE=nseed)

    allocate(seed(nseed))

    do i = 1,nseed
       seed(i) = s
    end do

    call random_seed(PUT=seed)

  end subroutine setSeed

! ******************************************************************
! ******************************************************************
  
  subroutine createFiles(it, nit, cont, ncont, qIt)

    use items, only : ItemType

    use containers, only : Container
    
    implicit none

    type(Container) :: cont(ncont)

    type(ItemType) :: it(nit)

    integer :: nit, ncont, qIt(nit)

    intent(in) :: it, nit, cont, ncont, qIt
    
    integer :: i

    real(8) :: typ

    ! Generate items
    
    open(99, FILE = "items.txt")

    open(98, FILE = "data.txt")

    write(99, *) nit
    
    do i = 1, nit
       
       write(99, FMT = 100) it(i)%length, it(i)%width, &
            it(i)%class

       write(98, *) qIt(i)

    end do

    close(99)

    close(98)

    ! Generate containers
    
    open(99, FILE = "containers.txt")

    write(99, *) ncont
    
    do i = 1, ncont

       write(99, FMT = 100) cont(i)%length, &
            cont(i)%width, cont(i)%class

    end do

    close(99)

100 FORMAT(F5.1,1X,F5.1,1X,I2)
    
  end subroutine createFiles
  
! ******************************************************************
! ******************************************************************

  subroutine test_sortContainers_noid

    use packdat, only : loadData, reset, sortContainers

    use items, only: ItemType

    use containers, only: Container, emptyCContainer
    
    implicit none

    character(80) :: filename

    type(ItemType) :: it(1)

    type(Container) :: cont(3)

    integer :: L(3)<commit_msg>sortContainers correctly sorts. closes #3.<commit_after>module packdat_test

  use fruit

  implicit none
  
contains

! ******************************************************************
! ******************************************************************

  subroutine setSeed(s)

    implicit none

    integer, intent(in) :: s

    integer :: i, nseed
    
    integer, allocatable :: seed(:)

    call random_seed(SIZE=nseed)

    allocate(seed(nseed))

    do i = 1,nseed
       seed(i) = s
    end do

    call random_seed(PUT=seed)

  end subroutine setSeed

! ******************************************************************
! ******************************************************************
  
  subroutine createFiles(it, nit, cont, ncont, qIt)

    use items, only : ItemType

    use containers, only : Container
    
    implicit none

    type(Container) :: cont(ncont)

    type(ItemType) :: it(nit)

    integer :: nit, ncont, qIt(nit)

    intent(in) :: it, nit, cont, ncont, qIt
    
    integer :: i

    real(8) :: typ

    ! Generate items
    
    open(99, FILE = "items.txt")

    open(98, FILE = "data.txt")

    write(99, *) nit
    
    do i = 1, nit
       
       write(99, FMT = 100) it(i)%length, it(i)%width, &
            it(i)%class

       write(98, *) qIt(i)

    end do

    close(99)

    close(98)

    ! Generate containers
    
    open(99, FILE = "containers.txt")

    write(99, *) ncont
    
    do i = 1, ncont

       write(99, FMT = 100) cont(i)%length, &
            cont(i)%width, cont(i)%class

    end do

    close(99)

100 FORMAT(F5.1,1X,F5.1,1X,I2)
    
  end subroutine createFiles

! ******************************************************************
! ******************************************************************

  subroutine test_sortContainers_with_id

    use packdat, only : loadData, reset, sortContainers

    use items, only: ItemType

    use containers, only: Container, emptyContainer
    
    implicit none

    character(80) :: filename

    type(ItemType) :: it(1)

    type(Container) :: cont(3)

    integer :: L(3)

    call reset()

    it(1) = ItemType(0, 0, 0.0D0, 0.0D0)

    cont(1) = emptyContainer(1, 1, 1.0D0, 1.0D0)

    cont(2) = emptyContainer(2, 0, 5.0D0, 5.0D0)

    cont(3) = emptyContainer(3, 0, 2.0D0, 2.0D0)

    call createFiles(it, 1, cont, 3, (/ 0 /))
    
    filename = 'data.txt'
    
    call loadData(filename)

    ! No changes
    
    L = (/ 2, 1, 0 /)

    call sortContainers(2, L)

    call assert_equals(2, L(1))

    call assert_equals(1, L(2))

    ! Inverted id order
    
    L = (/ 1, 2, 0 /)

    call sortContainers(2, L)

    call assert_equals(2, L(1))

    call assert_equals(1, L(2))

    ! Full vector

    L = (/ 1, 2, 3 /)
    
    call sortContainers(3, L)

    call assert_equals(3, L(1))

    call assert_equals(2, L(2))

    call assert_equals(1, L(3))
    
  end subroutine test_sortContainers_with_id
  
! ******************************************************************
! ******************************************************************

  subroutine test_sortContainers_noid

    use packdat, only : loadData, reset, sortContainers

    use items, only: ItemType

    use containers, only: Container, emptyCContainer
    
    implicit none

    character(80) :: filename

    type(ItemType) :: it(1)

    type(Container) :: cont(3)

    integer :: L(3)
{'fraction_non_alphanumeric': 0.2709134175361523, 'fraction_numerical': 0.030203185063152116, 'mean_word_length': 2.8862019914651493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4296461', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1696, 'n_words': 408}