public void GetEnumeratorTest() { // ReSharper disable once CollectionNeverUpdated.Local var dictionary = new UniqueDictionary <object, object>(); using var enumerator = dictionary.GetEnumerator(); Assert.That(enumerator.Current, Is.EqualTo(default(KeyValuePair <object, object>))); Assert.False(enumerator.MoveNext()); }
public void GetEnumeratorExplicitTest() { // ReSharper disable once CollectionNeverUpdated.Local var dictionary = new UniqueDictionary <object, object>(); var enumerator = ((IEnumerable)dictionary).GetEnumerator(); Assert.Throws <InvalidOperationException>(() => { var _ = enumerator.Current; }); Assert.False(enumerator.MoveNext()); }
public void ClearTest() { var dictionary = new UniqueDictionary <int, string>(); Assert.IsEmpty(dictionary); dictionary[0] = "A"; Assert.That(dictionary.Count, Is.EqualTo(1)); dictionary.Clear(); Assert.IsEmpty(dictionary); }
public void CountTest() { var dictionary = new UniqueDictionary <int, string>(); Assert.That(dictionary.Count, Is.EqualTo(0)); dictionary[0] = "A"; Assert.That(dictionary.Count, Is.EqualTo(1)); dictionary[0] = "B"; Assert.That(dictionary.Count, Is.EqualTo(1)); dictionary[1] = "C"; Assert.That(dictionary.Count, Is.EqualTo(2)); }
public void AddTest() { var dictionary = new UniqueDictionary <int, string>(); Assert.IsEmpty(dictionary); dictionary.Add(0, "A"); Assert.That(dictionary.Count, Is.EqualTo(1)); dictionary.Add(1, "B"); Assert.That(dictionary.Count, Is.EqualTo(2)); Assert.Throws <ArgumentException>(() => { dictionary.Add(0, "C"); }); }
static FileBom() { KeyValue <EncodingBom, FileBom>[] bomArray = new KeyValue <EncodingBom, FileBom> [4]; int count = 0; bomArray[count++].Set(Encoding.Unicode, new FileBom { Bom = 0xfeffU, Length = 2 }); bomArray[count++].Set(Encoding.BigEndianUnicode, new FileBom { Bom = 0xfffeU, Length = 2 }); bomArray[count++].Set(Encoding.UTF8, new FileBom { Bom = 0xbfbbefU, Length = 3 }); bomArray[count++].Set(Encoding.UTF32, new FileBom { Bom = 0xfeffU, Length = 4 }); boms = new UniqueDictionary <EncodingBom, FileBom>(bomArray, 4); }
static Settings() { ValidCharacterSet = new UniqueDictionary <int, char>(); int index = 0; for (int i = 0; i < AllCharacterSet.Length; i++) { // Ignore dummy characters. if (DummyCharacterSet.Contains(AllCharacterSet[i])) { continue; } ValidCharacterSet.Add(index, AllCharacterSet[i]); index++; } Base = ValidCharacterSet.Count; }
public Pokedex(IReadOnlySet <ISpecies> species) { Species = species; var speciesIds = new UniqueDictionary <int, ISpecies>(); var speciesNames = new UniqueDictionary <string, ISpecies>(); foreach (var s in species) { speciesIds[s.Id] = s; } foreach (var s in species) { speciesNames[s.Name] = s; } SpeciesIds = speciesIds; SpeciesNames = speciesNames; }
unsafe static DbType() { #region 数据类型集合 sqlTypeNames = new string[Sql.DbType.MaxEnumValue]; sqlTypeNames[(int)SqlDbType.BigInt] = "BIGINT"; //SqlTypeNames[(int)SqlDbType.Binary] = typeof(byte[]); sqlTypeNames[(int)SqlDbType.Bit] = "BIT"; sqlTypeNames[(int)SqlDbType.Char] = "CHAR"; sqlTypeNames[(int)SqlDbType.DateTime] = "DATETIME"; sqlTypeNames[(int)SqlDbType.Decimal] = "DECIMAL"; sqlTypeNames[(int)SqlDbType.Float] = "DOUBLE"; //SqlTypeNames[(int)SqlDbType.Image] = typeof(byte[]); sqlTypeNames[(int)SqlDbType.Int] = "INT"; sqlTypeNames[(int)SqlDbType.Money] = "DECIMAL"; sqlTypeNames[(int)SqlDbType.NChar] = "CHAR"; sqlTypeNames[(int)SqlDbType.NText] = "TEXT"; sqlTypeNames[(int)SqlDbType.NVarChar] = "VARCHAR"; sqlTypeNames[(int)SqlDbType.Real] = "FLOAT"; //SqlTypeNames[(int)SqlDbType.UniqueIdentifier] = typeof(Guid); sqlTypeNames[(int)SqlDbType.SmallDateTime] = "DATETIME"; sqlTypeNames[(int)SqlDbType.SmallInt] = "SMALLINT"; sqlTypeNames[(int)SqlDbType.SmallMoney] = "DECIMAL"; sqlTypeNames[(int)SqlDbType.Text] = "TEXT"; //SqlTypeNames[(int)SqlDbType.Timestamp] = typeof(byte[]); sqlTypeNames[(int)SqlDbType.TinyInt] = "TINYINT UNSIGNED"; //SqlTypeNames[(int)SqlDbType.VarBinary] = typeof(byte[]); sqlTypeNames[(int)SqlDbType.VarChar] = "VARCHAR"; //SqlTypeNames[(int)SqlDbType.Variant] = typeof(object); #endregion #region 默认值集合 defaultValues = new string[Sql.DbType.MaxEnumValue]; defaultValues[(int)SqlDbType.BigInt] = "0"; defaultValues[(int)SqlDbType.Bit] = "0"; defaultValues[(int)SqlDbType.Char] = "''"; defaultValues[(int)SqlDbType.DateTime] = "now()"; defaultValues[(int)SqlDbType.Decimal] = "0"; defaultValues[(int)SqlDbType.Float] = "0"; defaultValues[(int)SqlDbType.Int] = "0"; defaultValues[(int)SqlDbType.Money] = "0"; defaultValues[(int)SqlDbType.NChar] = "''"; defaultValues[(int)SqlDbType.NText] = "''"; defaultValues[(int)SqlDbType.NVarChar] = "''"; defaultValues[(int)SqlDbType.Real] = "0"; defaultValues[(int)SqlDbType.SmallDateTime] = "now()"; defaultValues[(int)SqlDbType.SmallInt] = "0"; defaultValues[(int)SqlDbType.SmallMoney] = "0"; defaultValues[(int)SqlDbType.Text] = "''"; defaultValues[(int)SqlDbType.TinyInt] = "0"; defaultValues[(int)SqlDbType.VarChar] = "''"; #endregion #region 数据类型集合唯一哈希 KeyValue <TypeName, KeyValue <SqlDbType, int> >[] names = new KeyValue <TypeName, KeyValue <SqlDbType, int> > [12]; names[0].Set((TypeName)"bigint", new KeyValue <SqlDbType, int>(SqlDbType.BigInt, sizeof(long))); names[1].Set((TypeName)"bit", new KeyValue <SqlDbType, int>(SqlDbType.Bit, sizeof(bool))); names[2].Set((TypeName)"char", new KeyValue <SqlDbType, int>(SqlDbType.Char, sizeof(char))); names[3].Set((TypeName)"datetime", new KeyValue <SqlDbType, int>(SqlDbType.DateTime, sizeof(DateTime))); names[4].Set((TypeName)"decimal", new KeyValue <SqlDbType, int>(SqlDbType.Decimal, sizeof(decimal))); names[5].Set((TypeName)"double", new KeyValue <SqlDbType, int>(SqlDbType.Float, sizeof(double))); names[6].Set((TypeName)"int", new KeyValue <SqlDbType, int>(SqlDbType.Int, sizeof(int))); names[7].Set((TypeName)"text", new KeyValue <SqlDbType, int>(SqlDbType.Text, int.MinValue)); names[8].Set((TypeName)"varchar", new KeyValue <SqlDbType, int>(SqlDbType.VarChar, int.MinValue)); names[9].Set((TypeName)"float", new KeyValue <SqlDbType, int>(SqlDbType.Real, sizeof(float))); names[10].Set((TypeName)"smallint", new KeyValue <SqlDbType, int>(SqlDbType.SmallInt, sizeof(short))); names[11].Set((TypeName)"tinyint", new KeyValue <SqlDbType, int>(SqlDbType.TinyInt, sizeof(byte))); sqlTypes = new UniqueDictionary <TypeName, KeyValue <SqlDbType, int> >(names, 16); #endregion }
public void ContainsKeyTest() { var dictionary = new UniqueDictionary <int, string>(); Assert.False(dictionary.ContainsKey(default));