public void TestNested() { dict4 = new TinyDictionary <ushort, IDictionary <ushort, ArrowDirection> >(); IDictionary <ushort, ArrowDirection> innerDict1 = new TinyDictionary <ushort, ArrowDirection>(); dict4.Add(1270, innerDict1); innerDict1.Add(1270, ArrowDirection.Turn); innerDict1.Add(14929, ArrowDirection.Forward); innerDict1.Add(26395, ArrowDirection.Left); IDictionary <ushort, ArrowDirection> innerDict2 = new TinyDictionary <ushort, ArrowDirection>(); dict4.Add(14929, innerDict2); innerDict2.Add(1270, ArrowDirection.Forward); innerDict2.Add(14929, ArrowDirection.Turn); innerDict2.Add(26395, ArrowDirection.Right); IDictionary <ushort, ArrowDirection> innerDict3 = new TinyDictionary <ushort, ArrowDirection>(); dict4.Add(26395, innerDict3); innerDict3.Add(1270, ArrowDirection.Right); innerDict3.Add(14929, ArrowDirection.Left); innerDict3.Add(26395, ArrowDirection.Turn); Assert.AreEqual(3, dict4.Count); Assert.IsTrue(dict4.ContainsKey(1270)); Assert.IsTrue(dict4.ContainsKey(14929)); Assert.IsTrue(dict4.ContainsKey(26395)); Assert.AreEqual(3, dict4[1270].Count); Assert.AreEqual(3, dict4[14929].Count); Assert.AreEqual(3, dict4[26395].Count); Assert.IsTrue(dict4[1270].ContainsKey(1270)); Assert.IsTrue(dict4[1270].ContainsKey(14929)); Assert.IsTrue(dict4[1270].ContainsKey(26395)); Assert.IsTrue(dict4[14929].ContainsKey(1270)); Assert.IsTrue(dict4[14929].ContainsKey(14929)); Assert.IsTrue(dict4[14929].ContainsKey(26395)); Assert.IsTrue(dict4[26395].ContainsKey(1270)); Assert.IsTrue(dict4[26395].ContainsKey(14929)); Assert.IsTrue(dict4[26395].ContainsKey(26395)); Assert.AreEqual(ArrowDirection.Turn, dict4[1270][1270]); Assert.AreEqual(ArrowDirection.Forward, dict4[1270][14929]); Assert.AreEqual(ArrowDirection.Left, dict4[1270][26395]); Assert.AreEqual(ArrowDirection.Forward, dict4[14929][1270]); Assert.AreEqual(ArrowDirection.Turn, dict4[14929][14929]); Assert.AreEqual(ArrowDirection.Right, dict4[14929][26395]); Assert.AreEqual(ArrowDirection.Right, dict4[26395][1270]); Assert.AreEqual(ArrowDirection.Left, dict4[26395][14929]); Assert.AreEqual(ArrowDirection.Turn, dict4[26395][26395]); }
public void TestAddRemove() { dict0.Add(1, 5); dict0.Add(5, 1); dict0.Add(2, 2); Assert.AreEqual(3, dict0.Count); Assert.AreEqual(5, dict0[1]); Assert.AreEqual(1, dict0[5]); Assert.AreEqual(2, dict0[2]); dict0.Remove(1); Assert.AreEqual(2, dict0.Count); Assert.IsFalse(dict0.ContainsKey(1)); dict0.Add(2, 3); Assert.AreEqual(2, dict0.Count); Assert.AreEqual(3, dict0[2]); dict0.Add(3, 0); Assert.AreEqual(3, dict0.Count); Assert.AreEqual(0, dict0[3]); dict0.Add(1, 4); Assert.AreEqual(4, dict0.Count); Assert.AreEqual(4, dict0[1]); dict0.Add(1, 8); Assert.AreEqual(4, dict0.Count); Assert.AreEqual(8, dict0[1]); dict0.Remove(1); Assert.AreEqual(3, dict0.Count); dict0.Add(1, 2); Assert.AreEqual(4, dict0.Count); Assert.AreEqual(2, dict0[1]); Assert.AreEqual(3, dict0[2]); Assert.AreEqual(0, dict0[3]); Assert.AreEqual(1, dict0[5]); }
public ParseErrorExpression Merge(RichPresenceBuilder from) { if (!String.IsNullOrEmpty(from.DisplayString)) { DisplayString = from.DisplayString; } _conditionalDisplayStrings.AddRange(from._conditionalDisplayStrings); foreach (var kvp in from._valueFields) { ValueField field; if (!_valueFields.TryGetValue(kvp.Key, out field)) { _valueFields.Add(kvp); } else if (field.Format != kvp.Value.Format) { return(new ParseErrorExpression("Multiple rich_presence_value calls with the same name must have the same format", field.Func)); } } foreach (var kvp in from._lookupFields) { Lookup existing; if (!_lookupFields.TryGetValue(kvp.Key, out existing)) { _lookupFields.Add(kvp); } else { var toMerge = kvp.Value; if (existing.Fallback != toMerge.Fallback) { return(new ParseErrorExpression("Multiple rich_presence_lookup calls with the same name must have the same fallback", toMerge.Fallback ?? existing.Fallback)); } if (existing.Entries.Count != toMerge.Entries.Count) { return(new ParseErrorExpression("Multiple rich_presence_lookup calls with the same name must have the same dictionary", toMerge.Func ?? existing.Func)); } foreach (var kvp2 in existing.Entries) { string value; if (!toMerge.Entries.TryGetValue(kvp2.Key, out value) || kvp2.Value != value) { return(new ParseErrorExpression("Multiple rich_presence_lookup calls with the same name must have the same dictionary", toMerge.Func ?? existing.Func)); } } } } return(null); }
public void InitializeTest() { dict0 = new TinyDictionary <byte, byte>(); dict1 = new TinyDictionary <string, int>(); dict1.Add(alice, 1); dict1.Add(bob, 2); dict1.Add(cedric, 3); dict2 = new TinyDictionary <string, IList <string> >(); dict2.Add(bob, bobsNicknames); dict2.Add(cedric, cedricsNicknames); dict2.Add(dora, dorasNicknames); dict2.Add(alice, alicesNicknames); dict3 = new TinyDictionary <ICollection <string>, bool>(); dict3.Add(girls, true); dict3.Add(boys, false); }
private void GetTags(BinaryReader reader) { var block = _blocks.Find(b => b.Tag == "moov.udta.meta.ilst"); reader.BaseStream.Seek(block.Address + 8, SeekOrigin.Begin); var remaining = block.Size - 8; while (remaining > 0) { var size = ReadUInt32(reader); var type = (Mp4Tag)ReadUInt32(reader); var datasize = ReadUInt32(reader) - 16; reader.BaseStream.Seek(12, SeekOrigin.Current); // skip 'data' tag and data flags switch (GetDataType(type)) { case ItemListDataType.Utf8String: var bytes = new byte[datasize]; reader.Read(bytes, 0, (int)datasize); var strval = Encoding.UTF8.GetString(bytes, 0, (int)datasize); _tags.Add(type, strval); break; case ItemListDataType.Int32: var intval = ReadUInt32(reader); _tags.Add(type, intval.ToString()); break; case ItemListDataType.Image: var image = new byte[datasize]; reader.Read(image, 0, (int)datasize); var imageval = Convert.ToBase64String(image); _tags.Add(type, imageval); break; } remaining -= size; } block = _blocks.Find(b => b.Tag == "moov.udta.tags.meta"); if (block.Size > 0) { reader.BaseStream.Seek(block.Address + 8, SeekOrigin.Begin); var count = ReadUInt32(reader); while (count-- > 0) { reader.ReadByte(); // flag? var keysize = (reader.ReadByte() << 8) | reader.ReadByte(); var buffer = new byte[keysize]; reader.Read(buffer, 0, keysize); var key = Encoding.UTF8.GetString(buffer); var tag = GetExtendedTag(key); reader.ReadByte(); // flag? reader.ReadByte(); // flag? var valuesize = ReadUInt32(reader); buffer = new byte[valuesize]; reader.Read(buffer, 0, buffer.Length); var value = Encoding.UTF8.GetString(buffer, 0, buffer.Length); if (tag != Mp4Tag.None) { _tags[tag] = value; } } } block = _blocks.Find(b => b.Tag == "moov.udta.Xtra"); if (block.Size > 0) { reader.BaseStream.Seek(block.Address + 8, SeekOrigin.Begin); remaining = block.Size - 8; while (remaining > 0) { var tagsize = ReadUInt32(reader); var keysize = ReadUInt32(reader); var buffer = new byte[keysize]; reader.Read(buffer, 0, (int)keysize); var key = Encoding.UTF8.GetString(buffer); var tag = GetWMTag(key); reader.BaseStream.Seek(10, SeekOrigin.Current); // skip flags buffer = new byte[tagsize - keysize - 8 - 10]; reader.Read(buffer, 0, buffer.Length); var value = Encoding.Unicode.GetString(buffer, 0, buffer.Length - 2); // expect null terminated if (tag != Mp4Tag.None) { _tags[tag] = value; } remaining -= tagsize; } } }