public void ShouldAddIntToTable() { var hashTable = new IntHashTable(); hashTable.Add(1); Assert.True(hashTable.Contains(1)); }
public void TestIntHashTable() { // update hashtable IntHashTable T = new IntHashTable(); Random Rnd = new Random(); int i = 0; for ( ; i < 1000; ++i) { T[i - 500] = Rnd.Next(10000000).ToString(); } // test IEnumerable implementation int iCount = 0; foreach (IntHashTable.Entry E in T) { ++iCount; if (E.Value == null) { throw new Exception("Null value in IntHashTable"); } } if (iCount != 1000) { throw new Exception("IntHashTable as IEnumerable returns invalid entries"); } // test IDictionary implementation if (!T.Contains(100) || !T.Contains(200)) { throw new Exception("IntHashTable's key resolution error"); } if (T.Count != 1000) { throw new Exception("IntHashTable.Count returned invalid value: " + T.Count.ToString()); } }
public void WhenNumberNotInTable_ContainsShouldReturnFalse() { var hashTable = new IntHashTable(); Assert.False(hashTable.Contains(0)); }
private void RepairPropTypes() { int propID = GetPropId("ID"); int propName = GetPropId("Name"); int propDataType = GetPropId("DataType"); int propFlags = GetPropId("Flags"); int typePropType = GetResourceTypeId("PropType"); bool needRebuildIndexes = false; if (_propTypes.PeekNextID() > 65536) { needRebuildIndexes = true; } using (IResultSet rs = _propTypes.CreateResultSet(0)) { foreach (IRecord rec in rs) { int typeId = rec.GetIntValue(0); string name = rec.GetStringValue(1); int dataType = rec.GetIntValue(2); int flags = rec.GetIntValue(3); if (typeId < 0 || typeId > 65536) { ReportError("Invalid property type ID " + typeId); if (_fixErrors) { rec.Delete(); _fixCount++; needRebuildIndexes = true; continue; } } if (_propTypeMap.Contains(typeId)) { ReportError("Duplicate property ID " + typeId); } if (_propTypeNames.Contains(name)) { ReportError("Duplicate property name " + name); } _propTypeMap.Add(typeId, name); _propTypeNames.Add(name); _propDataTypes [typeId] = dataType; if (_dumpStructure) { ShowProgress("Property type {0}, name {1}, dataType {2}, flags {3}", typeId, name, dataType, (PropTypeFlags)flags); } int resID; try { resID = FindResource(typePropType, _stringProps, propName, name); } catch (Exception e) { ReportError("Property " + name + ": " + e.Message); continue; } if (resID == -1) { ReportError("Could not find matching resource for property name " + name); if (_fixErrors) { try { int resourceId = CreateResource(typePropType); CreatePropValue(_stringProps, resourceId, propName, name); CreatePropValue(_intProps, resourceId, propID, typeId); CreatePropValue(_intProps, resourceId, propDataType, dataType); CreatePropValue(_intProps, resourceId, propFlags, flags); _fixCount++; } catch (Exception e) { ReportError("Failed to create property type resource: " + e.Message); } } continue; } object idValue = GetPropValueSafe(_intProps, resID, propID); if (idValue == null) { ReportError("ID property not found for property " + name); } else if ((int)idValue != typeId) { ReportError("ID property for property " + name + " does not match ID value"); if (_fixErrors) { Trace.WriteLine("Set ID property of PropType resource " + name + " to " + typeId); UpdatePropValue(_intProps, resID, propID, typeId); _fixCount++; } } object dataTypeValue = GetPropValueSafe(_intProps, resID, propDataType); if (dataTypeValue == null) { ReportError("DataType property not found for property " + name); } else if ((int)dataTypeValue != dataType) { ReportError("DataType property for property " + name + " does not match Type value"); } object flagsValue = GetPropValueSafe(_intProps, resID, propFlags); if (flagsValue == null) { ReportError("Flags property not found for property " + name); } else if ((int)flagsValue != flags) { ReportError("Flags property for property " + name + " does not match Flags value. Fixing..."); UpdatePropValue(_intProps, resID, propFlags, flags); _fixCount++; } } } if (needRebuildIndexes) { _propTypes.RebuildIndexes(true); } }