|
| 1 | +using System.Collections; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | + |
| 5 | +namespace Python.Test |
| 6 | +{ |
| 7 | + /// <summary> |
| 8 | + /// Supports units tests for dictionary __contains__ and __len__ |
| 9 | + /// </summary> |
| 10 | + public class PublicDictionaryTest |
| 11 | + { |
| 12 | + public IDictionary<string, int> items; |
| 13 | + |
| 14 | + public PublicDictionaryTest() |
| 15 | + { |
| 16 | + items = new int[5] { 0, 1, 2, 3, 4 } |
| 17 | + .ToDictionary(k => k.ToString(), v => v); |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + |
| 22 | + public class ProtectedDictionaryTest |
| 23 | + { |
| 24 | + protected IDictionary<string, int> items; |
| 25 | + |
| 26 | + public ProtectedDictionaryTest() |
| 27 | + { |
| 28 | + items = new int[5] { 0, 1, 2, 3, 4 } |
| 29 | + .ToDictionary(k => k.ToString(), v => v); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + |
| 34 | + public class InternalDictionaryTest |
| 35 | + { |
| 36 | + internal IDictionary<string, int> items; |
| 37 | + |
| 38 | + public InternalDictionaryTest() |
| 39 | + { |
| 40 | + items = new int[5] { 0, 1, 2, 3, 4 } |
| 41 | + .ToDictionary(k => k.ToString(), v => v); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + |
| 46 | + public class PrivateDictionaryTest |
| 47 | + { |
| 48 | + private IDictionary<string, int> items; |
| 49 | + |
| 50 | + public PrivateDictionaryTest() |
| 51 | + { |
| 52 | + items = new int[5] { 0, 1, 2, 3, 4 } |
| 53 | + .ToDictionary(k => k.ToString(), v => v); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + public class InheritedDictionaryTest : IDictionary<string, int> |
| 58 | + { |
| 59 | + private readonly IDictionary<string, int> items; |
| 60 | + |
| 61 | + public InheritedDictionaryTest() |
| 62 | + { |
| 63 | + items = new int[5] { 0, 1, 2, 3, 4 } |
| 64 | + .ToDictionary(k => k.ToString(), v => v); |
| 65 | + } |
| 66 | + |
| 67 | + public int this[string key] |
| 68 | + { |
| 69 | + get { return items[key]; } |
| 70 | + set { items[key] = value; } |
| 71 | + } |
| 72 | + |
| 73 | + public ICollection<string> Keys => items.Keys; |
| 74 | + |
| 75 | + public ICollection<int> Values => items.Values; |
| 76 | + |
| 77 | + public int Count => items.Count; |
| 78 | + |
| 79 | + public bool IsReadOnly => false; |
| 80 | + |
| 81 | + public void Add(string key, int value) => items.Add(key, value); |
| 82 | + |
| 83 | + public void Add(KeyValuePair<string, int> item) => items.Add(item); |
| 84 | + |
| 85 | + public void Clear() => items.Clear(); |
| 86 | + |
| 87 | + public bool Contains(KeyValuePair<string, int> item) => items.Contains(item); |
| 88 | + |
| 89 | + public bool ContainsKey(string key) => items.ContainsKey(key); |
| 90 | + |
| 91 | + public void CopyTo(KeyValuePair<string, int>[] array, int arrayIndex) |
| 92 | + { |
| 93 | + items.CopyTo(array, arrayIndex); |
| 94 | + } |
| 95 | + |
| 96 | + public IEnumerator<KeyValuePair<string, int>> GetEnumerator() => items.GetEnumerator(); |
| 97 | + |
| 98 | + public bool Remove(string key) => items.Remove(key); |
| 99 | + |
| 100 | + public bool Remove(KeyValuePair<string, int> item) => items.Remove(item); |
| 101 | + |
| 102 | + public bool TryGetValue(string key, out int value) => items.TryGetValue(key, out value); |
| 103 | + |
| 104 | + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); |
| 105 | + } |
| 106 | +} |
0 commit comments