Commit 561240a0 authored by Graham, Aaron's avatar Graham, Aaron
Browse files

Adds insertEntry interfaces for SNK and SLK rank-0 insertions

parent 158950c2
......@@ -199,9 +199,15 @@ ENDINTERFACE
!> @brief Interface to insert an entry of a list from the list
!>
INTERFACE insertEntry
!> @copybrief ArrayUtils::insertEntry_1DString_0Dentry
!> @copydetails ArrayUtils::insertEntry_1DString_0Dentry
MODULE PROCEDURE insertEntry_1DString_0Dentry
!> @copybrief ArrayUtils::insertEntry_1DSNK_0Dentry
!> @copydetails ArrayUtils::insertEntry_1DSNK_0Dentry
MODULE PROCEDURE insertEntry_1DSNK_0Dentry
!> @copybrief ArrayUtils::insertEntry_1DSLK_0Dentry
!> @copydetails ArrayUtils::insertEntry_1DSLK_0Dentry
MODULE PROCEDURE insertEntry_1DSLK_0Dentry
!> @copybrief ArrayUtils::insertEntry_1DString_0Dentry
!> @copydetails ArrayUtils::insertEntry_1DString_0Dentry
MODULE PROCEDURE insertEntry_1DString_0Dentry
!> @copybrief ArrayUtils::insertEntry_1DString_1Dentry
!> @copydetails ArrayUtils::insertEntry_1DString_1Dentry
MODULE PROCEDURE insertEntry_1DString_1Dentry
......@@ -1435,6 +1441,66 @@ FUNCTION popEntry_1DString(list,entry) RESULT(popped)
ENDFUNCTION popEntry_1DString
!
!-------------------------------------------------------------------------------
!> @brief Inserts an SNK Integer into a list of integers
!> @param list the original list
!> @param insert the new SNK integer to insert
!> @param entry the index to insert the new SNK integer at
!>
!> After insertion, the @c entry-th index of the list will be @c insert, with
!> the original values at @c entry and later being moved back by one. If
!> @c entry is given a value of @c SIZE(list)+1, then @c insert is added to the
!> back of the list
!>
SUBROUTINE insertEntry_1DSNK_0Dentry(list,insert,entry)
INTEGER(SNK),ALLOCATABLE,INTENT(INOUT) :: list(:)
INTEGER(SNK),INTENT(IN) :: insert
INTEGER(SIK),INTENT(IN) :: entry
!
INTEGER(SNK),ALLOCATABLE :: oldlist(:)
REQUIRE(ALLOCATED(list))
REQUIRE(entry > 0)
REQUIRE(entry <= SIZE(list)+1)
CALL MOVE_ALLOC(list,oldlist)
ALLOCATE(list(SIZE(oldlist)+1))
list(1:entry-1)=oldlist(1:entry-1)
list(entry)=insert
list(entry+1:SIZE(list))=oldlist(entry:SIZE(oldlist))
ENDSUBROUTINE insertEntry_1DSNK_0Dentry
!
!-------------------------------------------------------------------------------
!> @brief Inserts an SLK Integer into a list of integers
!> @param list the original list
!> @param insert the new SLK integer to insert
!> @param entry the index to insert the new SLK integer at
!>
!> After insertion, the @c entry-th index of the list will be @c insert, with
!> the original values at @c entry and later being moved back by one. If
!> @c entry is given a value of @c SIZE(list)+1, then @c insert is added to the
!> back of the list
!>
SUBROUTINE insertEntry_1DSLK_0Dentry(list,insert,entry)
INTEGER(SLK),ALLOCATABLE,INTENT(INOUT) :: list(:)
INTEGER(SLK),INTENT(IN) :: insert
INTEGER(SIK),INTENT(IN) :: entry
!
INTEGER(SLK),ALLOCATABLE :: oldlist(:)
REQUIRE(ALLOCATED(list))
REQUIRE(entry > 0)
REQUIRE(entry <= SIZE(list)+1)
CALL MOVE_ALLOC(list,oldlist)
ALLOCATE(list(SIZE(oldlist)+1))
list(1:entry-1)=oldlist(1:entry-1)
list(entry)=insert
list(entry+1:SIZE(list))=oldlist(entry:SIZE(oldlist))
ENDSUBROUTINE insertEntry_1DSLK_0Dentry
!
!-------------------------------------------------------------------------------
!> @brief Inserts a string into a list of strings
!> @param list the original list
!> @param insert the new string to insert
......
......@@ -777,7 +777,7 @@ SUBROUTINE testReplaceEntry()
ASSERT_EQ(CHAR(strlist(4)),'test string 1','strlist(4)')
ASSERT_EQ(CHAR(strlist(5)),'test string 1','strlist(5)')
ASSERT_EQ(CHAR(strlist(6)),'test string 2','strlist(6)')
ENDSUBROUTINE testReplaceEntry
!
!-------------------------------------------------------------------------------
......@@ -818,9 +818,79 @@ ENDSUBROUTINE testPopEntry
!
!-------------------------------------------------------------------------------
SUBROUTINE testInsertEntry()
INTEGER(SNK) :: snk0
INTEGER(SNK),ALLOCATABLE :: snk1(:),snklist(:)
INTEGER(SLK) :: slk0
INTEGER(SLK),ALLOCATABLE :: slk1(:),slklist(:)
TYPE(StringType) :: str0
TYPE(StringType),ALLOCATABLE :: str1(:),strlist(:)
COMPONENT_TEST('1D SNK, 0D SNK')
snk0=1
ALLOCATE(snklist(0))
CALL insertEntry(snklist,snk0,1)
ASSERT_EQ(SIZE(snklist),1,'SIZE list')
ASSERT_EQ(snklist(1),1,'list(1)')
snk0=2
CALL insertEntry(snklist,snk0,1)
ASSERT_EQ(SIZE(snklist),2,'SIZE list')
ASSERT_EQ(snklist(1),2,'list(1)')
snk0=3
CALL insertEntry(snklist,snk0,1)
ASSERT_EQ(SIZE(snklist),3,'SIZE list')
ASSERT_EQ(snklist(1),3,'list(1)')
snk0=4
CALL insertEntry(snklist,snk0,4)
ASSERT_EQ(SIZE(snklist),4,'SIZE list')
ASSERT_EQ(snklist(4),4,'list(4)')
snk0=5
CALL insertEntry(snklist,snk0,4)
ASSERT_EQ(SIZE(snklist),5,'SIZE list')
ASSERT_EQ(snklist(4),5,'list(4)')
snk0=6
CALL insertEntry(snklist,snk0,2)
ASSERT_EQ(SIZE(snklist),6,'SIZE list')
ASSERT_EQ(snklist(1),3,'list(1)')
ASSERT_EQ(snklist(2),6,'list(2)')
ASSERT_EQ(snklist(3),2,'list(3)')
ASSERT_EQ(snklist(4),1,'list(4)')
ASSERT_EQ(snklist(5),5,'list(5)')
ASSERT_EQ(snklist(6),4,'list(6)')
DEALLOCATE(snklist)
COMPONENT_TEST('1D SLK, 0D SLK')
slk0=1
ALLOCATE(slklist(0))
CALL insertEntry(slklist,slk0,1)
ASSERT_EQ(SIZE(slklist),1,'SIZE list')
ASSERT_EQ(slklist(1),1,'list(1)')
slk0=2
CALL insertEntry(slklist,slk0,1)
ASSERT_EQ(SIZE(slklist),2,'SIZE list')
ASSERT_EQ(slklist(1),2,'list(1)')
slk0=3
CALL insertEntry(slklist,slk0,1)
ASSERT_EQ(SIZE(slklist),3,'SIZE list')
ASSERT_EQ(slklist(1),3,'list(1)')
slk0=4
CALL insertEntry(slklist,slk0,4)
ASSERT_EQ(SIZE(slklist),4,'SIZE list')
ASSERT_EQ(slklist(4),4,'list(4)')
slk0=5
CALL insertEntry(slklist,slk0,4)
ASSERT_EQ(SIZE(slklist),5,'SIZE list')
ASSERT_EQ(slklist(4),5,'list(4)')
slk0=6
CALL insertEntry(slklist,slk0,2)
ASSERT_EQ(SIZE(slklist),6,'SIZE list')
ASSERT_EQ(slklist(1),3,'list(1)')
ASSERT_EQ(slklist(2),6,'list(2)')
ASSERT_EQ(slklist(3),2,'list(3)')
ASSERT_EQ(slklist(4),1,'list(4)')
ASSERT_EQ(slklist(5),5,'list(5)')
ASSERT_EQ(slklist(6),4,'list(6)')
DEALLOCATE(slklist)
COMPONENT_TEST('1D String, 0D String')
str0='inserted'
ALLOCATE(strlist(0))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment