def codeListConfigGet( codeListConfig, key):
 ensureConsType( codeListConfig, ar_codeListConfig)
 codeListConfigEnvironment= assocGet( codeListConfig, (lambda x: x.car()==key))
 if 0==listLen( codeListConfigEnvironment):
  assert( False) # test-hook
  codeListConfigSet( codeListConfigSet, key, None) # baustelle: ungetestet
  codeListConfigEnvironment= assocGet( codeListConfig, (lambda x: x.car()==key))
 assert( 1==listLen( codeListConfigEnvironment))
 return consesNth0( assocNth0( codeListConfigEnvironment, 0), 1)
def codeListConfigSet( codeListConfig, key, value):
 ensureConsType( codeListConfig, ar_codeListConfig)
 codeListConfigEnvironment= assocGet( codeListConfig, (lambda x: x.car()==key))
 assert( 1==listLen( codeListConfigEnvironment))
 assocNth0( codeListConfigEnvironment, 0).cdr().car( value)
Beispiel #3
0
def testConsTrait3():
 
 def testCrCr( ex, ou, htEnvLocals= None):
  if None==htEnvLocals:
   htEnvLocals= dict()
  test( ConsRepr( ex ).repr_wrapped( htEnvLocals),
   ConsRepr( ou ).repr_wrapped( htEnvLocals))

 s= Symbol
 cs= ConsSimple

 te.checkComplainAndAdjustExpected( 0)
 uNames.next( usRename( ConsSimple, 'cs'))
 uNames.next( usRename( Symbol, 's'))

 as1= assocMake()

 test( "cs( s( 'ar_assoc'), s( 'nil'))", ConsRepr( as1).repr_wrapped())
 testCrCr( cs( ar_assoc, nil), as1)
 test( 0, listLen( as1))

 asGot= assocGet( as1, (lambda elem: False))
 testCrCr( cs( ar_assoc, nil), asGot)

 asGot= assocGet( as1, (lambda elem: True))
 testCrCr( cs( ar_assoc, nil), asGot)

 del asGot

 assocAdd( as1, cs( '1', nil))
 testCrCr( cs( ar_assoc, cs( cs( ar_assocElem, cs( '1', nil)), nil)), as1)
 test( 1, listLen( as1))

 assocAdd( as1, cs( '2', nil))
 testCrCr( cs( ar_assoc, cs( cs( ar_assocElem, cs( '1', nil)), cs( cs( ar_assocElem, cs( '2', nil)), nil))), as1)
 test( "listGeneral( listGeneral( '1'), listGeneral( '2'))", ConsRepr( as1).repr_wrapped( None, [ CpctReprListGeneral]))
 test( "assocInternGeneral( assocElemGeneral( '1'), assocElemGeneral( '2'))", ConsRepr( as1).repr_wrapped( None, [ CpctReprAssocInternGeneral, CpctReprAssocElemGeneral]))
 test( "consesMake( s( 'ar_assoc'), consesMake( s( 'ar_assocElem'), '1'), consesMake( s( 'ar_assocElem'), '2'))", ConsRepr( as1).repr_wrapped( None, [ CpctReprConses])) 
 test( "assocGeneral( consesMake( '1'), consesMake( '2'))", ConsRepr( as1).repr_wrapped( None, [ CpctReprAssocGeneral, CpctReprConses])) # klar: konflikt, geloest per f5fbafd44f9a4a3c9f65860301b2c1c5
 test( 2, listLen( as1)) 

 testCrCr( cs( ar_assocElem, cs( '1', nil)), listNth0( as1, 0))
 testCrCr( cs( ar_assocElem, cs( '2', nil)), listNth0( as1, 1))

 test( not_found, listNth0( as1, -1))
 test( not_found, listNth0( as1, 2))

 as2= assocGet( as1, (lambda elem: '1'==elem.car()))
 testCrCr( cs( ar_assoc, cs( cs( ar_assocElem, cs( '1', nil)), nil)), as2)

 as3= assocGet( as1, (lambda elem: '2'==elem.car()))
 testCrCr( cs( ar_assoc, cs( cs( ar_assocElem, cs( '2', nil)), nil)), as3)

 as4= assocDel( as1, (lambda elem: '1'==elem.car()))
 testCrCr( cs( ar_assoc, cs( cs( ar_assocElem, cs( '1', nil)), nil)), as4)
 testCrCr( cs( ar_assoc, cs( cs( ar_assocElem, cs( '2', nil)), nil)), as1)
 test( 1, listLen( as1))

 as5= assocDel( as1, (lambda elem: '2'==elem.car()))
 testCrCr( cs( ar_assoc, cs( cs( ar_assocElem, cs( '2', nil)), nil)), as5)
 testCrCr( cs( ar_assoc, nil), as1)
 test( 0, listLen( as1))

 uNames.undo()
 uNames.undo()
 te.checkComplainAndAdjustExpected( 25)