hasty_test_hash_table Program

program~~hasty_test_hash_table~~UsesGraph program~hasty_test_hash_table hasty_test_hash_table module~hasty hasty module~hasty->program~hasty_test_hash_table iso_fortran_env iso_fortran_env iso_fortran_env->program~hasty_test_hash_table module~tester tester iso_fortran_env->module~tester module~penf_stringify penf_stringify iso_fortran_env->module~penf_stringify module~tester->program~hasty_test_hash_table module~hasty_dictionary_node hasty_dictionary_node module~hasty_dictionary_node->module~hasty module~hasty_dictionary hasty_dictionary module~hasty_dictionary_node->module~hasty_dictionary module~hasty_hash_table hasty_hash_table module~hasty_hash_table->module~hasty module~hasty_content_adt hasty_content_adt module~hasty_content_adt->module~hasty module~hasty_content_adt->module~hasty_dictionary_node module~hasty_content_adt->module~hasty_hash_table module~hasty_dictionary->module~hasty module~hasty_dictionary->module~hasty_hash_table module~hasty_key_base hasty_key_base module~hasty_key_base->module~hasty module~hasty_key_base->module~hasty_dictionary_node module~hasty_key_base->module~hasty_hash_table module~hasty_key_base->module~hasty_dictionary module~hasty_key_morton hasty_key_morton module~hasty_key_base->module~hasty_key_morton module~hasty_key_morton->module~hasty module~penf penf module~penf->module~hasty_dictionary_node module~penf->module~hasty_hash_table module~penf->module~hasty_dictionary module~penf->module~hasty_key_base module~penf->module~hasty_key_morton module~penf_global_parameters_variables penf_global_parameters_variables module~penf_global_parameters_variables->module~penf module~penf_b_size penf_b_size module~penf_global_parameters_variables->module~penf_b_size module~penf_global_parameters_variables->module~penf_stringify module~penf_b_size->module~penf module~penf_b_size->module~penf_stringify module~penf_stringify->module~penf
Help


HASTY test hash table.

Calls

program~~hasty_test_hash_table~~CallsGraph program~hasty_test_hash_table hasty_test_hash_table proc~tests_non_captured~2 tests_non_captured program~hasty_test_hash_table->proc~tests_non_captured~2 proc~initialize~3 initialize program~hasty_test_hash_table->proc~initialize~3 proc~test_assert_equal~3 test_assert_equal program~hasty_test_hash_table->proc~test_assert_equal~3 proc~hash_table_finalize hash_table_finalize proc~tests_non_captured~2->proc~hash_table_finalize
Help

Source Code


Variables

Type AttributesNameInitial
type(tester_t) :: hasty_tester

Tests handler.

class(*), allocatable:: a_key

A key.

class(*), pointer:: a_content

A content.

class(*), allocatable:: another_content

Another content.

type(hash_table) :: a_table

A table.

integer(kind=int32) :: max_content

Maximum content value.


Subroutines

subroutine initialize()

Initialize tests.

Arguments

None

subroutine iterator_max(key, content, done)

Iterator that computes the max of contents.

Arguments

Type IntentOptional AttributesName
class(*), intent(in) :: key

The node key.

class(*), intent(in), pointer:: content

The generic content.

logical, intent(out) :: done

Flag to set to true to stop traversing.

subroutine test_assert_equal(content, reference)

Test content==reference.

Arguments

Type IntentOptional AttributesName
class(*), intent(in) :: content

Content value.

integer(kind=int32), intent(in) :: reference

Reference value.

subroutine hash_table_finalize()

Test finalize.

Arguments

None

subroutine tests_non_captured()

Tests with non-captured results.

Arguments

None

Source Code

program hasty_test_hash_table
!-----------------------------------------------------------------------------------------------------------------------------------
!< HASTY test hash table.
!-----------------------------------------------------------------------------------------------------------------------------------
use, intrinsic :: iso_fortran_env, only : int32
use hasty
use tester
!-----------------------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------------------
type(tester_t)        :: hasty_tester    !< Tests handler.
class(*), allocatable :: a_key           !< A key.
class(*), pointer     :: a_content       !< A content.
class(*), allocatable :: another_content !< Another content.
type(hash_table)      :: a_table         !< A table.
integer(int32)        :: max_content     !< Maximum content value.
!-----------------------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------------------
call hasty_tester%init

call initialize

call tests_non_captured

call a_table%add_clone(key=5_int32, content=13_int32)
a_content => a_table%get_pointer(key=5_int32)
call test_assert_equal(content=a_content, reference=13_int32)

call hasty_tester%assert_equal(a_table%has_key(3_int32), .true.)

call hasty_tester%assert_equal(len(a_table), 2_int32)

max_content = 0
call a_table%traverse(iterator=iterator_max)
call hasty_tester%assert_equal(max_content, 13)

call a_table%remove(key=3_int32)
call hasty_tester%assert_equal(a_table%has_key(3_int32), .false.)

call a_table%get_clone(key=5_int32, content=another_content)
if (allocated(another_content)) then
  call test_assert_equal(content=another_content, reference=13_int32)
endif

call hasty_tester%assert_equal(int(a_table%ids(), int32), [5_int32, 5_int32])

call a_table%destroy
call a_table%initialize(buckets_number=11, homogeneous=.true., typeguard_key='a string', typeguard_content=1_int32)
call hasty_tester%assert_equal(a_table%is_initialized(), .true.)
call hasty_tester%assert_equal(a_table%is_homogeneous(), .true.)

call hasty_tester%print
!-----------------------------------------------------------------------------------------------------------------------------------
contains
  ! auxiliary procedures
  subroutine initialize
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Initialize tests.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  allocate(a_key, source=3_int32)
  allocate(a_content, source=12_int32)

  call a_table%add_pointer(key=a_key, content=a_content)
  call a_table%add_clone(key=5_int32, content=13_int32)
  !---------------------------------------------------------------------------------------------------------------------------------
  endsubroutine initialize

  subroutine iterator_max(key, content, done)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Iterator that computes the max of contents.
  !---------------------------------------------------------------------------------------------------------------------------------
  class(*),          intent(in)  :: key     !< The node key.
  class(*), pointer, intent(in)  :: content !< The generic content.
  logical,           intent(out) :: done    !< Flag to set to true to stop traversing.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  if (associated(content)) then
    select type(content)
    type is(integer(int32))
      max_content = max(max_content, content)
    endselect
  endif
  done = .false.
  !---------------------------------------------------------------------------------------------------------------------------------
  endsubroutine iterator_max

  ! tests
  subroutine test_assert_equal(content, reference)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Test `content==reference`.
  !---------------------------------------------------------------------------------------------------------------------------------
  class(*),       intent(in) :: content   !< Content value.
  integer(int32), intent(in) :: reference !< Reference value.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  select type(content)
  type is(integer(int32))
    call hasty_tester%assert_equal(content, reference)
  endselect
  !---------------------------------------------------------------------------------------------------------------------------------
  endsubroutine test_assert_equal

  subroutine hash_table_finalize
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Test [[hash_table:finalize]].
  !---------------------------------------------------------------------------------------------------------------------------------
  type(hash_table) :: local_hash_table !< A hash_table.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  call local_hash_table%add_clone(key=5_int32, content=13_int32)
  !---------------------------------------------------------------------------------------------------------------------------------
  endsubroutine hash_table_finalize

  subroutine tests_non_captured
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Tests with non-captured results.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  print '(A)', 'Keys in table:'
  call a_table%print_keys

  call hash_table_finalize
  !---------------------------------------------------------------------------------------------------------------------------------
  endsubroutine tests_non_captured
endprogram hasty_test_hash_table