Changeset 2318 for cobra/trunk/Source/Cobra.Lang/ExtendDictionary.cobra
- Timestamp:
- 03/14/10 08:28:09 (2 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/Cobra.Lang/ExtendDictionary.cobra
r2246 r2318 18 18 return newDict 19 19 20 def get(key as TKey, default as TValue) as TValue 21 """ 22 Returns the value for the given key, or returns the default if the key is not found. 23 """ 24 ensure not .containsKey(key) implies result == default 25 value as TValue 26 if .tryGetValue(key, out value), return value 27 else, return default 28 29 20 30 class TestIDictionaryExtensions 21 31 … … 32 42 assert b.count == 2 33 43 assert b['x'] == 1 and b['y'] == 2 44 45 d = {'a': 1, 'b': 2} 46 assert d.get('a', 0) == 1 47 assert d.get('c', 1) == 1



